Created
December 21, 2018 16:23
-
-
Save psilospore/1aaafd202d5048a1c4cd3e8ee52b4fea to your computer and use it in GitHub Desktop.
Look up usages of scala method using macros
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
import scala.language.experimental.macros | |
//WIP does not function | |
final class lookerUpper extends scala.annotation.StaticAnnotation { | |
import lookerUpper._ | |
/** | |
* @param annottees list of untyped annottees | |
* @return | |
*/ | |
def macroTransform(annottees: Any*): Any = macro lookerUpper_impl | |
} | |
object lookerUpper { | |
import reflect.macros.whitebox | |
def lookerUpper_impl(c: whitebox.Context)(annottees: c.Tree*): c.Tree = { | |
import c.universe._ | |
println(s"entering impl $annottees") | |
annottees.headOption.foreach { | |
case vodd: ValOrDefDefApi =>{ | |
println("hi 1");c.warning(vodd.pos, s"f${vodd.name}") | |
} | |
case _ => c.warning(c.enclosingPosition, "This is unexpected") | |
} | |
c.warning(c.enclosingPosition, "Didn't hit anything :(") | |
//I don't want to do anything to the tree actually | |
// Block(annottees) //Deprecated | |
q""" | |
..$annottees | |
""" | |
} | |
} | |
@lookerUpper() def hi = "hi" | |
@lookerUpper() val hi = "hi" | |
//no warnings or anything |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment