Created
August 16, 2010 23:47
-
-
Save bwmcadams/527992 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Test Method | |
@Stache("unitTest", Some(3600)) def foo(x: Int) = { | |
println("Multiplying X (%s) by 2".format(x)) | |
x * 2 | |
} | |
// Compiler steps | |
var block = tree.find( _.isInstanceOf[Block] ) orElse tree.find( _.isInstanceOf[Apply] ) getOrElse(throw new IllegalArgumentException("Cannot find method body for Stache annotated DefDef '%s'. Was looking for either a code block or a one liner. Is method abstract or something else boneheaded?".format(dDef.name))) | |
val base: Tree = treeCopy.Function(tree, Nil, block) | |
UnTyper.traverse(base) | |
val fn = Apply( | |
Apply( | |
TypeApply( | |
Select( | |
Ident(definitions.getModule("com.novus.stache.StacheManager")), | |
newTermName("apply") | |
), | |
List(TypeTree(sym.info.resultType.normalize)) | |
), | |
callArgs), | |
List(base) | |
) | |
localTyper.typed { DEF(sym) === fn } // returns (end of block) | |
// At this point it's simply passed as a function parameter into the new method body. | |
// Generated compiler code | |
StacheManager.apply[Int]("unitTest", scala.Some.apply[Long](3600L), "<root>.com.novus.stache.plugin.test.TestMethods.foo", "_foo", x)((() => { | |
scala.this.Predef.println(scala.this.Predef.augmentString("Multiplying X (%s) by 2").format(x)); | |
x.$times(2) | |
})) | |
// Compiler error is scala.tools.nsc.symtab.Types$TypeError: scala is not an enclosing class referring to scala.this.Predef... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment