Skip to content

Instantly share code, notes, and snippets.

@nadavwr
Created July 26, 2012 22:15
Show Gist options
  • Save nadavwr/3184926 to your computer and use it in GitHub Desktop.
Save nadavwr/3184926 to your computer and use it in GitHub Desktop.
macro for: val foo: Foo = new Foo(bar)
// val foo: Foo = new Foo(bar)
private[this] def declareRuntime: Tree = {
val runtimeClass = context.mirror.staticClass(classOf[Foo].getName)
ValDef(
Modifiers(),
newTermName("foo"),
TypeTree(runtimeClass.asType),
Apply(
Select(
New(Ident(runtimeClass)),
newTermName("<init>")),
List(
Select(
context.prefix.tree,
newTermName("bar")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment