in shared/src/main/scala-3/magnolify/shared/AnnotationTypeMacros.scala [23:51]
private def getClassTag[T](using Type[T], Quotes): Expr[ClassTag[T]] =
import quotes.reflect._
Expr.summon[ClassTag[T]] match
case Some(ct) =>
ct
case None =>
report.error(
s"Unable to find a ClassTag for type ${Type.show[T]}",
Position.ofMacroExpansion
)
throw new Exception("Error when applying macro")
def annotationTypeMacro[T: Type](using quotes: Quotes): Expr[AnnotationType[T]] =
import quotes.reflect.*
val annotated = Type.of[T] match
case '[Enumeration#Value] =>
// Annotation for Scala enumerations are on the outer object
val TypeRef(pre, _) = TypeRepr.of[T]: @unchecked
pre
case _ =>
TypeRepr.of[T]
// only collect scala annotations
val sAnnotations =
Expr.ofList[Any](annotated.typeSymbol.annotations.map(_.asExprOf[Any]).filter {
case '{ $x: java.lang.annotation.Annotation } => false
case '{ $x: scala.annotation.StaticAnnotation } => true
case _ => false
})