Created
August 20, 2010 13:23
-
-
Save jto/540298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jto.demo | |
object HelloWorld { | |
def main(args: Array[String]) { | |
println("Hello, world!") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jto.scala.compiler.plugins | |
import scala.tools.nsc._ | |
import scala.tools.nsc.plugins._ | |
import scala.tools.nsc.ast.parser._ | |
/** | |
* Search "println" in AST | |
*/ | |
class NoPrint(val global: scala.tools.nsc.Global) extends Plugin with Parsers{ | |
import global._ | |
val name = "NoPrint" | |
val description = """Find all "println"""" | |
val components = List[PluginComponent](NoPrintComponent) | |
object PrintFinder extends Traverser{ | |
override def traverse(tree: Tree) = { | |
tree match{ | |
case id @ Ident(_) if (id.name == newTermName("println")) => { | |
reporter.info(id.pos, "Println found!", true) | |
} | |
case _ => //Nothing | |
} | |
super.traverse(tree) | |
} | |
} | |
private object NoPrintComponent extends PluginComponent{ | |
val global: NoPrint.this.global.type = NoPrint.this.global | |
val runsAfter = List[String]() | |
val phaseName = NoPrint.this.name | |
//We run this just after the parser phase | |
override val runsRightAfter= Some("parser") | |
def newPhase(_prev: Phase) = new NoPrintPhase(_prev) | |
class NoPrintPhase(_prev: Phase) extends StdPhase(_prev){ | |
override def name = NoPrint.this.name | |
def apply(unit: CompilationUnit) = PrintFinder.traverse(unit.body) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment