Class AnnotationMatcher

  • All Implemented Interfaces:
    net.bytebuddy.matcher.ElementMatcher<net.bytebuddy.description.annotation.AnnotationSource>, net.bytebuddy.matcher.ElementMatcher.Junction<net.bytebuddy.description.annotation.AnnotationSource>

    public class AnnotationMatcher
    extends net.bytebuddy.matcher.ElementMatcher.Junction.AbstractBase<net.bytebuddy.description.annotation.AnnotationSource>
    ByteBuddy ElementMatcher that finds elements that are annotated with matching annotations.

    The matcher must be initialized with a pattern prefixed with '@' or '@@' to find either annotation names or meta annotation names.

    If prefixed with '@' it matches AnnotationSources that are annotated with an annotation whose name matches the pattern. If prefixed with '@@' it matches AnnotationSources that are annotated with annotations that are themselves annotated with an annotation whose name matches the pattern. The pattern itself is matched against the name of an annotation using WildcardMatcher

    Examples:

    • @java.inject.ApplicationScoped matches all types annotated with the java.inject.ApplicationScoped annotation
    • @java.inject.* matches all types annotated with any annotation in the 'javax.inject' package or subpackages
    • @@javax.enterprise.context.NormalScope matches all typed annotated with an annotation that is annotated with the javax.enterprise.context.NormalScope annotation
    See Also:
    WildcardMatcher
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher

        net.bytebuddy.matcher.ElementMatcher.Junction<S extends java.lang.Object>
      • Nested classes/interfaces inherited from interface net.bytebuddy.matcher.ElementMatcher.Junction

        net.bytebuddy.matcher.ElementMatcher.Junction.AbstractBase<V extends java.lang.Object>, net.bytebuddy.matcher.ElementMatcher.Junction.Conjunction<W extends java.lang.Object>, net.bytebuddy.matcher.ElementMatcher.Junction.Disjunction<W extends java.lang.Object>
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static AnnotationMatcher annotationMatcher​(java.lang.String annotationPattern)  
      static AnnotationMatcher matchAll()  
      boolean matches​(net.bytebuddy.description.annotation.AnnotationSource target)
      Test if the target has any annotations matching the annotationPattern of this matcher.
      java.lang.String toString()  
      • Methods inherited from class net.bytebuddy.matcher.ElementMatcher.Junction.AbstractBase

        and, or
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • annotationMatcher

        public static AnnotationMatcher annotationMatcher​(java.lang.String annotationPattern)
        Parameters:
        annotationPattern - the pattern to match against. Must either start with '@' or '@@'.
        Returns:
        an AnnotationMatcher for the specified annotationPattern
      • matchAll

        public static AnnotationMatcher matchAll()
        Returns:
        an AnnotationMatcher that always returns true (matches anything)
      • matches

        public boolean matches​(net.bytebuddy.description.annotation.AnnotationSource target)
        Test if the target has any annotations matching the annotationPattern of this matcher.
        Parameters:
        target - the AnnotationSource to test.
        Returns:
        true if the target has an annotation matching the annotationPattern of this AnnotationMatcher, else false. If this AnnotationMatcher was initialized with matchAll() always returns true.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object