Created
June 6, 2013 20:07
-
-
Save gkossakowski/5724506 to your computer and use it in GitHub Desktop.
Test case for SI-7561.
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
package cons | |
import mac._ | |
class Consumer { | |
val f: Foo = new Foo | |
Rewrite.rewrite(f.k) | |
} | |
class Foo { | |
@fancy val k: Int = 5 | |
def k$fancy: Int = ??? | |
} |
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
package mac | |
@scala.annotation.meta.getter | |
class fancy extends scala.annotation.StaticAnnotation | |
object Rewrite { | |
import scala.language.experimental.macros | |
import scala.reflect.macros.Context | |
def rewrite[A](a: A) = macro rewriteImpl[A] | |
def rewriteImpl[A: c.WeakTypeTag](c: Context)(a: c.Expr[A]): c.Expr[A] = { | |
import c.universe._ | |
//c.error(a.tree.pos, s"annotations: ${a.tree.symbol}") | |
//c.error(a.tree.pos, s"annotations: ${a.tree.symbol.annotations}") | |
def forceAnnotations(s: Symbol) = { | |
println(s.owner.typeSignature) | |
println(s.annotations) | |
s.annotations.foreach { ann => | |
val annInternal: scala.reflect.internal.AnnotationInfos#AnnotationInfo = ann.asInstanceOf[scala.reflect.internal.AnnotationInfos#AnnotationInfo] | |
annInternal.completeInfo | |
} | |
} | |
val t = a.tree match { | |
case sel @ Select(qual, name) if { forceAnnotations(sel.symbol); sel.symbol.annotations.exists(_.tpe =:= weakTypeOf[fancy]) } => | |
c.error(sel.pos, "rewriting $sel") | |
Select(qual, newTermName(name + "$fancy")) | |
case s => s | |
} | |
c.Expr[A](t) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment