I am writing a Scala Compiler Plugin with a component the executes after the "jvm" phase where there is need to know that a method is overridden. Here is a distilled version of a test case I am working on:
abstract class GenericController[T] {
def getPath():String
def save(entity:T):String = "parent"
}
class StatusController extends GenericController[String] {
override def getPath():String = "/statuses"
override def save(entity:String):String = "child"
}
When traversing the AST, I iterate over the classes and the methods ensuring that I only process the methods that are not overridden. The scala.reflect.internal.Symbols.MethodSymbol.overrides() method applied to the symbol for the StatusController.getPath method will include the one for GenericController.getPath.
However, the MethodSymbol.overrides() fails to return the GenericController.save method for the StatusController.save symbol. Seem like the generic type complicates this behavior, Should this be done after another compiler phase?
Let's define test compiler plugin.
core/src/main/scala/Main.scala
plugin/src/main/resources/scalac-plugin.xml
plugin/src/main/scala/compilerPlugin/MyCompilerPlugin.scala
build.sbt
If you run (sbt
reload; clean; plugin/package; core/compile) this compiler plugin aftertyperphase it printsbut if you run it after
jvmphase it printsSo as you can see, after
typerphase, method symbolStatusController.getPathoverrides method symbolGenericController.getPathandStatusController.saveoverridesGenericController.save. And afterjvmphaseStatusController.getPathagain overridesGenericController.getPathbut it's bridgeStatusController.saveinstead of ordinaryStatusController.savethat overridesGenericController.save. So I guess you confused symbol of bridge method with symbol of ordinary method.