gzoller/scala-reflection

Compiler Plugin: it would be nice to be able to annotate classes that you don't want to be analysed by compiler plugin

Closed this issue · 4 comments

I enable the plugin on https://github.com/pjfanning/jackson-scala3-reflection-extensions and it failed with this Mixin class.

object ScalaReflectionExtensions {
  def ::(o: JsonMapper) = new Mixin(o)
  final class Mixin private[ScalaReflectionExtensions](mapper: JsonMapper)
    extends JsonMapper(mapper.rebuild().build()) with ScalaReflectionExtensions
}

This is not a class that I need scala-reflection to worry about - but this class makes plugin fail the entire build.

[error] co.blocke.scala_reflection.ReflectException: Class [com.github.pjfanning.jackson.reflection.ScalaReflectionExtensions$.Mixin]: Non-case class constructor arguments must all be 'val'
[error] 	at co.blocke.scala_reflection.impl.TastyReflection$.$anonfun$11(TastyReflection.scala:362)
[error] 	at scala.collection.immutable.List.map(List.scala:246)
[error] 	at co.blocke.scala_reflection.impl.TastyReflection$.reflectOnClass(TastyReflection.scala:365)
[error] 	at co.blocke.scala_reflection.impl.TastyReflection$.reflectOnType$$anonfun$3(TastyReflection.scala:97)
[error] 	at scala.Option.getOrElse(Option.scala:201)
[error] 	at co.blocke.scala_reflection.impl.TastyReflection$.reflectOnType(TastyReflection.scala:98)
[error] 	at co.blocke.scala_reflection.RType$.unwindType$$anonfun$1(RType.scala:205)
[error] 	at scala.collection.mutable.HashMap.getOrElse(HashMap.scala:436)
[error] 	at co.blocke.scala_reflection.RType$.unwindType(RType.scala:208)
[error] 	at co.blocke.scala_reflection.ReflectionWorkerPhase.transformTypeDef(ReflectionWorker.scala:44)
[error] 	at dotty.tools.dotc.transform.MegaPhase.goTypeDef(MegaPhase.scala:989)
[error] 	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:257)

This looks related to #17 - same TastyReflection error

Yep, I saw that. I like this idea so let me have a look and see about some annotation to tell scala-reflection to ignore a class.

Done. In next release you can annotate classes/traits with @Skip_Reflection and these will return an RType of UnknownInfo. They have to return something for the parser to work.

Release 1.1.0 is out and now supports 3.0.2, has the new @Skip_Reflection annotation, allows non-val constructors, and cleans up the bug for a class created inside an object. Enjoy! 1.1.1 (not yet released) will be a 3.1.0 build.