Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update format
Browse files Browse the repository at this point in the history
ekrich committed Jan 21, 2022
1 parent 94702f5 commit a5ac308
Showing 131 changed files with 2,951 additions and 2,791 deletions.
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ def versionFmt(out: sbtdynver.GitDescribeOutput): String = {

val dotcOpts = List("-unchecked", "-deprecation", "-feature")
val scalacOpts = dotcOpts ++ List(
//"-Ywarn-unused:imports", // no 2.11 - maybe time for sbt-tpolecat
// "-Ywarn-unused:imports", // no 2.11 - maybe time for sbt-tpolecat
"-Xsource:3"
//"-Xlint:nonlocal-return" // no 2.11/2.12
// "-Xlint:nonlocal-return" // no 2.11/2.12
)

Compile / console / scalacOptions --= Seq(
@@ -46,9 +46,9 @@ val scala300 = "3.1.0"
val javaTime = "1.1.8"
val scCompat = "2.6.0"

val versionsBase = Seq(scala211, scala212, scala213)
val versionsJVM = versionsBase :+ scala300
val versionsJS = versionsJVM
val versionsBase = Seq(scala211, scala212, scala213)
val versionsJVM = versionsBase :+ scala300
val versionsJS = versionsJVM
val versionsNative = versionsJVM

ThisBuild / scalaVersion := scala212
@@ -156,12 +156,12 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
Test / run / fork := true,
// env vars for tests
Test / envVars ++= Map(
"testList.0" -> "0",
"testList.1" -> "1",
"testList.0" -> "0",
"testList.1" -> "1",
"testClassesPath" -> (Test / classDirectory).value.getPath
),
// uncomment for debugging
//Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
// Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
// mima settings
mimaPreviousArtifacts := Set("org.ekrich" %% "sconfig" % prevVersion),
mimaBinaryIssueFilters ++= ignoredABIProblems
@@ -236,7 +236,7 @@ lazy val sharedJvmNativeSource: Seq[Setting[_]] = Def.settings(
lazy val sconfigJVM = sconfig.jvm
.dependsOn(testLibJVM % "test->test")
lazy val sconfigNative = sconfig.native
lazy val sconfigJS = sconfig.js
lazy val sconfigJS = sconfig.js

lazy val ignoredABIProblems = {
import com.typesafe.tools.mima.core._
Original file line number Diff line number Diff line change
@@ -38,8 +38,8 @@ class SimpleLibSettings(config: Config) {

// note that these fields are NOT lazy, because if we're going to
// get any exceptions, we want to get them on startup.
val foo = config.getString("simple-lib.foo")
val hello = config.getString("simple-lib.hello")
val foo = config.getString("simple-lib.foo")
val hello = config.getString("simple-lib.hello")
val whatever = config.getString("simple-lib.whatever")
}

12 changes: 6 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -2,20 +2,20 @@
resolvers += Resolver.sonatypeRepo("snapshots")

// versions
val crossVer = "1.1.0"
val scalaJSVersion = "1.8.0"
val crossVer = "1.1.0"
val scalaJSVersion = "1.8.0"
val scalaNativeVersion = "0.4.3-RC2"

// includes sbt-dynver sbt-pgp sbt-sonatype sbt-git
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")

// Scala Native support
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % crossVer)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)

// Scala.js support
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
Original file line number Diff line number Diff line change
@@ -97,7 +97,8 @@ private object ConfigParseOptionsEmptyParenFunCall
"getClassLoader",
"getIncluder",
"getOriginDescription",
"getSyntax")
"getSyntax"
)

private object ConfigRenderOptionsEmptyParenFunCall
extends AbstractEmptyParenFunCall(
@@ -107,7 +108,8 @@ private object ConfigRenderOptionsEmptyParenFunCall
"getComments",
"getFormatted",
"getJson",
"getOriginComments")
"getOriginComments"
)

private object ConfigResolveOptionsEmptyParenFunCall
extends AbstractEmptyParenFunCall(
@@ -116,31 +118,38 @@ private object ConfigResolveOptionsEmptyParenFunCall
"getAllowUnresolved",
"getResolver",
"getUseSystemEnvironment",
"noSystem")
"noSystem"
)

private object ConfigDocumentEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Symbol("com/typesafe/config/parser/ConfigDocument#"),
"render")
"render"
)

private object ConfigNodeEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Symbol("com/typesafe/config/parser/ConfigNode#"),
"render")
"render"
)

private abstract class AbstractEmptyParenFunCall(
typesafeConfigSymbol: Symbol,
atLeastOneMethodName: String,
emptyParenMethodNames: String*) {
emptyParenMethodNames: String*
) {
def unapply(tree: Tree)(implicit doc: SemanticDocument): Option[Term] =
EmptyParenFunCallsOnSymbol(typesafeConfigSymbol,
atLeastOneMethodName +: emptyParenMethodNames,
tree)
EmptyParenFunCallsOnSymbol(
typesafeConfigSymbol,
atLeastOneMethodName +: emptyParenMethodNames,
tree
)
}

