Skip to content

Commit fa36d90

Browse files
committed
AnnotationOf test
1 parent 7781469 commit fa36d90

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.avsystem.commons
2+
package misc
3+
4+
import com.avsystem.commons.annotation.AnnotationAggregate
5+
import org.scalatest.FunSuite
6+
7+
import scala.annotation.StaticAnnotation
8+
9+
class genann[T](val value: T) extends StaticAnnotation
10+
class genagg[T](value: T) extends AnnotationAggregate {
11+
@genann(value) type Implied
12+
}
13+
14+
@genagg(42)
15+
class Subject
16+
17+
class AnnotationOfTest extends FunSuite {
18+
test("aggregate with generic") {
19+
assert(AnnotationOf.materialize[genann[Int], Subject].annot.value == 42)
20+
}
21+
}

commons-macros/src/main/scala/com/avsystem/commons/macros/misc/MiscMacros.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,23 +496,23 @@ class MiscMacros(ctx: blackbox.Context) extends AbstractMacroCommons(ctx) {
496496
c.untypecheck(annot.tree)
497497
}
498498

499-
def annotationOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = {
499+
def annotationOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = showOnDebug {
500500
val atpe = weakTypeOf[A].dealias
501501
val tpe = assertLocal(weakTypeOf[T].dealias)
502502
val annot = findAnnotation(tpe.typeSymbol, atpe)
503503
.getOrElse(abort(s"No annotation of type $atpe found on $tpe"))
504504
q"$MiscPkg.AnnotationOf(${safeAnnotTree(annot)})"
505505
}
506506

507-
def optAnnotationOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = {
507+
def optAnnotationOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = showOnDebug {
508508
val atpe = weakTypeOf[A].dealias
509509
val tpe = assertLocal(weakTypeOf[T].dealias)
510510
val annotTree = findAnnotation(tpe.typeSymbol, atpe)
511511
.fold[Tree](q"$MiscPkg.Opt.Empty")(a => q"$MiscPkg.Opt(${safeAnnotTree(a)})")
512512
q"$MiscPkg.OptAnnotationOf($annotTree)"
513513
}
514514

515-
def annotationsOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = {
515+
def annotationsOf[A: WeakTypeTag, T: WeakTypeTag]: Tree = showOnDebug {
516516
val atpe = weakTypeOf[A].dealias
517517
val tpe = assertLocal(weakTypeOf[T].dealias)
518518
val annots = allAnnotations(tpe.typeSymbol, atpe).map(safeAnnotTree)

0 commit comments

Comments
 (0)