diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-12-07 16:55:38 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-12-30 19:07:05 +0300 |
commit | 4d92aec651def608628a2275e1b6bf2d1fcbabe7 (patch) | |
tree | d1d51ad3d92343c4345b0b454835a4053234508d /test/files/run/macroPlugins-namerHooks.scala | |
parent | 6c7b003003e6cb6a1f0b00f79f784e6deea37a39 (diff) | |
download | scala-4d92aec651def608628a2275e1b6bf2d1fcbabe7.tar.gz scala-4d92aec651def608628a2275e1b6bf2d1fcbabe7.tar.bz2 scala-4d92aec651def608628a2275e1b6bf2d1fcbabe7.zip |
unprivates important helpers in Namers.scala
This is the first of two commits that enable hooks necessary to implement
macro annotations in an honest, hackless compiler plugin.
This particular commit turns certain helpers into public methods. Of course,
there is a probability that with the evolution of macro paradise, I will need
more helper methods, and those will have to be called via reflection, but
at least for now it's nice to have a reflection-less plugin :)
Diffstat (limited to 'test/files/run/macroPlugins-namerHooks.scala')
-rw-r--r-- | test/files/run/macroPlugins-namerHooks.scala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/files/run/macroPlugins-namerHooks.scala b/test/files/run/macroPlugins-namerHooks.scala new file mode 100644 index 0000000000..b0f29cbbed --- /dev/null +++ b/test/files/run/macroPlugins-namerHooks.scala @@ -0,0 +1,38 @@ +import scala.tools.partest._ +import scala.tools.nsc._ + +object Test extends DirectTest { + override def extraSettings: String = "-usejavacp" + + def code = """ + case class C(x: Int, y: Int) + """.trim + + def show() { + val global = newCompiler() + import global._ + import analyzer._ + + val output = collection.mutable.ListBuffer[String]() + + object macroPlugin extends MacroPlugin { + override def pluginsEnterSym(namer: Namer, tree: Tree): Boolean = { + output += s"enterSym(${tree.toString.replace('\n', ' ')})" + namer.enterSym(tree) + true + } + override def pluginsEnsureCompanionObject(namer: Namer, cdef: ClassDef, creator: ClassDef => Tree = companionModuleDef(_)): Option[Symbol] = { + output += s"ensureCompanionObject(${cdef.toString.replace('\n', ' ')}, ...)" + Some(namer.ensureCompanionObject(cdef, creator)) + } + override def pluginsEnterStats(typer: Typer, stats: List[Tree]): List[Tree] = { + stats.foreach(stat => output += s"enterStat(${stat.toString.replace('\n', ' ')})") + stats + } + } + + addMacroPlugin(macroPlugin) + compileString(global)(code) + println(output.mkString("\n")) + } +} |