From 31b9ccf983ef073105322c699036163d708b349f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 17 Nov 2011 21:31:45 -0500 Subject: [PATCH] rename parse() methods to parseFoo() for clarity and to avoid overload ambiguity --- .../com/typesafe/config/ConfigFactory.java | 20 ++++++++++--------- .../config/impl/EquivalentsTest.scala | 4 ++-- .../typesafe/config/impl/PropertiesTest.scala | 4 ++-- .../typesafe/config/impl/PublicApiTest.scala | 18 ++++++++--------- .../com/typesafe/config/impl/TestUtils.scala | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/typesafe/config/ConfigFactory.java b/src/main/java/com/typesafe/config/ConfigFactory.java index 38ef0298..08e8f4b5 100644 --- a/src/main/java/com/typesafe/config/ConfigFactory.java +++ b/src/main/java/com/typesafe/config/ConfigFactory.java @@ -70,8 +70,9 @@ public final class ConfigFactory { ConfigParseOptions options) { ConfigRoot system = systemPropertiesRoot(rootPath); - Config mainFiles = parse(rootPath, options); - Config referenceFiles = parse(rootPath + ".reference", options); + Config mainFiles = parseResourcesForPath(rootPath, options); + Config referenceFiles = parseResourcesForPath(rootPath + ".reference", + options); return system.withFallbacks(mainFiles, referenceFiles); } @@ -123,24 +124,24 @@ public final class ConfigFactory { * @param options * @return */ - public static Config parse(Properties properties, + public static Config parseProperties(Properties properties, ConfigParseOptions options) { return Parseable.newProperties(properties, options).parse().toConfig(); } - public static Config parse(Reader reader, ConfigParseOptions options) { + public static Config parseReader(Reader reader, ConfigParseOptions options) { return Parseable.newReader(reader, options).parse().toConfig(); } - public static Config parse(URL url, ConfigParseOptions options) { + public static Config parseURL(URL url, ConfigParseOptions options) { return Parseable.newURL(url, options).parse().toConfig(); } - public static Config parse(File file, ConfigParseOptions options) { + public static Config parseFile(File file, ConfigParseOptions options) { return Parseable.newFile(file, options).parse().toConfig(); } - public static Config parse(Class klass, String resource, + public static Config parseResource(Class klass, String resource, ConfigParseOptions options) { return Parseable.newResource(klass, resource, options).parse() .toConfig(); @@ -156,9 +157,10 @@ public final class ConfigFactory { * @param options * @return */ - public static Config parse(String path, ConfigParseOptions options) { + public static Config parseResourcesForPath(String rootPath, + ConfigParseOptions options) { // null originDescription is allowed in parseResourcesForPath - return ConfigImpl.parseResourcesForPath(path, options).toConfig(); + return ConfigImpl.parseResourcesForPath(rootPath, options).toConfig(); } /** diff --git a/src/test/scala/com/typesafe/config/impl/EquivalentsTest.scala b/src/test/scala/com/typesafe/config/impl/EquivalentsTest.scala index a4742399..0721fb1e 100644 --- a/src/test/scala/com/typesafe/config/impl/EquivalentsTest.scala +++ b/src/test/scala/com/typesafe/config/impl/EquivalentsTest.scala @@ -42,12 +42,12 @@ class EquivalentsTest extends TestUtils { private def parse(flavor: ConfigSyntax, f: File) = { val options = ConfigParseOptions.defaults().setSyntax(flavor) - postParse(ConfigFactory.parse(f, options).toObject) + postParse(ConfigFactory.parseFile(f, options).toObject) } private def parse(f: File) = { val options = ConfigParseOptions.defaults() - postParse(ConfigFactory.parse(f, options).toObject) + postParse(ConfigFactory.parseFile(f, options).toObject) } // would like each "equivNN" directory to be a suite and each file in the dir diff --git a/src/test/scala/com/typesafe/config/impl/PropertiesTest.scala b/src/test/scala/com/typesafe/config/impl/PropertiesTest.scala index 2e96ebb2..21b138e5 100644 --- a/src/test/scala/com/typesafe/config/impl/PropertiesTest.scala +++ b/src/test/scala/com/typesafe/config/impl/PropertiesTest.scala @@ -51,7 +51,7 @@ class PropertiesTest extends TestUtils { props.setProperty(propsPath, propsPath) - val conf = ConfigFactory.parse(props, ConfigParseOptions.defaults()) + val conf = ConfigFactory.parseProperties(props, ConfigParseOptions.defaults()) assertEquals(propsPath, conf.getString(confPath)) } @@ -83,7 +83,7 @@ class PropertiesTest extends TestUtils { props.setProperty("x.y", "bar") props.setProperty("x.y.z", "foo") - val conf = ConfigFactory.parse(props, ConfigParseOptions.defaults()) + val conf = ConfigFactory.parseProperties(props, ConfigParseOptions.defaults()) assertEquals(2, conf.toObject.size()) assertEquals("foo", conf.getString("a.b")) diff --git a/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala b/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala index b741305f..b915b466 100644 --- a/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala +++ b/src/test/scala/com/typesafe/config/impl/PublicApiTest.scala @@ -217,7 +217,7 @@ class PublicApiTest extends TestUtils { } } - private def resource(filename: String) = { + private def resourceFile(filename: String) = { val resourceDir = new File("src/test/resources") if (!resourceDir.exists()) throw new RuntimeException("This test can only be run from the project's root directory") @@ -236,11 +236,11 @@ class PublicApiTest extends TestUtils { @Test def allowMissing() { val e = intercept[ConfigException.IO] { - ConfigFactory.parse(resource("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(false)) + ConfigFactory.parseFile(resourceFile("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(false)) } assertTrue(e.getMessage.contains("No such")) - val conf = ConfigFactory.parse(resource("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(true)) + val conf = ConfigFactory.parseFile(resourceFile("nonexistent.conf"), ConfigParseOptions.defaults().setAllowMissing(true)) assertTrue(conf.isEmpty()) } @@ -251,10 +251,10 @@ class PublicApiTest extends TestUtils { // change that the includes are allowed to be missing. // This can break because some options might "propagate" through // to includes, but we don't want them all to do so. - val conf = ConfigFactory.parse(resource("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(false)) + val conf = ConfigFactory.parseFile(resourceFile("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(false)) assertEquals(42, conf.getInt("test01.booleans")) - val conf2 = ConfigFactory.parse(resource("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(true)) + val conf2 = ConfigFactory.parseFile(resourceFile("test03.conf"), ConfigParseOptions.defaults().setAllowMissing(true)) assertEquals(conf, conf2) } @@ -288,7 +288,7 @@ class PublicApiTest extends TestUtils { @Test def includersAreUsedWithFiles() { - val included = whatWasIncluded(ConfigFactory.parse(resource("test03.conf"), _)) + val included = whatWasIncluded(ConfigFactory.parseFile(resourceFile("test03.conf"), _)) assertEquals(List("test01", "test02.conf", "equiv01/original.json", "nothere", "nothere.conf", "nothere.json", "nothere.properties"), @@ -298,7 +298,7 @@ class PublicApiTest extends TestUtils { @Test def includersAreUsedRecursivelyWithFiles() { // includes.conf has recursive includes in it - val included = whatWasIncluded(ConfigFactory.parse(resource("equiv03/includes.conf"), _)) + val included = whatWasIncluded(ConfigFactory.parseFile(resourceFile("equiv03/includes.conf"), _)) assertEquals(List("letters/a.conf", "numbers/1.conf", "numbers/2", "letters/b.json", "letters/c"), included.map(_.name)) @@ -306,7 +306,7 @@ class PublicApiTest extends TestUtils { @Test def includersAreUsedWithClasspath() { - val included = whatWasIncluded(ConfigFactory.parse(classOf[PublicApiTest], "/test03.conf", _)) + val included = whatWasIncluded(ConfigFactory.parseResource(classOf[PublicApiTest], "/test03.conf", _)) assertEquals(List("test01", "test02.conf", "equiv01/original.json", "nothere", "nothere.conf", "nothere.json", "nothere.properties"), @@ -316,7 +316,7 @@ class PublicApiTest extends TestUtils { @Test def includersAreUsedRecursivelyWithClasspath() { // includes.conf has recursive includes in it - val included = whatWasIncluded(ConfigFactory.parse(classOf[PublicApiTest], "/equiv03/includes.conf", _)) + val included = whatWasIncluded(ConfigFactory.parseResource(classOf[PublicApiTest], "/equiv03/includes.conf", _)) assertEquals(List("letters/a.conf", "numbers/1.conf", "numbers/2", "letters/b.json", "letters/c"), included.map(_.name)) diff --git a/src/test/scala/com/typesafe/config/impl/TestUtils.scala b/src/test/scala/com/typesafe/config/impl/TestUtils.scala index 7f8d52ff..281596e0 100644 --- a/src/test/scala/com/typesafe/config/impl/TestUtils.scala +++ b/src/test/scala/com/typesafe/config/impl/TestUtils.scala @@ -340,7 +340,7 @@ abstract trait TestUtils { val options = ConfigParseOptions.defaults(). setOriginDescription("test string"). setSyntax(ConfigSyntax.CONF); - ConfigFactory.parse(new StringReader(s), options).asInstanceOf[SimpleConfig] + ConfigFactory.parseReader(new StringReader(s), options).asInstanceOf[SimpleConfig] } protected def subst(ref: String) = {