Skip to content

Commit f57cb17

Browse files
committed
allow usage in annotations
1 parent 8b0c0cd commit f57cb17

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/scala-2/com/github/dwickern/macros/NameOfImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.dwickern.macros
22

33
import scala.language.experimental.macros
4-
import scala.reflect.macros.{blackbox, whitebox}
4+
import scala.reflect.macros.whitebox
55
import scala.annotation.tailrec
66

77
object NameOfImpl {
@@ -47,7 +47,7 @@ object NameOfImpl {
4747
c.Expr[String](q"$name")
4848
}
4949

50-
def qualifiedNameOf(c: blackbox.Context)(expr: c.Expr[Any]): c.Expr[String] = {
50+
def qualifiedNameOf(c: whitebox.Context)(expr: c.Expr[Any]): c.Expr[String] = {
5151
import c.universe._
5252

5353
def extractNames(tree: c.Tree): List[c.Name] = {

src/test/scalajvm/com/github/dwickern/macros/AnnotationTest.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class AnnotationTest extends AnyFunSuite with Matchers {
3535
annotation.name should === ("classMember")
3636
}
3737

38+
test("qualifiedNameOf") {
39+
class C(val foo: Foo)
40+
class Foo(val bar: Bar)
41+
class Bar(val baz: String)
42+
43+
@Resource(name = qualifiedNameOf[C](_.foo.bar.baz))
44+
class AnnotatedClass
45+
46+
val annotation = classOf[AnnotatedClass].getDeclaredAnnotation(classOf[Resource])
47+
annotation.name should === ("foo.bar.baz")
48+
}
49+
3850
test("nameOfType") {
3951
@Resource(name = nameOfType[AnnotatedClass])
4052
class AnnotatedClass

0 commit comments

Comments
 (0)