scalac plugin : how to get it working after typer phase with a missing jar

102 views Asked by At

I'm currently trying to build a plugin that visits the AST produced by Scala to run some rule checks. So far, it only pretty prints the AST to get an hand in. AFAK, this plugin may run after different phases, but I tried with those two :

  • namer : If this plugin runs after the namer phase, it is invoked no matter the configuration. It is fine even if lots of symbols are not resolved because of a missing jar.
  • typer : in case of a missing jar, the plug in is not called on the analysis unit, unless I override the hasErrors method of the reporter and set it to false. It doesn't seem the right way to do it.

Am I wrong to believe I have to run the typer phase to be able to achieve my goal as resolution will be done for me. If I'm right, is there a configuration of scalac that could help to issue nodes with unresolved type rather than stopping compilation at compilation unit level ? If I'm wrong, why can't I see any printout from my plugin

Would presentation compiler help then ? Or maybe the idea to go for a plugin is not the right one.

Here is the code use for invocation

object TestJF {
val settings = new Settings


settings.plugin.appendToValue("")
settings.bootclasspath.append("C:\\Users\\JTR\\.ivy2\\cache\\org.scala-lang\\scala-library\\jars\\scala-library-2.11.8.jar")
settings.classpath.append("C:\\Users\\JTR\\.ivy2\\cache\\org.scala-lang\\scala-library\\jars\\scala-library-2.11.8.jar")
settings.classpath.append("C:\\Users\\JTR\\.ivy2\\cache\\org.scala-lang\\scala-library\\jars\\scala-library-2.11.8.jar")
settings.classpath.append("C:\\Users\\JTR\\.ivy2\\cache\\org.scala-lang\\scala-compiler\\jars\\scala-compiler-2.11.8.jar")
// missing jar here to trigger resolution issues
//settings.classpath.append("C:\\Users\\JTR\\.ivy2\\cache\\org.scala-lang\\scala-reflect\\jars\\scala-reflect-2.11.8.jar")

settings.plugin.appendToValue("C:\\Users\\jeff\\IdeaProjects\\scalanyzer\\target\\scala-2.11\\scalanyzer_2.11-1.0.jar")
settings.Yidedebug.value = true
settings.genPhaseGraph.value = "phases"
settings.Ylogcp.value = true
settings.nowarn.value = true


settings.developer.value = true
settings.withErrorFn (err => { println("ERROR" +err) })

val global = Global(settings, new ConsoleReporter(settings)
{
   override def hasErrors: Boolean = false
})


def main (args : Array[String]) : Unit = {
  val run = new global.Run() {
     override def informUnitStarting(phase: Phase, unit: TestJF.global.CompilationUnit): Unit = {
        println(s"Phase ${phase.name} with unit ${unit.source.path}")
     }

  }

      run.compile(List("C:\\Users\\jeff\\IdeaProjects\\untitled\\src\\main\\java\\TestJf.scala"))


}
0

There are 0 answers