diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b9450b..548b349 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,8 @@ jobs: with: java-version: "adopt@1.8" - uses: coursier/cache-action@v5 + - name: Formatting + run: sbt lint - name: Unit tests run: sbt "++${{ matrix.scalaversion }}" "${{ env.PROJECT_NAME }}/test" - name: Test generate documentation diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..085a276 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,16 @@ +rules = [ + ExplicitResultTypes + LeakingImplicitClassVal + NoAutoTupling + NoValInForComprehension + OrganizeImports + ProcedureSyntax + RemoveUnused +] +OrganizeImports { + # Allign with IntelliJ IDEA so that they don't fight each other + groupedImports = Merge +} +RemoveUnused { + imports = false // handled by OrganizeImports +} diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..ddba29e --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,7 @@ +version = "2.7.5" +preset=Scala.js +maxColumn = 100 +newlines.alwaysBeforeMultilineDef = false +rewrite.rules = [AvoidInfix, PreferCurlyFors] +docstrings.style = AsteriskSpace +danglingParentheses.ctrlSite = false diff --git a/build.sbt b/build.sbt index 8b2e61a..33daa4a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,50 +1,77 @@ -// shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released +// shadow sbt-scalajs' crossProject until Scala.js 1.0.0 is released import com.typesafe.tools.mima.core._ -import sbtcrossproject.{crossProject, CrossType} +import sbtcrossproject.crossProject val previousVersion = "1.1.1" -inThisBuild(Def.settings( - crossScalaVersions := Seq("2.12.13", "2.11.12", "2.13.4"), - scalaVersion := crossScalaVersions.value.head, - version := "1.1.2-SNAPSHOT", - organization := "org.portable-scala", - - scalacOptions ++= Seq( - "-deprecation", - "-feature", - "-encoding", - "utf-8", - "-Xfatal-warnings", - ), - - homepage := Some(url("https://github.com/portable-scala/portable-scala-reflect")), - licenses += ("BSD New", - url("https://github.com/portable-scala/portable-scala-reflect/blob/master/LICENSE")), - scmInfo := Some(ScmInfo( - url("https://github.com/portable-scala/portable-scala-reflect"), - "scm:git:git@github.com:portable-scala/portable-scala-reflect.git", - Some("scm:git:git@github.com:portable-scala/portable-scala-reflect.git"))), -)) +inThisBuild( + Def.settings( + crossScalaVersions := Seq("2.13.4", "2.12.13", "2.11.12"), + scalaVersion := crossScalaVersions.value.head, + version := "1.1.2-SNAPSHOT", + organization := "org.portable-scala", + scalacOptions ++= Seq( + "-deprecation", + "-feature", + "-encoding", + "utf-8", + "-Ywarn-unused" + ) ++ { + if (sys.env.contains("CI")) { + List("-Xfatal-warnings") + } else { + List() // to enable Scalafix locally + } + }, + semanticdbEnabled := true, + semanticdbOptions += "-P:semanticdb:synthetics:on", + semanticdbVersion := scalafixSemanticdb.revision, + ThisBuild / scalafixScalaBinaryVersion := CrossVersion + .binaryScalaVersion(scalaVersion.value), + ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0", + libraryDependencies ++= List( + ("com.github.ghik" % "silencer-lib" % "1.7.3" % Provided).cross(CrossVersion.full), + compilerPlugin( + ("com.github.ghik" % "silencer-plugin" % "1.7.3").cross(CrossVersion.full) + ) + ), + homepage := Some(url("https://github.com/portable-scala/portable-scala-reflect")), + licenses += ("BSD New", + url("https://github.com/portable-scala/portable-scala-reflect/blob/master/LICENSE")), + scmInfo := Some(ScmInfo(url("https://github.com/portable-scala/portable-scala-reflect"), + "scm:git:git@github.com:portable-scala/portable-scala-reflect.git", + Some("scm:git:git@github.com:portable-scala/portable-scala-reflect.git"))) + )) lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file(".")) .settings( - scalacOptions in (Compile, doc) -= "-Xfatal-warnings", - - mimaPreviousArtifacts += - organization.value %%% moduleName.value % previousVersion, - - publishMavenStyle := true, - publishTo := { - val nexus = "https://oss.sonatype.org/" - if (isSnapshot.value) - Some("snapshots" at nexus + "content/repositories/snapshots") - else - Some("releases" at nexus + "service/local/staging/deploy/maven2") - }, - pomExtra := ( - + scalacOptions in (Compile, doc) -= "-Xfatal-warnings", + mimaPreviousArtifacts += + organization.value %%% moduleName.value % previousVersion, + mimaBinaryIssueFilters ++= List( + /* `MacroCompat` has been removed, it was needed for Scala 2.10 only */ + ProblemFilters.exclude[MissingClassProblem]( + "org.portablescala.reflect.internal.Macros$MacroCompat$"), + ProblemFilters.exclude[MissingClassProblem]( + "org.portablescala.reflect.internal.Macros$MacroCompat$Scope1$"), + ProblemFilters.exclude[MissingClassProblem]( + "org.portablescala.reflect.internal.Macros$MacroCompat$Scope2$"), + ProblemFilters.exclude[MissingClassProblem]( + "org.portablescala.reflect.internal.Macros$MacroCompat$Scope2$Inner$"), + ProblemFilters.exclude[MissingClassProblem]( + "org.portablescala.reflect.internal.Macros$MacroCompat$Scope1$blackbox$") + ), + publishMavenStyle := true, + publishTo := { + val nexus = "https://oss.sonatype.org/" + if (isSnapshot.value) + Some("snapshots".at(nexus + "content/repositories/snapshots")) + else + Some("releases".at(nexus + "service/local/staging/deploy/maven2")) + }, + pomExtra := ( + sjrd Sébastien Doeraene @@ -61,22 +88,28 @@ lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform, Native https://github.com/densh/ - ), - pomIncludeRepository := { _ => false }, + ), + pomIncludeRepository := { _ => false } ) .jvmSettings( - // Macros - libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided, - - // Speed up compilation a bit. Our .java files do not need to see the .scala files. - compileOrder := CompileOrder.JavaThenScala, - - libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test", + // Macros + libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided, + // Speed up compilation a bit. Our .java files do not need to see the .scala files. + compileOrder := CompileOrder.JavaThenScala, + libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test" ) .jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)) .nativeSettings( - libraryDependencies += - "org.scala-native" %%% "junit-runtime" % "0.4.0" % "test", - addCompilerPlugin( - "org.scala-native" % "junit-plugin" % "0.4.0" cross CrossVersion.full), + libraryDependencies += + "org.scala-native" %%% "junit-runtime" % "0.4.0" % "test", + addCompilerPlugin(("org.scala-native" % "junit-plugin" % "0.4.0").cross(CrossVersion.full)) ) + +addCommandAlias( + "fix", + "; all compile:scalafix test:scalafix; all scalafmtSbt scalafmtAll" +) +addCommandAlias( + "lint", + "; scalafmtSbtCheck; scalafmtCheckAll; compile:scalafix --check; test:scalafix --check" +) diff --git a/js/src/main/scala/org/portablescala/reflect/Reflect.scala b/js/src/main/scala/org/portablescala/reflect/Reflect.scala index b1a521e..1311784 100644 --- a/js/src/main/scala/org/portablescala/reflect/Reflect.scala +++ b/js/src/main/scala/org/portablescala/reflect/Reflect.scala @@ -1,8 +1,11 @@ package org.portablescala.reflect +import com.github.ghik.silencer.silent + import scala.scalajs.reflect.{Reflect => SJSReflect} object Reflect { + /** Reflectively looks up a loadable module class. * * A module class is the technical term referring to the class of a Scala @@ -34,10 +37,10 @@ object Reflect { * Fully-qualified name of the module class, including its trailing `$` * * @param loader - * Ignored + * Ignored, used in the JVM variant and we need to keep the API */ def lookupLoadableModuleClass(fqcn: String, - loader: ClassLoader): Option[LoadableModuleClass] = { + @silent("never used") loader: ClassLoader): Option[LoadableModuleClass] = { lookupLoadableModuleClass(fqcn) } @@ -72,10 +75,10 @@ object Reflect { * Fully-qualified name of the class * * @param loader - * Ignored + * Ignored, used in the JVM variant and we need to keep the API */ def lookupInstantiatableClass(fqcn: String, - loader: ClassLoader): Option[InstantiatableClass] = { + @silent("never used") loader: ClassLoader): Option[InstantiatableClass] = { lookupInstantiatableClass(fqcn) } } diff --git a/jvm/src/main/scala/org/portablescala/reflect/InstantiatableClass.scala b/jvm/src/main/scala/org/portablescala/reflect/InstantiatableClass.scala index 5bb8480..0ee05d7 100644 --- a/jvm/src/main/scala/org/portablescala/reflect/InstantiatableClass.scala +++ b/jvm/src/main/scala/org/portablescala/reflect/InstantiatableClass.scala @@ -8,9 +8,10 @@ import java.lang.reflect.InvocationTargetException * The `java.lang.Class[_]` representing the class. */ final class InstantiatableClass private[reflect] (val runtimeClass: Class[_]) { + /** A list of the public constructors declared in this class. */ val declaredConstructors: List[InvokableConstructor] = - runtimeClass.getConstructors().map(new InvokableConstructor(_)).toList + runtimeClass.getConstructors.map(new InvokableConstructor(_)).toList /** Instantiates this class using its zero-argument constructor. * @@ -26,12 +27,6 @@ final class InstantiatableClass private[reflect] (val runtimeClass: Class[_]) { throw e.getCause case e: NoSuchMethodException => throw new InstantiationException(runtimeClass.getName).initCause(e) - case _: IllegalAccessException => - /* The constructor exists but is private; make it look like it does not - * exist at all. - */ - throw new InstantiationException(runtimeClass.getName).initCause( - new NoSuchMethodException(runtimeClass.getName + ".()")) } } @@ -42,8 +37,7 @@ final class InstantiatableClass private[reflect] (val runtimeClass: Class[_]) { */ def getConstructor(parameterTypes: Class[_]*): Option[InvokableConstructor] = { try { - Some(new InvokableConstructor( - runtimeClass.getConstructor(parameterTypes: _*))) + Some(new InvokableConstructor(runtimeClass.getConstructor(parameterTypes: _*))) } catch { case _: NoSuchMethodException => None } diff --git a/jvm/src/main/scala/org/portablescala/reflect/InvokableConstructor.scala b/jvm/src/main/scala/org/portablescala/reflect/InvokableConstructor.scala index a546b74..224a744 100644 --- a/jvm/src/main/scala/org/portablescala/reflect/InvokableConstructor.scala +++ b/jvm/src/main/scala/org/portablescala/reflect/InvokableConstructor.scala @@ -1,13 +1,14 @@ package org.portablescala.reflect -import java.lang.reflect.Constructor +import java.lang.reflect._ /** A description of a constructor that can reflectively invoked. */ final class InvokableConstructor private[reflect] (ctor: Constructor[_]) { + /** The `Class[_]` objects representing the formal parameters of this * constructor. */ - val parameterTypes: List[Class[_]] = ctor.getParameterTypes().toList + val parameterTypes: List[Class[_]] = ctor.getParameterTypes.toList /** Invokes this constructor to instantiate a new object. * @@ -22,12 +23,8 @@ final class InvokableConstructor private[reflect] (ctor: Constructor[_]) { try { ctor.newInstance(args.asInstanceOf[Seq[AnyRef]]: _*) } catch { - case e: java.lang.reflect.InvocationTargetException => - val cause = e.getCause - if (cause == null) - throw e - else - throw cause + case e: InvocationTargetException if e.getCause != null => + throw e.getCause } } } diff --git a/jvm/src/main/scala/org/portablescala/reflect/LoadableModuleClass.scala b/jvm/src/main/scala/org/portablescala/reflect/LoadableModuleClass.scala index e77e76c..0897786 100644 --- a/jvm/src/main/scala/org/portablescala/reflect/LoadableModuleClass.scala +++ b/jvm/src/main/scala/org/portablescala/reflect/LoadableModuleClass.scala @@ -6,6 +6,7 @@ package org.portablescala.reflect * The `java.lang.Class[_]` representing the module class. */ final class LoadableModuleClass private[reflect] (val runtimeClass: Class[_]) { + /** Loads the module instance and returns it. * * If the underlying constructor throws an exception `e`, then `loadModule` @@ -16,12 +17,8 @@ final class LoadableModuleClass private[reflect] (val runtimeClass: Class[_]) { try { runtimeClass.getField("MODULE$").get(null) } catch { - case e: java.lang.ExceptionInInitializerError => - val cause = e.getCause - if (cause == null) - throw e - else - throw cause + case e: ExceptionInInitializerError if e.getCause != null => + throw e.getCause } } } diff --git a/jvm/src/main/scala/org/portablescala/reflect/Reflect.scala b/jvm/src/main/scala/org/portablescala/reflect/Reflect.scala index d3045c7..fcb0dde 100644 --- a/jvm/src/main/scala/org/portablescala/reflect/Reflect.scala +++ b/jvm/src/main/scala/org/portablescala/reflect/Reflect.scala @@ -1,11 +1,12 @@ package org.portablescala.reflect -import scala.language.experimental.macros -import scala.collection.mutable -import java.lang.reflect._ import org.portablescala.reflect.annotation._ import org.portablescala.reflect.internal.Macros +import java.lang.reflect._ +import scala.collection.mutable +import scala.language.experimental.macros + object Reflect { /** Reflectively looks up a loadable module class using the current class @@ -52,8 +53,7 @@ object Reflect { * @param loader * Class loader to use to load the module class */ - def lookupLoadableModuleClass(fqcn: String, - loader: ClassLoader): Option[LoadableModuleClass] = { + def lookupLoadableModuleClass(fqcn: String, loader: ClassLoader): Option[LoadableModuleClass] = { load(fqcn, loader).filter(isModuleClass).map(new LoadableModuleClass(_)) } @@ -101,8 +101,7 @@ object Reflect { * @param loader * Class loader to use to load the class */ - def lookupInstantiatableClass(fqcn: String, - loader: ClassLoader): Option[InstantiatableClass] = { + def lookupInstantiatableClass(fqcn: String, loader: ClassLoader): Option[InstantiatableClass] = { load(fqcn, loader).filter(isInstantiatableClass).map(new InstantiatableClass(_)) } @@ -121,10 +120,10 @@ object Reflect { * inner class (non-local), both are the same non-null class. */ def isLocalClass: Boolean = - clazz.getEnclosingClass() != clazz.getDeclaringClass() + clazz.getEnclosingClass != clazz.getDeclaringClass - (clazz.getModifiers() & Modifier.ABSTRACT) == 0 && - clazz.getConstructors().length > 0 && + (clazz.getModifiers & Modifier.ABSTRACT) == 0 && + clazz.getConstructors.length > 0 && !isModuleClass(clazz) && !isLocalClass } @@ -136,8 +135,7 @@ object Reflect { * `loadModule`. */ val clazz = Class.forName(fqcn, false, loader) - if (inheritsAnnotation(clazz)) Some(clazz) - else None + Some(clazz).filter(inheritsAnnotation) } catch { case _: ClassNotFoundException => None } diff --git a/jvm/src/main/scala/org/portablescala/reflect/internal/Macros.scala b/jvm/src/main/scala/org/portablescala/reflect/internal/Macros.scala index c781486..b3a120a 100644 --- a/jvm/src/main/scala/org/portablescala/reflect/internal/Macros.scala +++ b/jvm/src/main/scala/org/portablescala/reflect/internal/Macros.scala @@ -2,6 +2,8 @@ package org.portablescala.reflect.internal import org.portablescala.reflect._ +import scala.reflect.macros.blackbox + /* Macro definitions are enclosed in a dedicated `Macros` object, * so that their metadata (the types involved etc.) don't pollute `Reflect`'s metadata. * This enables using `Reflect`'s methods without `scala-reflect` JAR @@ -9,40 +11,20 @@ import org.portablescala.reflect._ * https://github.com/xeno-by/sbt-example-paradise210/issues/1#issuecomment-20996354 */ object Macros { - /** Magic to get cross-compiling access to `blackbox.Context` with a fallback - * on `macros.Context`, without deprecation warning in any Scala version. - */ - private object MacroCompat { - object Scope1 { - object blackbox - } - import Scope1._ - - object Scope2 { - import scala.reflect.macros._ - object Inner { - import blackbox._ - type BlackboxContext = Context - } - } - } - - import MacroCompat.Scope2.Inner.BlackboxContext private def currentClassLoaderExpr( - c: BlackboxContext { type PrefixType = Reflect.type }): c.Expr[ClassLoader] = { + c: blackbox.Context { type PrefixType = Reflect.type }): c.Expr[ClassLoader] = { import c.universe._ val enclosingClassTree = c.reifyEnclosingRuntimeClass if (enclosingClassTree.isEmpty) c.abort(c.enclosingPosition, "call site does not have an enclosing class") val enclosingClassExpr = c.Expr[java.lang.Class[_]](enclosingClassTree) reify { - enclosingClassExpr.splice.getClassLoader() + enclosingClassExpr.splice.getClassLoader } } - def lookupLoadableModuleClass( - c: BlackboxContext { type PrefixType = Reflect.type })( + def lookupLoadableModuleClass(c: blackbox.Context { type PrefixType = Reflect.type })( fqcn: c.Expr[String]): c.Expr[Option[LoadableModuleClass]] = { import c.universe._ val loaderExpr = currentClassLoaderExpr(c) @@ -51,8 +33,7 @@ object Macros { } } - def lookupInstantiatableClass( - c: BlackboxContext { type PrefixType = Reflect.type })( + def lookupInstantiatableClass(c: blackbox.Context { type PrefixType = Reflect.type })( fqcn: c.Expr[String]): c.Expr[Option[InstantiatableClass]] = { import c.universe._ val loaderExpr = currentClassLoaderExpr(c) diff --git a/native/src/main/scala/org/portablescala/reflect/Reflect.scala b/native/src/main/scala/org/portablescala/reflect/Reflect.scala index 9db0a7d..9906ee7 100644 --- a/native/src/main/scala/org/portablescala/reflect/Reflect.scala +++ b/native/src/main/scala/org/portablescala/reflect/Reflect.scala @@ -1,8 +1,11 @@ package org.portablescala.reflect +import com.github.ghik.silencer.silent + import scala.scalanative.reflect.{Reflect => ScalaNativeReflect} object Reflect { + /** Reflectively looks up a loadable module class. * * A module class is the technical term referring to the class of a Scala @@ -34,10 +37,10 @@ object Reflect { * Fully-qualified name of the module class, including its trailing `$` * * @param loader - * Ignored + * Ignored, used in the JVM variant and we need to keep the API */ def lookupLoadableModuleClass(fqcn: String, - loader: ClassLoader): Option[LoadableModuleClass] = { + @silent("never used") loader: ClassLoader): Option[LoadableModuleClass] = { lookupLoadableModuleClass(fqcn) } @@ -72,10 +75,10 @@ object Reflect { * Fully-qualified name of the class * * @param loader - * Ignored + * Ignored, used in the JVM variant and we need to keep the API */ def lookupInstantiatableClass(fqcn: String, - loader: ClassLoader): Option[InstantiatableClass] = { + @silent("never used") loader: ClassLoader): Option[InstantiatableClass] = { lookupInstantiatableClass(fqcn) } } diff --git a/project/plugins.sbt b/project/plugins.sbt index 0301257..59bf49a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,9 +2,12 @@ val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_ != "").getOrElse("1.0.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0") addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0") addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1") + +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.26") diff --git a/shared/src/test/scala/org/portablescala/reflect/ReflectTest.scala b/shared/src/test/scala/org/portablescala/reflect/ReflectTest.scala index 22481b6..aacfa40 100644 --- a/shared/src/test/scala/org/portablescala/reflect/ReflectTest.scala +++ b/shared/src/test/scala/org/portablescala/reflect/ReflectTest.scala @@ -1,13 +1,12 @@ package org.portablescala.reflect -import scala.reflect.ClassTag - +import com.github.ghik.silencer.silent import org.junit.Assert._ -import org.junit.Assume._ import org.junit.Test - import org.portablescala.reflect.annotation.EnableReflectiveInstantiation +import scala.reflect.ClassTag + package subpackage { @EnableReflectiveInstantiation private class PrivateClassEnableDirect { @@ -15,6 +14,7 @@ package subpackage { } } +@silent("never used") class ReflectTest { import ReflectTest.{Accessors, VC, ConstructorThrowsMessage, intercept} @@ -35,7 +35,7 @@ class ReflectTest { private final val NameInnerClass = { Prefix + "ClassWithInnerClassWithEnableReflectiveInstantiation$" + - "InnerClassWithEnableReflectiveInstantiation" + "InnerClassWithEnableReflectiveInstantiation" } private final val NameClassEnableIndirect = @@ -60,7 +60,7 @@ class ReflectTest { private final val NameInnerObject = { Prefix + "ClassWithInnerObjectWithEnableReflectiveInstantiation$" + - "InnerObjectWithEnableReflectiveInstantiation" + "InnerObjectWithEnableReflectiveInstantiation" } private final val NameObjectWithInitialization = @@ -77,7 +77,7 @@ class ReflectTest { def test(name: String): Unit = { val optClassData = Reflect.lookupInstantiatableClass(name) assertTrue(name, optClassData.isDefined) - val classData = optClassData.get + val _ = optClassData.get val runtimeClass = optClassData.get.runtimeClass assertEquals(name, name, runtimeClass.getName) @@ -93,7 +93,7 @@ class ReflectTest { def test(name: String): Unit = { val optClassData = Reflect.lookupLoadableModuleClass(name) assertTrue(name, optClassData.isDefined) - val classData = optClassData.get + val _ = optClassData.get val runtimeClass = optClassData.get.runtimeClass assertEquals(name, name, runtimeClass.getName) @@ -151,8 +151,7 @@ class ReflectTest { } @Test def testClassNoArgCtorErrorCase(): Unit = { - for (name <- Seq(NameClassEnableDirectNoZeroArgCtor, - NameClassEnableIndirectNoZeroArgCtor)) { + for (name <- Seq(NameClassEnableDirectNoZeroArgCtor, NameClassEnableIndirectNoZeroArgCtor)) { val optClassData = Reflect.lookupInstantiatableClass(name) assertTrue(name, optClassData.isDefined) val classData = optClassData.get @@ -163,7 +162,7 @@ class ReflectTest { @Test def testClassCtorWithArgs(): Unit = { for (name <- Seq(NameClassEnableDirect, NameClassEnableDirectNoZeroArgCtor, - NameClassEnableIndirect, NameClassEnableIndirectNoZeroArgCtor)) { + NameClassEnableIndirect, NameClassEnableIndirectNoZeroArgCtor)) { val optClassData = Reflect.lookupInstantiatableClass(name) assertTrue(optClassData.isDefined) val classData = optClassData.get @@ -234,8 +233,7 @@ class ReflectTest { @EnableReflectiveInstantiation class LocalClassWithEnableReflectiveInstantiationInsideMethod - assertCannotFind( - classOf[LocalClassWithEnableReflectiveInstantiationInsideMethod]) + assertCannotFind(classOf[LocalClassWithEnableReflectiveInstantiationInsideMethod]) // In a lambda whose owner is ultimately the constructor of the class assertCannotFind(classInsideLambdaInsideCtor()) @@ -245,8 +243,7 @@ class ReflectTest { @EnableReflectiveInstantiation class LocalClassWithEnableReflectiveInstantiationInsideLambdaInsideMethod - assertCannotFind( - classOf[LocalClassWithEnableReflectiveInstantiationInsideLambdaInsideMethod]) + assertCannotFind(classOf[LocalClassWithEnableReflectiveInstantiationInsideLambdaInsideMethod]) } f() } @@ -323,10 +320,11 @@ class ReflectTest { } } +@silent("never used") object ReflectTest { private final val ConstructorThrowsMessage = "constructor throws" - def intercept[T <: Throwable : ClassTag](body: => Unit): T = { + def intercept[T <: Throwable: ClassTag](body: => Unit): T = { try { body throw new AssertionError("no exception was thrown") @@ -361,8 +359,7 @@ object ReflectTest { } @EnableReflectiveInstantiation - class ClassEnableDirectNoZeroArgCtor(val x: Int, val y: String) - extends Accessors { + class ClassEnableDirectNoZeroArgCtor(val x: Int, val y: String) extends Accessors { def this(x: Int) = this(x, "ClassEnableDirectNoZeroArgCtor") def this(vc: VC) = this(vc.self.toInt * 2) @@ -380,8 +377,7 @@ object ReflectTest { trait TraitEnableDirect extends Accessors @EnableReflectiveInstantiation - abstract class AbstractClassEnableDirect(val x: Int, val y: String) - extends Accessors { + abstract class AbstractClassEnableDirect(val x: Int, val y: String) extends Accessors { def this(x: Int) = this(x, "AbstractClassEnableDirect") def this() = this(-1) @@ -392,16 +388,14 @@ object ReflectTest { } @EnableReflectiveInstantiation - class ClassNoPublicConstructorEnableDirect private (val x: Int, val y: String) - extends Accessors { + class ClassNoPublicConstructorEnableDirect private (val x: Int, val y: String) extends Accessors { //protected def this(y: String) = this(-5, y) } class ClassWithInnerClassWithEnableReflectiveInstantiation(_x: Int) { @EnableReflectiveInstantiation - class InnerClassWithEnableReflectiveInstantiation(_y: String) - extends Accessors { + class InnerClassWithEnableReflectiveInstantiation(_y: String) extends Accessors { val x = _x val y = _y } @@ -412,8 +406,7 @@ object ReflectTest { @EnableReflectiveInstantiation trait EnablingTrait - class ClassEnableIndirect(val x: Int, val y: String) - extends EnablingTrait with Accessors { + class ClassEnableIndirect(val x: Int, val y: String) extends EnablingTrait with Accessors { def this(x: Int) = this(x, "ClassEnableIndirect") def this() = this(-1) @@ -450,8 +443,7 @@ object ReflectTest { private def this(d: Double) = this(d.toInt) } - class ClassNoPublicConstructorEnableIndirect private ( - val x: Int, val y: String) + class ClassNoPublicConstructorEnableIndirect private (val x: Int, val y: String) extends EnablingTrait with Accessors { //protected def this(y: String) = this(-5, y)