Skip to content

Commit cebc4a3

Browse files
committed
Initial refactor for ConfigDocumentFactory
1 parent 27ee375 commit cebc4a3

File tree

7 files changed

+122
-92
lines changed

7 files changed

+122
-92
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config.parser
2+
3+
/**
4+
* [[ConfigFactoryDocument]] methods for Scala.js platform
5+
*/
6+
abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryShared {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config.parser
2+
3+
/**
4+
* [[ConfigFactoryDocument]] methods common to JVM and Native
5+
*/
6+
abstract class ConfigDocumentFactoryJvmNative extends ConfigDocumentFactoryShared {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config.parser
2+
3+
/**
4+
* [[ConfigFactoryDocument]] methods for Scala JVM platform
5+
*/
6+
abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryJvmNative {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.ekrich.config.parser
2+
3+
/**
4+
* [[ConfigFactoryDocument]] methods for Scala Native platform
5+
*/
6+
abstract class PlatformConfigDocumentFactory extends ConfigDocumentFactoryJvmNative {}
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,6 @@
11
package org.ekrich.config.parser
22

3-
import org.ekrich.config.ConfigParseOptions
4-
import org.ekrich.config.impl.Parseable
5-
import java.io.File
6-
import java.io.Reader
7-
83
/**
94
* Factory for creating [[org.ekrich.config.parser.ConfigDocument]] instances.
105
*/
11-
object ConfigDocumentFactory {
12-
13-
/**
14-
* Parses a Reader into a ConfigDocument instance.
15-
*
16-
* @param reader
17-
* the reader to parse
18-
* @param options
19-
* parse options to control how the reader is interpreted
20-
* @return
21-
* the parsed configuration
22-
* @throws ConfigException
23-
* on IO or parse errors
24-
*/
25-
def parseReader(reader: Reader, options: ConfigParseOptions): ConfigDocument =
26-
Parseable.newReader(reader, options).parseConfigDocument()
27-
28-
/**
29-
* Parses a reader into a Config instance as with
30-
* [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]]
31-
* but always uses the default parse options.
32-
*
33-
* @param reader
34-
* the reader to parse
35-
* @return
36-
* the parsed configuration
37-
* @throws org.ekrich.config.ConfigException
38-
* on IO or parse errors
39-
*/
40-
def parseReader(reader: Reader): ConfigDocument =
41-
parseReader(reader, ConfigParseOptions.defaults)
42-
43-
/**
44-
* Parses a file into a ConfigDocument instance.
45-
*
46-
* @param file
47-
* the file to parse
48-
* @param options
49-
* parse options to control how the file is interpreted
50-
* @return
51-
* the parsed configuration
52-
* @throws org.ekrich.config.ConfigException
53-
* on IO or parse errors
54-
*/
55-
def parseFile(file: File, options: ConfigParseOptions): ConfigDocument =
56-
Parseable.newFile(file, options).parseConfigDocument()
57-
58-
/**
59-
* Parses a file into a ConfigDocument instance as with
60-
* [[#parseFile(file:java\.io\.File,options:org\.ekrich\.config\.ConfigParseOptions)* parseFile(File, ConfigParseOptions)]]
61-
* but always uses the default parse options.
62-
*
63-
* @param file
64-
* the file to parse
65-
* @return
66-
* the parsed configuration
67-
* @throws org.ekrich.config.ConfigException
68-
* on IO or parse errors
69-
*/
70-
def parseFile(file: File): ConfigDocument =
71-
parseFile(file, ConfigParseOptions.defaults)
72-
73-
/**
74-
* Parses a string which should be valid HOCON or JSON.
75-
*
76-
* @param s
77-
* string to parse
78-
* @param options
79-
* parse options
80-
* @return
81-
* the parsed configuration
82-
*/
83-
def parseString(s: String, options: ConfigParseOptions): ConfigDocument =
84-
Parseable.newString(s, options).parseConfigDocument()
85-
86-
/**
87-
* Parses a string (which should be valid HOCON or JSON). Uses the default
88-
* parse options.
89-
*
90-
* @param s
91-
* string to parse
92-
* @return
93-
* the parsed configuration
94-
*/
95-
def parseString(s: String): ConfigDocument =
96-
parseString(s, ConfigParseOptions.defaults)
97-
}
6+
object ConfigDocumentFactory extends PlatformConfigDocumentFactory {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package org.ekrich.config.parser
2+
3+
import org.ekrich.config.ConfigParseOptions
4+
import org.ekrich.config.impl.Parseable
5+
import java.io.File
6+
import java.io.Reader
7+
8+
/**
9+
* Shared Factory methods for creating [[org.ekrich.config.parser.ConfigDocument]] instances.
10+
*/
11+
abstract class ConfigDocumentFactoryShared {
12+
13+
/**
14+
* Parses a Reader into a ConfigDocument instance.
15+
*
16+
* @param reader
17+
* the reader to parse
18+
* @param options
19+
* parse options to control how the reader is interpreted
20+
* @return
21+
* the parsed configuration
22+
* @throws ConfigException
23+
* on IO or parse errors
24+
*/
25+
def parseReader(reader: Reader, options: ConfigParseOptions): ConfigDocument =
26+
Parseable.newReader(reader, options).parseConfigDocument()
27+
28+
/**
29+
* Parses a reader into a Config instance as with
30+
* [[#parseReader(reader:java\.io\.Reader,options:org\.ekrich\.config\.ConfigParseOptions)* parseReader(Reader, ConfigParseOptions)]]
31+
* but always uses the default parse options.
32+
*
33+
* @param reader
34+
* the reader to parse
35+
* @return
36+
* the parsed configuration
37+
* @throws org.ekrich.config.ConfigException
38+
* on IO or parse errors
39+
*/
40+
def parseReader(reader: Reader): ConfigDocument =
41+
parseReader(reader, ConfigParseOptions.defaults)
42+
43+
/**
44+
* Parses a file into a ConfigDocument instance.
45+
*
46+
* @param file
47+
* the file to parse
48+
* @param options
49+
* parse options to control how the file is interpreted
50+
* @return
51+
* the parsed configuration
52+
* @throws org.ekrich.config.ConfigException
53+
* on IO or parse errors
54+
*/
55+
def parseFile(file: File, options: ConfigParseOptions): ConfigDocument =
56+
Parseable.newFile(file, options).parseConfigDocument()
57+
58+
/**
59+
* Parses a file into a ConfigDocument instance as with
60+
* [[#parseFile(file:java\.io\.File,options:org\.ekrich\.config\.ConfigParseOptions)* parseFile(File, ConfigParseOptions)]]
61+
* but always uses the default parse options.
62+
*
63+
* @param file
64+
* the file to parse
65+
* @return
66+
* the parsed configuration
67+
* @throws org.ekrich.config.ConfigException
68+
* on IO or parse errors
69+
*/
70+
def parseFile(file: File): ConfigDocument =
71+
parseFile(file, ConfigParseOptions.defaults)
72+
73+
/**
74+
* Parses a string which should be valid HOCON or JSON.
75+
*
76+
* @param s
77+
* string to parse
78+
* @param options
79+
* parse options
80+
* @return
81+
* the parsed configuration
82+
*/
83+
def parseString(s: String, options: ConfigParseOptions): ConfigDocument =
84+
Parseable.newString(s, options).parseConfigDocument()
85+
86+
/**
87+
* Parses a string (which should be valid HOCON or JSON). Uses the default
88+
* parse options.
89+
*
90+
* @param s
91+
* string to parse
92+
* @return
93+
* the parsed configuration
94+
*/
95+
def parseString(s: String): ConfigDocument =
96+
parseString(s, ConfigParseOptions.defaults)
97+
}

0 commit comments

Comments
 (0)