From 850e7acc7b3e5462bb02fec2aa05db71ec57db2c Mon Sep 17 00:00:00 2001 From: Eric K Richardson Date: Mon, 5 Aug 2024 10:13:43 -0700 Subject: [PATCH] Initial refactor for ConfigDocumentFactory --- .../PlatformConfigDocumentFactory.scala | 6 ++ .../ConfigDocumentFactoryJvmNative.scala | 6 ++ .../PlatformConfigDocumentFactory.scala | 6 ++ .../{impl => }/PlatformConfigFactory.scala | 0 .../PlatformConfigDocumentFactory.scala | 6 ++ .../config/parser/ConfigDocumentFactory.scala | 93 +----------------- .../parser/ConfigDocumentFactoryShared.scala | 97 +++++++++++++++++++ 7 files changed, 122 insertions(+), 92 deletions(-) create mode 100644 sconfig/js/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala create mode 100644 sconfig/jvm-native/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryJvmNative.scala create mode 100644 sconfig/jvm/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala rename sconfig/native/src/main/scala/org/ekrich/config/{impl => }/PlatformConfigFactory.scala (100%) create mode 100644 sconfig/native/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala create mode 100644 sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryShared.scala diff --git a/sconfig/js/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala b/sconfig/js/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala new file mode 100644 index 00000000..b6350b18 --- /dev/null +++ b/sconfig/js/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala @@ -0,0 +1,6 @@ +package org.ekrich.config.parser + +/** + * [[ConfigFactoryDocument]] methods for Scala.js platform + */ +abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryShared {} diff --git a/sconfig/jvm-native/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryJvmNative.scala b/sconfig/jvm-native/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryJvmNative.scala new file mode 100644 index 00000000..211931f9 --- /dev/null +++ b/sconfig/jvm-native/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryJvmNative.scala @@ -0,0 +1,6 @@ +package org.ekrich.config.parser + +/** + * [[ConfigFactoryDocument]] methods common to JVM and Native + */ +abstract class ConfigDocumentFactoryJvmNative extends ConfigDocumentFactoryShared {} diff --git a/sconfig/jvm/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala b/sconfig/jvm/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala new file mode 100644 index 00000000..9c037a9d --- /dev/null +++ b/sconfig/jvm/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala @@ -0,0 +1,6 @@ +package org.ekrich.config.parser + +/** + * [[ConfigFactoryDocument]] methods for Scala JVM platform + */ +abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryJvmNative {} diff --git a/sconfig/native/src/main/scala/org/ekrich/config/impl/PlatformConfigFactory.scala b/sconfig/native/src/main/scala/org/ekrich/config/PlatformConfigFactory.scala similarity index 100% rename from sconfig/native/src/main/scala/org/ekrich/config/impl/PlatformConfigFactory.scala rename to sconfig/native/src/main/scala/org/ekrich/config/PlatformConfigFactory.scala diff --git a/sconfig/native/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala b/sconfig/native/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala new file mode 100644 index 00000000..b231ea5e --- /dev/null +++ b/sconfig/native/src/main/scala/org/ekrich/config/parser/PlatformConfigDocumentFactory.scala @@ -0,0 +1,6 @@ +package org.ekrich.config.parser + +/** + * [[ConfigFactoryDocument]] methods for Scala Native platform + */ +abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryJvmNative {} diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactory.scala b/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactory.scala index ef3b4dda..8a7ecd1e 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactory.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactory.scala @@ -1,97 +1,6 @@ package org.ekrich.config.parser -import org.ekrich.config.ConfigParseOptions -import org.ekrich.config.impl.Parseable -import java.io.File -import java.io.Reader - /** * Factory for creating [[org.ekrich.config.parser.ConfigDocument]] instances. */ -object ConfigDocumentFactory { - - /** - * Parses a Reader into a ConfigDocument instance. - * - * @param reader - * the reader to parse - * @param options - * parse options to control how the reader is interpreted - * @return - * the parsed configuration - * @throws ConfigException - * on IO or parse errors - */ - def parseReader(reader: Reader, options: ConfigParseOptions): ConfigDocument = - Parseable.newReader(reader, options).parseConfigDocument() - - /** - * Parses a reader into a Config instance as with - * [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]] - * but always uses the default parse options. - * - * @param reader - * the reader to parse - * @return - * the parsed configuration - * @throws org.ekrich.config.ConfigException - * on IO or parse errors - */ - def parseReader(reader: Reader): ConfigDocument = - parseReader(reader, ConfigParseOptions.defaults) - - /** - * Parses a file into a ConfigDocument instance. - * - * @param file - * the file to parse - * @param options - * parse options to control how the file is interpreted - * @return - * the parsed configuration - * @throws org.ekrich.config.ConfigException - * on IO or parse errors - */ - def parseFile(file: File, options: ConfigParseOptions): ConfigDocument = - Parseable.newFile(file, options).parseConfigDocument() - - /** - * Parses a file into a ConfigDocument instance as with - * [[#parseFile(file:java\.io\.File,options:org\.ekrich\.config\.ConfigParseOptions)* parseFile(File, ConfigParseOptions)]] - * but always uses the default parse options. - * - * @param file - * the file to parse - * @return - * the parsed configuration - * @throws org.ekrich.config.ConfigException - * on IO or parse errors - */ - def parseFile(file: File): ConfigDocument = - parseFile(file, ConfigParseOptions.defaults) - - /** - * Parses a string which should be valid HOCON or JSON. - * - * @param s - * string to parse - * @param options - * parse options - * @return - * the parsed configuration - */ - def parseString(s: String, options: ConfigParseOptions): ConfigDocument = - Parseable.newString(s, options).parseConfigDocument() - - /** - * Parses a string (which should be valid HOCON or JSON). Uses the default - * parse options. - * - * @param s - * string to parse - * @return - * the parsed configuration - */ - def parseString(s: String): ConfigDocument = - parseString(s, ConfigParseOptions.defaults) -} +object ConfigDocumentFactory extends PlatformConfigDocumentFactory {} diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryShared.scala b/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryShared.scala new file mode 100644 index 00000000..654207bd --- /dev/null +++ b/sconfig/shared/src/main/scala/org/ekrich/config/parser/ConfigDocumentFactoryShared.scala @@ -0,0 +1,97 @@ +package org.ekrich.config.parser + +import org.ekrich.config.ConfigParseOptions +import org.ekrich.config.impl.Parseable +import java.io.File +import java.io.Reader + +/** + * Shared Factory methods for creating [[org.ekrich.config.parser.ConfigDocument]] instances. + */ +abstract class ConfigDocumentFactoryShared { + + /** + * Parses a Reader into a ConfigDocument instance. + * + * @param reader + * the reader to parse + * @param options + * parse options to control how the reader is interpreted + * @return + * the parsed configuration + * @throws ConfigException + * on IO or parse errors + */ + def parseReader(reader: Reader, options: ConfigParseOptions): ConfigDocument = + Parseable.newReader(reader, options).parseConfigDocument() + + /** + * Parses a reader into a Config instance as with + * [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]] + * but always uses the default parse options. + * + * @param reader + * the reader to parse + * @return + * the parsed configuration + * @throws org.ekrich.config.ConfigException + * on IO or parse errors + */ + def parseReader(reader: Reader): ConfigDocument = + parseReader(reader, ConfigParseOptions.defaults) + + /** + * Parses a file into a ConfigDocument instance. + * + * @param file + * the file to parse + * @param options + * parse options to control how the file is interpreted + * @return + * the parsed configuration + * @throws org.ekrich.config.ConfigException + * on IO or parse errors + */ + def parseFile(file: File, options: ConfigParseOptions): ConfigDocument = + Parseable.newFile(file, options).parseConfigDocument() + + /** + * Parses a file into a ConfigDocument instance as with + * [[#parseFile(file:java\.io\.File,options:org\.ekrich\.config\.ConfigParseOptions)* parseFile(File, ConfigParseOptions)]] + * but always uses the default parse options. + * + * @param file + * the file to parse + * @return + * the parsed configuration + * @throws org.ekrich.config.ConfigException + * on IO or parse errors + */ + def parseFile(file: File): ConfigDocument = + parseFile(file, ConfigParseOptions.defaults) + + /** + * Parses a string which should be valid HOCON or JSON. + * + * @param s + * string to parse + * @param options + * parse options + * @return + * the parsed configuration + */ + def parseString(s: String, options: ConfigParseOptions): ConfigDocument = + Parseable.newString(s, options).parseConfigDocument() + + /** + * Parses a string (which should be valid HOCON or JSON). Uses the default + * parse options. + * + * @param s + * string to parse + * @return + * the parsed configuration + */ + def parseString(s: String): ConfigDocument = + parseString(s, ConfigParseOptions.defaults) +}