Created
August 9, 2016 00:11
-
-
Save DavidDudson/b2fb2f51c8919a1584911dc5bd5c1d61 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
@WhatAmI | |
object Test { | |
@WhatAmI | |
def main(args: Array[String]) = {} | |
@WhatAmI | |
val hi = "" | |
@WhatAmI | |
var hello = "" | |
@WhatAmI | |
object SomeObject {} | |
@WhatAmI | |
class SomeClass(a:String) {} | |
@WhatAmI | |
case class SomeCaseClass(a:String) {} | |
@WhatAmI | |
trait SomeTrait | |
@WhatAmI | |
sealed trait SomeSealedTrait | |
} |
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.annotation.compileTimeOnly | |
import scala.meta._ | |
@compileTimeOnly("@WhatAmI not expanded") | |
class WhatAmI extends scala.annotation.StaticAnnotation { | |
inline def apply(defn: Defn) = meta { | |
defn match { | |
case _:Defn.Def => println("Def") | |
case _:Defn.Class => println("Class") | |
case _:Defn.Macro => println("Macro") | |
case _:Defn.Trait => println("Trait") | |
case _:Defn.Type => println("Type") | |
case _:Defn.Val => println("Val") | |
case _:Defn.Var => println("Var") | |
case _:Defn.Object => println("Object") | |
case _=> println("Unknown") | |
} | |
defn | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1.Compile:
2. Observe that it only prints Object
3. Remove WhatAmI in line 1 of Test.scala
4. Compile
5. Observe that the list of annotations are printed correctly