private object EmptyParenFunCallsOnSymbol {
def apply(symbol: Symbol, methodNames: Seq[String], tree: Tree)(
implicit doc: SemanticDocument): Option[Term] = {
def apply(symbol: Symbol, methodNames: Seq[String], tree: Tree)(implicit
doc: SemanticDocument
): Option[Term] = {

object SelectSymbolEmptyParenMethod {
def unapply(subtree: Tree)(implicit doc: SemanticDocument): Option[Term] =
@@ -156,12 +165,15 @@ private object EmptyParenFunCallsOnSymbol {
}

object SymbolEmptyParenMethod {
def unapply(term: Term.Name)(
implicit doc: SemanticDocument): Option[MethodSignature] =
def unapply(
term: Term.Name
)(implicit doc: SemanticDocument): Option[MethodSignature] =
PartialFunction.condOpt(term) {
case Term.Name(name) & XSymbol(
XSymbol.Owner(DoesSymbolHaveCorrectType()) & XSignature(
sig: MethodSignature)) if methodNames contains name =>
sig: MethodSignature
)
) if methodNames contains name =>
sig
}
}
38 changes: 23 additions & 15 deletions scalafix/rules/src/main/scala/org/ekrich/sconfig/fix/package.scala
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@ import scala.util.control.NonFatal
*/
package object fix {

/** Allows to apply multiple extractors/matchers to a single expression in a `case` block.
/**
* Allows to apply multiple extractors/matchers to a single expression in a
* `case` block.
*/
object & {
def unapply[A](a: A): Option[(A, A)] = Some((a, a))
@@ -88,26 +90,31 @@ package object fix {
*/
None
case NonFatal(ex) =>
throw UnexpectedException(sym,
Properties.javaVersion,
Properties.versionString,
ex)
throw UnexpectedException(
sym,
Properties.javaVersion,
Properties.versionString,
ex
)
}
}

object XSemanticType {

/** Tries to infer a result SemanticType of a particular Stat.
/**
* Tries to infer a result SemanticType of a particular Stat.
*
* @note Not all possible cases are handled.
* @note
* Not all possible cases are handled.
*/
def unapply(stat: Stat)(
implicit doc: SemanticDocument): Option[SemanticType] =
def unapply(
stat: Stat
)(implicit doc: SemanticDocument): Option[SemanticType] =
PartialFunction.condOpt(stat) {
case Term.Name(_) & XSymbol(XSignature(ValueSignature(tpe))) => tpe

case Term.Apply(_, _) &
XSymbol(XSignature(ValueSignature(TypeRef(_, funcSym, _ :+ tpe))))
XSymbol(XSignature(ValueSignature(TypeRef(_, funcSym, _ :+ tpe))))
if funcSym.value.startsWith("scala/Function") && funcSym.value
.endsWith("#") =>
tpe
@@ -117,11 +124,12 @@ package object fix {
}
}

case class UnexpectedException(sym: Symbol,
java: String,
scala: String,
cause: Throwable)
extends RuntimeException(
case class UnexpectedException(
sym: Symbol,
java: String,
scala: String,
cause: Throwable
) extends RuntimeException(
s"""An unexpected exception occurred. Please report this as an issue at https://github.com/ekrich/sconfig/issues and include the following information:
|
|Failing symbol: ${sym.value}
Original file line number Diff line number Diff line change
@@ -3,15 +3,16 @@ package org.ekrich.config
import org.ekrich.config.impl.ConfigBeanImpl

/**
* Factory for automatically creating a Java class from a {@link Config}.
* See {@link ConfigBeanFactory#create}.
* Factory for automatically creating a Java class from a {@link Config}. See
* {@link ConfigBeanFactory#create}.
*
* @since 1.3.0
*/
object ConfigBeanFactory {

/**
* Creates an instance of a class, initializing its fields from a {@link Config}.
* Creates an instance of a class, initializing its fields from a {@link
* Config}.
*
* Example usage:
*
@@ -20,27 +21,29 @@ object ConfigBeanFactory {
* val config: FooConfig = ConfigBeanFactory.create(configSource, classOf[FooConfig]);
* }}}
*
* The Java class should follow JavaBean conventions. Field types
* can be any of the types you can normally get from a {@link Config},
* including `java.time.Duration` or {@link ConfigMemorySize}.
* Fields may also be another JavaBean-style
* class.
* The Java class should follow JavaBean conventions. Field types can be any
* of the types you can normally get from a {@link Config}, including
* `java.time.Duration` or {@link ConfigMemorySize}. Fields may also be
* another JavaBean-style class.
*
* Fields are mapped to config by converting the config key to
* camel case. So the key `foo-bar` becomes JavaBean
* setter `setFooBar`.
* Fields are mapped to config by converting the config key to camel case. So
* the key `foo-bar` becomes JavaBean setter `setFooBar`.
*
* @since 1.3.0
* @param config source of config information
* @param clazz class to be instantiated
* @param [T] the type of the class to be instantiated
* @return an instance of the class populated with data from the config
* @param config
* source of config information
* @param clazz
* class to be instantiated
* @param [T]
* the type of the class to be instantiated
* @return
* an instance of the class populated with data from the config
* @throws ConfigException#BadBean
* If something is wrong with the JavaBean
* If something is wrong with the JavaBean
* @throws ConfigException#ValidationFailed
* If the config doesn't conform to the bean's implied schema
* If the config doesn't conform to the bean's implied schema
* @throws ConfigException
* Can throw the same exceptions as the getters on {@link Config}
* Can throw the same exceptions as the getters on {@link Config}
*/
def create[T](config: Config, clazz: Class[T]): T =
ConfigBeanImpl.createInternal(config, clazz)
Loading
Oops, something went wrong.

0 comments on commit a5ac308

Please sign in to comment.