All Downloads are FREE. Search and download functionalities are using the official Maven repository.

izumi.fundamentals.reflection.AnnotationTools.scala Maven / Gradle / Ivy

The newest version!
package izumi.fundamentals.reflection

import izumi.fundamentals.reflection.ReflectionUtil.stripByName

import scala.annotation.nowarn
import scala.reflect.api.Universe

object AnnotationTools {

  def getAllAnnotations(u: Universe)(symb: u.Symbol): List[u.Annotation] = {
    symb.annotations ++ getAllTypeAnnotations(u)(symb.typeSignature)
  }

  def getAllTypeAnnotations(u: Universe)(typ: u.Type): List[u.Annotation] = {
    @nowarn("msg=outer reference")
    val out = stripByName(u)(typ.finalResultType.dealias) match {
      case t: u.AnnotatedTypeApi =>
        t.annotations
      case _ =>
        Nil
    }
    out
  }

  def annotationTypeEq(u: Universe)(tpe: u.Type, ann: u.Annotation): Boolean = {
    ann.tree.tpe.erasure =:= tpe.erasure
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy