diff --git a/build.sbt b/build.sbt index 849f3f46..325eb852 100644 --- a/build.sbt +++ b/build.sbt @@ -25,9 +25,9 @@ val scalacOpts = dotcOpts ++ List( // 57 inferred return type Scala 2.13 cat=scala3-migration "-Wconf:msg=inferred:ws", // 2 deprecations Scala 2.12 Stack - fixed for 2.13 - "-Wconf:msg=poorly-performing:ws" + "-Wconf:msg=poorly-performing:ws", // uncomment to see messages - // "-Wconf:any:warning-verbose" + "-Wconf:any:warning-verbose" ) Compile / console / scalacOptions --= Seq( diff --git a/project/build.properties b/project/build.properties index db1723b0..73df629a 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.5 +sbt.version=1.10.7 diff --git a/project/plugins.sbt b/project/plugins.sbt index 3c3100b4..93111244 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,11 +4,11 @@ resolvers ++= Resolver.sonatypeOssRepos("snapshots") // versions val crossVer = "1.3.2" val scalaJSVersion = "1.17.0" -val scalaNativeVersion = "0.5.5" +val scalaNativeVersion = "0.5.6" val scalafix = "0.13.0" // includes sbt-dynver sbt-pgp sbt-sonatype sbt-git -addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.2") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4") // Scala Native support diff --git a/sconfig/jvm-native/src/main/scala/org/ekrich/config/ConfigFactoryJvmNative.scala b/sconfig/jvm-native/src/main/scala/org/ekrich/config/ConfigFactoryJvmNative.scala index 3085e9ea..e3e9bfdc 100644 --- a/sconfig/jvm-native/src/main/scala/org/ekrich/config/ConfigFactoryJvmNative.scala +++ b/sconfig/jvm-native/src/main/scala/org/ekrich/config/ConfigFactoryJvmNative.scala @@ -3,4 +3,10 @@ package org.ekrich.config /** * [[ConfigFactory]] methods common to JVM and Native */ -abstract class ConfigFactoryJvmNative extends ConfigFactoryShared {} +abstract class ConfigFactoryJvmNative extends ConfigFactoryShared { + // parseFile and parseFileAnySyntax should be here but they + // use shared so then it is very tangled so any refactor is big + // TODO: first create a PublicApiFileTest for JVM native to test + // this API on Native. + +} diff --git a/sconfig/jvm-native/src/test/scala/org/ekrich/config/impl/PublicApiFileTest.scala b/sconfig/jvm-native/src/test/scala/org/ekrich/config/impl/PublicApiFileTest.scala new file mode 100644 index 00000000..0592b25a --- /dev/null +++ b/sconfig/jvm-native/src/test/scala/org/ekrich/config/impl/PublicApiFileTest.scala @@ -0,0 +1,108 @@ +/** + * Copyright (C) 2011 Typesafe Inc. + */ +package org.ekrich.config.impl + +import org.junit.Assert._ +import org.junit._ + +import org.ekrich.config._ + +import FileUtils._ + +/** + * Most of the File tests should work but internally and externally they use URL + * and Native doesn't support URL. Once the API use URI internally more test + * support should be available. + */ +class PublicApiFileTest extends TestUtils { + + // dupe in PublicApiTest + private def assertNotFound(e: ConfigException): Unit = { + assertTrue( + "Message text: " + e.getMessage, + e.getMessage.contains("No such") || + e.getMessage.contains("not found") || + e.getMessage.contains("were found") || + e.getMessage.contains("java.io.FileNotFoundException") + ) + } + + @Test + def allowMissing(): Unit = { + val e = intercept[ConfigException.IO] { + ConfigFactory.parseFile( + resourceFile("nonexistent.conf"), + ConfigParseOptions.defaults.setAllowMissing(false) + ) + } + assertNotFound(e) + + val conf = ConfigFactory.parseFile( + resourceFile("nonexistent.conf"), + ConfigParseOptions.defaults.setAllowMissing(true) + ) + assertTrue("is empty", conf.isEmpty) + } + + @Test + def allowMissingFileAnySyntax(): Unit = { + val e = intercept[ConfigException.IO] { + ConfigFactory.parseFileAnySyntax( + resourceFile("nonexistent"), + ConfigParseOptions.defaults.setAllowMissing(false) + ) + } + assertNotFound(e) + + val conf = ConfigFactory.parseFileAnySyntax( + resourceFile("nonexistent"), + ConfigParseOptions.defaults.setAllowMissing(true) + ) + assertTrue("is empty", conf.isEmpty) + } + + @Test + def anySyntaxJvmNative(): Unit = { + // Kept in JVM as anySyntax() this is only a partial test + // as resource loading not supported yet in Native + + // test01 has all three syntaxes; first load with basename + val conf = ConfigFactory.parseFileAnySyntax( + resourceFile("test01"), + ConfigParseOptions.defaults + ) + assertEquals(42, conf.getInt("ints.fortyTwo")) + assertEquals("A", conf.getString("fromJsonA")) + assertEquals("true", conf.getString("fromProps.bool")) + + // now include a suffix, should only load one of them + val onlyProps = ConfigFactory.parseFileAnySyntax( + resourceFile("test01.properties"), + ConfigParseOptions.defaults + ) + assertFalse(onlyProps.hasPath("ints.fortyTwo")) + assertFalse(onlyProps.hasPath("fromJsonA")) + assertEquals("true", onlyProps.getString("fromProps.bool")) + + // force only one syntax via options + val onlyPropsViaOptions = ConfigFactory.parseFileAnySyntax( + resourceFile("test01.properties"), + ConfigParseOptions.defaults.setSyntax(ConfigSyntax.PROPERTIES) + ) + assertFalse(onlyPropsViaOptions.hasPath("ints.fortyTwo")) + assertFalse(onlyPropsViaOptions.hasPath("fromJsonA")) + assertEquals("true", onlyPropsViaOptions.getString("fromProps.bool")) + + // TODO: continue test when resourse work on native + // val fromResources = ConfigFactory.parseResourcesAnySyntax( + // classOf[PublicApiFileTest], + // "/test01", + // ConfigParseOptions.defaults + // ) + // assertEquals(42, fromResources.getInt("ints.fortyTwo")) + // assertEquals("A", fromResources.getString("fromJsonA")) + // assertEquals("true", fromResources.getString("fromProps.bool")) + } + +} diff --git a/sconfig/jvm/src/main/scala/org/ekrich/config/impl/ConfigBeanImpl.scala b/sconfig/jvm/src/main/scala/org/ekrich/config/impl/ConfigBeanImpl.scala index 58100483..920272eb 100644 --- a/sconfig/jvm/src/main/scala/org/ekrich/config/impl/ConfigBeanImpl.scala +++ b/sconfig/jvm/src/main/scala/org/ekrich/config/impl/ConfigBeanImpl.scala @@ -112,7 +112,7 @@ object ConfigBeanImpl { if (!problems.isEmpty) throw new ConfigException.ValidationFailed(problems) // Fill in the bean instance - val bean = clazz.getConstructor().newInstance() + val bean = clazz.getDeclaredConstructor().newInstance() for (beanProp <- beanProps.asScala) { breakable { val setter = beanProp.getWriteMethod @@ -137,11 +137,16 @@ object ConfigBeanImpl { } bean } catch { - case e: InstantiationException => + case e: NoSuchMethodException => throw new ConfigException.BadBean( clazz.getName + " needs a public no-args constructor to be used as a bean", e ) + case e: InstantiationException => + throw new ConfigException.BadBean( + clazz.getName + " needs to be instantiatable to be used as a bean", + e + ) case e: IllegalAccessException => throw new ConfigException.BadBean( clazz.getName + " getters and setters are not accessible, they must be for use as a bean", diff --git a/sconfig/jvm/src/test/scala/org/ekrich/config/impl/PublicApiTest.scala b/sconfig/jvm/src/test/scala/org/ekrich/config/impl/PublicApiTest.scala index c81415e0..9813e541 100644 --- a/sconfig/jvm/src/test/scala/org/ekrich/config/impl/PublicApiTest.scala +++ b/sconfig/jvm/src/test/scala/org/ekrich/config/impl/PublicApiTest.scala @@ -401,40 +401,6 @@ class PublicApiTest extends TestUtils { ) } - @Test - def allowMissing(): Unit = { - val e = intercept[ConfigException.IO] { - ConfigFactory.parseFile( - resourceFile("nonexistent.conf"), - ConfigParseOptions.defaults.setAllowMissing(false) - ) - } - assertNotFound(e) - - val conf = ConfigFactory.parseFile( - resourceFile("nonexistent.conf"), - ConfigParseOptions.defaults.setAllowMissing(true) - ) - assertTrue("is empty", conf.isEmpty) - } - - @Test - def allowMissingFileAnySyntax(): Unit = { - val e = intercept[ConfigException.IO] { - ConfigFactory.parseFileAnySyntax( - resourceFile("nonexistent"), - ConfigParseOptions.defaults.setAllowMissing(false) - ) - } - assertNotFound(e) - - val conf = ConfigFactory.parseFileAnySyntax( - resourceFile("nonexistent"), - ConfigParseOptions.defaults.setAllowMissing(true) - ) - assertTrue("is empty", conf.isEmpty) - } - @Test def allowMissingResourcesAnySyntax(): Unit = { val e = intercept[ConfigException.IO] { diff --git a/sconfig/native/src/test/resources/test01.conf b/sconfig/native/src/test/resources/test01.conf new file mode 100644 index 00000000..e40eb7f5 --- /dev/null +++ b/sconfig/native/src/test/resources/test01.conf @@ -0,0 +1,94 @@ +{ + "ints" : { + "fortyTwo" : 42, + "fortyTwoAgain" : ${ints.fortyTwo} + }, + + "floats" : { + "fortyTwoPointOne" : 42.1, + "fortyTwoPointOneAgain" : ${floats.fortyTwoPointOne}, + "pointThirtyThree": .33 + "pointThirtyThreeAgain": ${floats.pointThirtyThree} + }, + + "strings" : { + "abcd" : "abcd", + "abcdAgain" : ${strings.a}${strings.b}${strings.c}${strings.d}, + "a" : "a", + "b" : "b", + "c" : "c", + "d" : "d", + "concatenated" : null bar 42 baz true 3.14 hi, + "double" : "3.14", + "doubleStartingWithDot": ".33", + "number" : "57", + "null" : "null", + "true" : "true", + "yes" : "yes", + "false" : "false", + "no" : "no" + }, + + "arrays" : { + "empty" : [], + "ofInt" : [1, 2, 3], + "ofString" : [ ${strings.a}, ${strings.b}, ${strings.c} ], + "ofDouble" : [3.14, 4.14, 5.14], + "ofNull" : [null, null, null], + "ofBoolean" : [true, false], + "ofArray" : [${arrays.ofString}, ${arrays.ofString}, ${arrays.ofString}], + "ofObject" : [${ints}, ${booleans}, ${strings}], + "firstElementNotASubst" : [ "a", ${strings.b} ] + }, + + "booleans" : { + "true" : true, + "trueAgain" : ${booleans.true}, + "false" : false, + "falseAgain" : ${booleans.false} + }, + + "nulls" : { + "null" : null, + "nullAgain" : ${nulls.null} + }, + + "durations" : { + "second" : 1s, + "secondsList" : [1s,2seconds,3 s, 4000], + "secondAsNumber" : 1000, + "halfSecond" : 0.5s, + "millis" : 1 milli, + "micros" : 2000 micros, + "largeNanos" : 4878955355435272204ns, + "plusLargeNanos" : "+4878955355435272204ns", + "minusLargeNanos" : -4878955355435272204ns + }, + + "periods" : { + "day" : 1d, + "dayAsNumber": 2, + "week": 3 weeks, + "month": 5 mo, + "year": 8y + }, + + "memsizes" : { + "meg" : 1M, + "megsList" : [1M, 1024K, 1048576], + "megAsNumber" : 1048576, + "halfMeg" : 0.5M + }, + + "system" : { + "javaversion" : ${?java.version}, + "userhome" : ${?user.home}, + "home" : ${?HOME}, + "pwd" : ${?PWD}, + "shell" : ${?SHELL}, + "lang" : ${?LANG}, + "path" : ${?PATH}, + "not_here" : ${?NOT_HERE}, + "concatenated" : Your Java version is ${?system.javaversion} and your user.home is ${?system.userhome} + } +} diff --git a/sconfig/native/src/test/resources/test01.json b/sconfig/native/src/test/resources/test01.json new file mode 100644 index 00000000..13809157 --- /dev/null +++ b/sconfig/native/src/test/resources/test01.json @@ -0,0 +1,4 @@ +{ + "fromJson1" : 1, + "fromJsonA" : "A" +} \ No newline at end of file diff --git a/sconfig/native/src/test/resources/test01.properties b/sconfig/native/src/test/resources/test01.properties new file mode 100644 index 00000000..71de4e0b --- /dev/null +++ b/sconfig/native/src/test/resources/test01.properties @@ -0,0 +1,5 @@ +# .properties file +fromProps.abc=abc +fromProps.one=1 +fromProps.bool=true +fromProps.specialChars=hello^^ diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala index 61061963..be0636ef 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/ConfigFactory.scala @@ -1049,14 +1049,27 @@ object ConfigFactory extends PlatformConfigFactory { if (className != null) { try { classOf[ConfigLoadingStrategy].cast( - Class.forName(className).getConstructor().newInstance() + Class + .forName(className) + .asSubclass(classOf[ConfigLoadingStrategy]) + .getDeclaredConstructor() + .newInstance() ) } catch { + // possibly InvocationTargetException case e: Throwable => - throw new ConfigException.BugOrBroken( - "Failed to load strategy: " + className, - e - ) + val cause = e.getCause() + if (cause == null) { + throw new ConfigException.BugOrBroken( + "Failed to load strategy: " + className, + e + ) + } else { + throw new ConfigException.BugOrBroken( + "Failed to load strategy: " + className, + cause + ) + } } } else { new DefaultConfigLoadingStrategy() diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/AbstractConfigObject.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/AbstractConfigObject.scala index 74c8e9b8..25a1dbf4 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/AbstractConfigObject.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/AbstractConfigObject.scala @@ -164,7 +164,7 @@ abstract class AbstractConfigObject(_origin: ConfigOrigin) override def constructDelayedMerge( origin: ConfigOrigin, stack: ju.List[AbstractConfigValue] - ) = + ): AbstractConfigObject = new ConfigDelayedMergeObject(origin, stack) override def mergedWithObject( diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigBoolean.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigBoolean.scala index 97fcf075..420fa7aa 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigBoolean.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigBoolean.scala @@ -19,7 +19,8 @@ final class ConfigBoolean(origin: ConfigOrigin, val value: jl.Boolean) override def transformToString: String = value.toString() - override def newCopy(origin: ConfigOrigin) = new ConfigBoolean(origin, value) + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = + new ConfigBoolean(origin, value) // serialization all goes through SerializedConfigValue (signature is critical) @throws[ObjectStreamException] diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigConcatenation.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigConcatenation.scala index df428600..99c7cd9f 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigConcatenation.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigConcatenation.scala @@ -144,11 +144,11 @@ final class ConfigConcatenation( "need to Config#resolve(), see the API docs for Config#resolve(); substitution not resolved: " + this ) - override def valueType = throw notResolved + override def valueType: ConfigValueType = throw notResolved - override def unwrapped = throw notResolved + override def unwrapped: AnyRef = throw notResolved - override def newCopy(newOrigin: ConfigOrigin) = + override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue = new ConfigConcatenation(newOrigin, pieces) override def ignoresFallbacks: Boolean = { diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMerge.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMerge.scala index f967e56d..9fc5139e 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMerge.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMerge.scala @@ -10,6 +10,7 @@ import org.ekrich.config.ConfigException import org.ekrich.config.ConfigOrigin import org.ekrich.config.ConfigRenderOptions import org.ekrich.config.impl.AbstractConfigValue._ +import org.ekrich.config.ConfigValueType /** * The issue here is that we want to first merge our stack of config files, and @@ -227,12 +228,12 @@ final class ConfigDelayedMerge( ) } - override def valueType = + override def valueType: ConfigValueType = throw new ConfigException.NotResolved( "called valueType() on value with unresolved substitutions, need to Config#resolve() first, see API docs" ) - override def unwrapped = + override def unwrapped: AnyRef = throw new ConfigException.NotResolved( "called unwrapped() on value with unresolved substitutions, need to Config#resolve() first, see API docs" ) @@ -274,7 +275,7 @@ final class ConfigDelayedMerge( override def ignoresFallbacks: Boolean = ConfigDelayedMerge.stackIgnoresFallbacks(stack) - override def newCopy(newOrigin: ConfigOrigin) = + override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue = new ConfigDelayedMerge(newOrigin, stack) override final def mergedWithTheUnmergeable( diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMergeObject.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMergeObject.scala index b64997fa..a18abc18 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMergeObject.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDelayedMergeObject.scala @@ -114,19 +114,22 @@ final class ConfigDelayedMergeObject( mergeable: ConfigMergeable ): ConfigDelayedMergeObject = super.withFallback(mergeable).asInstanceOf[ConfigDelayedMergeObject] - override def withOnlyKey(key: String) = + override def withOnlyKey(key: String): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withoutKey(key: String) = + override def withoutKey(key: String): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withOnlyPathOrNull(path: Path) = + override def withOnlyPathOrNull(path: Path): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withOnlyPath(path: Path) = + override def withOnlyPath(path: Path): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withoutPath(path: Path) = + override def withoutPath(path: Path): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withValue(key: String, value: ConfigValue) = + override def withValue( + key: String, + value: ConfigValue + ): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved - override def withValue(path: Path, value: ConfigValue) = + override def withValue(path: Path, value: ConfigValue): AbstractConfigObject = throw ConfigDelayedMergeObject.notResolved override def unmergedValues: ju.Collection[AbstractConfigValue] = stack override def canEqual(other: Any): Boolean = @@ -158,18 +161,24 @@ final class ConfigDelayedMergeObject( ): Unit = { render(sb, indent, atRoot, null, options) } - override def unwrapped = throw ConfigDelayedMergeObject.notResolved - override def get(key: Any) = throw ConfigDelayedMergeObject.notResolved - override def remove(key: Any) = throw ConfigDelayedMergeObject.notResolved - override def containsKey(key: Any) = + override def unwrapped: ju.Map[String, AnyRef] = throw ConfigDelayedMergeObject.notResolved - override def containsValue(value: Any) = + override def get(key: Any): AbstractConfigValue = + throw ConfigDelayedMergeObject.notResolved + override def remove(key: Any): ConfigValue = + throw ConfigDelayedMergeObject.notResolved + override def containsKey(key: Any): Boolean = + throw ConfigDelayedMergeObject.notResolved + override def containsValue(value: Any): Boolean = + throw ConfigDelayedMergeObject.notResolved + override def entrySet: ju.Set[ju.Map.Entry[String, ConfigValue]] = + throw ConfigDelayedMergeObject.notResolved + override def isEmpty: Boolean = throw ConfigDelayedMergeObject.notResolved + override def keySet: ju.Set[String] = + throw ConfigDelayedMergeObject.notResolved + override def size: Int = throw ConfigDelayedMergeObject.notResolved + override def values: ju.Collection[ConfigValue] = throw ConfigDelayedMergeObject.notResolved - override def entrySet = throw ConfigDelayedMergeObject.notResolved - override def isEmpty = throw ConfigDelayedMergeObject.notResolved - override def keySet = throw ConfigDelayedMergeObject.notResolved - override def size = throw ConfigDelayedMergeObject.notResolved - override def values = throw ConfigDelayedMergeObject.notResolved // exercised in ValidationTest.validationFailedSerializable // and ConfigTest.test01Serializable diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDouble.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDouble.scala index 9905226e..521f1e4c 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDouble.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigDouble.scala @@ -29,7 +29,7 @@ final class ConfigDouble( override def doubleValue: Double = value - override def newCopy(origin: ConfigOrigin) = + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = new ConfigDouble(origin, value, originalText) // serialization all goes through SerializedConfigValue diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigInt.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigInt.scala index 0d45ab37..c325470b 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigInt.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigInt.scala @@ -29,7 +29,7 @@ final class ConfigInt( override def doubleValue: Double = value.toDouble - override def newCopy(origin: ConfigOrigin) = + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = new ConfigInt(origin, value, originalText) // serialization all goes through SerializedConfigValue diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigLong.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigLong.scala index 8b9f4b5a..87339228 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigLong.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigLong.scala @@ -28,7 +28,7 @@ final class ConfigLong( override def doubleValue: Double = value.toDouble - override def newCopy(origin: ConfigOrigin) = + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = new ConfigLong(origin, value, originalText) // serialization all goes through SerializedConfigValue diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeArray.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeArray.scala index 2d259a16..8ecc4cb2 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeArray.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeArray.scala @@ -5,6 +5,8 @@ import java.{util => ju} final class ConfigNodeArray private[impl] ( children: ju.Collection[AbstractConfigNode] ) extends ConfigNodeComplexValue(children) { - override def newNode(nodes: ju.Collection[AbstractConfigNode]) = + override def newNode( + nodes: ju.Collection[AbstractConfigNode] + ): ConfigNodeComplexValue = new ConfigNodeArray(nodes) } diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeConcatenation.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeConcatenation.scala index 0d4e11f7..55e6341c 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeConcatenation.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeConcatenation.scala @@ -5,6 +5,8 @@ import java.{util => ju} final class ConfigNodeConcatenation private[impl] ( children: ju.Collection[AbstractConfigNode] ) extends ConfigNodeComplexValue(children) { - override def newNode(nodes: ju.Collection[AbstractConfigNode]) = + override def newNode( + nodes: ju.Collection[AbstractConfigNode] + ): ConfigNodeComplexValue = new ConfigNodeConcatenation(nodes) } diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeObject.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeObject.scala index 1a57855c..34a11f26 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeObject.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeObject.scala @@ -8,7 +8,9 @@ import scala.util.control.Breaks._ final class ConfigNodeObject private[impl] ( _children: ju.Collection[AbstractConfigNode] ) extends ConfigNodeComplexValue(_children) { - override def newNode(nodes: ju.Collection[AbstractConfigNode]) = + override def newNode( + nodes: ju.Collection[AbstractConfigNode] + ): ConfigNodeComplexValue = new ConfigNodeObject(nodes) def hasValue(desiredPath: Path): Boolean = diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeRoot.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeRoot.scala index f27ad1af..c5934d71 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeRoot.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNodeRoot.scala @@ -10,7 +10,9 @@ final class ConfigNodeRoot private[impl] ( _children: ju.Collection[AbstractConfigNode], val origin: ConfigOrigin ) extends ConfigNodeComplexValue(_children) { - override def newNode(nodes: ju.Collection[AbstractConfigNode]) = + override def newNode( + nodes: ju.Collection[AbstractConfigNode] + ): ConfigNodeComplexValue = throw new ConfigException.BugOrBroken("Tried to indent the root object") private[impl] def value: ConfigNodeComplexValue = diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNull.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNull.scala index 4b2a90db..a725b2b7 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNull.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigNull.scala @@ -36,7 +36,8 @@ final class ConfigNull(origin: ConfigOrigin) sb.append("null") } - override def newCopy(origin: ConfigOrigin) = new ConfigNull(origin) + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = + new ConfigNull(origin) // serialization all goes through SerializedConfigValue @throws[ObjectStreamException] diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigReference.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigReference.scala index 406cc03c..f532e275 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigReference.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigReference.scala @@ -5,6 +5,7 @@ import java.{util => ju} import org.ekrich.config.ConfigException import org.ekrich.config.ConfigOrigin import org.ekrich.config.ConfigRenderOptions +import org.ekrich.config.ConfigValueType /** * ConfigReference replaces ConfigReference (the older class kept for back @@ -24,9 +25,9 @@ final class ConfigReference( new ConfigException.NotResolved( "need to Config#resolve(), see the API docs for Config#resolve(); substitution not resolved: " + this ) - override def valueType = throw notResolved - override def unwrapped = throw notResolved - override def newCopy(newOrigin: ConfigOrigin) = + override def valueType: ConfigValueType = throw notResolved + override def unwrapped: AnyRef = throw notResolved + override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue = new ConfigReference(newOrigin, expression, prefixLength) override def ignoresFallbacks = false override def unmergedValues: ju.Collection[ConfigReference] = diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigString.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigString.scala index 4f405e5d..a74b2ee2 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigString.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/ConfigString.scala @@ -16,7 +16,7 @@ object ConfigString { origin: ConfigOrigin, value: String ) extends ConfigString(origin, value) { - override def newCopy(origin: ConfigOrigin) = + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = new ConfigString.Quoted(origin, value) // serialization all goes through SerializedConfigValue @@ -36,7 +36,7 @@ object ConfigString { origin: ConfigOrigin, value: String ) extends ConfigString(origin, value) { - override def newCopy(origin: ConfigOrigin) = + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = new ConfigString.Unquoted(origin, value) @throws[ObjectStreamException] diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/Parseable.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/Parseable.scala index e3cfbdb7..4d35d540 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/Parseable.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/Parseable.scala @@ -113,7 +113,9 @@ object Parseable { ) extends Parseable(options) { postConstruct(options) @throws[IOException] - override protected def reader() = throw new FileNotFoundException(message) + override protected def reader(): Reader = throw new FileNotFoundException( + message + ) override protected def createOrigin(): ConfigOrigin = SimpleConfigOrigin.newSimple(what) } @@ -184,7 +186,7 @@ object Parseable { postConstruct(options) } @throws[IOException] - override protected def reader() = + override protected def reader(): Reader = throw new ConfigException.BugOrBroken( "reader() without options should not be called on ParseableURL" ) @@ -341,7 +343,7 @@ object Parseable { with Relativizer { postConstruct(options) @throws[IOException] - override protected def reader() = + override protected def reader(): Reader = throw new ConfigException.BugOrBroken( "reader() should not be called on resources" ) @@ -445,7 +447,7 @@ object Parseable { ) extends Parseable(options) { postConstruct(options) @throws[IOException] - override protected def reader() = + override protected def reader(): Reader = throw new ConfigException.BugOrBroken( "reader() should not be called on props" ) diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SerializedConfigValue.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SerializedConfigValue.scala index 36abbe4a..a23e047c 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SerializedConfigValue.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SerializedConfigValue.scala @@ -27,6 +27,7 @@ import org.ekrich.config.ConfigList import org.ekrich.config.ConfigObject import org.ekrich.config.ConfigOrigin import org.ekrich.config.ConfigValue +import org.ekrich.config.ConfigValueType /** * Deliberately shoving all the serialization code into this class instead of @@ -398,9 +399,10 @@ class SerializedConfigValue() // this has to be public for the Java deserializer in.readFully(bytes) new DataInputStream(new ByteArrayInputStream(bytes)) } - override def valueType = throw SerializedConfigValue.shouldNotBeUsed - override def unwrapped = throw SerializedConfigValue.shouldNotBeUsed - override def newCopy(origin: ConfigOrigin) = + override def valueType: ConfigValueType = + throw SerializedConfigValue.shouldNotBeUsed + override def unwrapped: AnyRef = throw SerializedConfigValue.shouldNotBeUsed + override def newCopy(origin: ConfigOrigin): AbstractConfigValue = throw SerializedConfigValue.shouldNotBeUsed override final def toString: String = getClass.getSimpleName + "(value=" + value + ",wasConfig=" + wasConfig + ")" diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigDocument.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigDocument.scala index 4a6577aa..421d1deb 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigDocument.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigDocument.scala @@ -38,7 +38,7 @@ final class SimpleConfigDocument private[impl] ( options = options.setOriginComments(false) withValueText(path, newValue.render(options).trim) } - override def withoutPath(path: String) = + override def withoutPath(path: String): ConfigDocument = new SimpleConfigDocument( configNodeTree.setValue(path, null, parseOptions.getSyntax), parseOptions diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigList.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigList.scala index a8b11faa..d39c5d5c 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigList.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigList.scala @@ -269,28 +269,29 @@ final class SimpleConfigList( override def toArray: Array[Object] = value.toArray override def toArray[T](a: Array[T with Object]): Array[T with Object] = value.toArray[T](a) - override def add(e: ConfigValue) = + override def add(e: ConfigValue): Boolean = throw SimpleConfigList.weAreImmutable("add") override def add(index: Int, element: ConfigValue): Unit = { throw SimpleConfigList.weAreImmutable("add") } - override def addAll(c: ju.Collection[_ <: ConfigValue]) = + override def addAll(c: ju.Collection[_ <: ConfigValue]): Boolean = throw SimpleConfigList.weAreImmutable("addAll") - override def addAll(index: Int, c: ju.Collection[_ <: ConfigValue]) = + override def addAll(index: Int, c: ju.Collection[_ <: ConfigValue]): Boolean = throw SimpleConfigList.weAreImmutable("addAll") override def clear(): Unit = { throw SimpleConfigList.weAreImmutable("clear") } - override def remove(o: Any) = throw SimpleConfigList.weAreImmutable("remove") - override def remove(index: Int) = + override def remove(o: Any): Boolean = throw SimpleConfigList.weAreImmutable("remove") - override def removeAll(c: ju.Collection[_]) = + override def remove(index: Int): ConfigValue = + throw SimpleConfigList.weAreImmutable("remove") + override def removeAll(c: ju.Collection[_]): Boolean = throw SimpleConfigList.weAreImmutable("removeAll") - override def retainAll(c: ju.Collection[_]) = + override def retainAll(c: ju.Collection[_]): Boolean = throw SimpleConfigList.weAreImmutable("retainAll") - override def set(index: Int, element: ConfigValue) = + override def set(index: Int, element: ConfigValue): ConfigValue = throw SimpleConfigList.weAreImmutable("set") - override def newCopy(newOrigin: ConfigOrigin) = + override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue = new SimpleConfigList(newOrigin, value) final private[impl] def concatenate(other: SimpleConfigList) = { val combinedOrigin = SimpleConfigOrigin.mergeOrigins(origin, other.origin) diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigObject.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigObject.scala index 18c0750f..f4536b5b 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigObject.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleConfigObject.scala @@ -593,7 +593,8 @@ final class SimpleConfigObject( override def size: Int = value.size - override def values = new ju.HashSet[ConfigValue](value.values) + override def values: ju.Collection[ConfigValue] = + new ju.HashSet[ConfigValue](value.values) // serialization all goes through SerializedConfigValue @throws[ObjectStreamException] diff --git a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleIncludeContext.scala b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleIncludeContext.scala index 12adbd66..423363e1 100644 --- a/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleIncludeContext.scala +++ b/sconfig/shared/src/main/scala/org/ekrich/config/impl/SimpleIncludeContext.scala @@ -26,7 +26,9 @@ class SimpleIncludeContext(parseable: Parseable, options: ConfigParseOptions) override def parseOptions: ConfigParseOptions = options - override def setParseOptions(options: ConfigParseOptions) = + override def setParseOptions( + options: ConfigParseOptions + ): ConfigIncludeContext = new SimpleIncludeContext( parseable, options.setSyntax(null).setOriginDescription(null)