Class ElementMatchers

java.lang.Object
net.bytebuddy.matcher.ElementMatchers

public final class ElementMatchers extends Object
A utility class that contains a human-readable language for creating ElementMatchers.
  • Constructor Details

    • ElementMatchers

      private ElementMatchers()
      A private constructor that must not be invoked.
  • Method Details

    • failSafe

      public static <T> ElementMatcher.Junction<T> failSafe(ElementMatcher<? super T> matcher)
      Wraps another matcher to assure that an element is not matched in case that the matching causes an Exception.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The element matcher that potentially throws an exception.
      Returns:
      A matcher that returns false in case that the given matcher throws an exception.
    • cached

      public static <T> ElementMatcher.Junction<T> cached(ElementMatcher<? super T> matcher, ConcurrentMap<? super T,Boolean> map)

      Wraps another matcher but caches the result of previously matched elements. Caching can be important if a matcher requires expensive calculations.

      Warning: The supplied map can however introduce a memory leak as the matched elements are stored within the map. It is therefore important to dereference this matcher at some point or to regularly evict entries from the supplied map.

      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The actual matcher for which the results are cached.
      map - The map for storing results of previously matched elements.
      Returns:
      A matcher that stores the results of a previous matching in the supplied map.
    • cached

      public static <T> ElementMatcher.Junction<T> cached(ElementMatcher<? super T> matcher, int evictionSize)

      Wraps another matcher but caches the result of previously matched elements. Caching can be important if a matcher requires expensive calculations.

      Warning: The cache will hold evictionSize elements and evict a random element once the cache contains more than the specified amount of elements. Cached elements are referenced strongly and might cause a memory leak if instance are of a significant size. Using cached(ElementMatcher, ConcurrentMap) allows for explicit control over cache eviction.

      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The actual matcher for which the results are cached.
      evictionSize - The maximum amount of elements that are stored in the cache. Must be a positive number.
      Returns:
      A matcher that stores the results of a previous matching in the supplied map.
    • is

      public static <T> ElementMatcher.Junction<T> is(@MaybeNull Object value)
      Matches the given value which can also be null by the Object.equals(Object) method or by a null-check.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The value that is to be matched.
      Returns:
      A matcher that matches an exact value.
    • is

      public static <T extends FieldDescription> ElementMatcher.Junction<T> is(Field field)
      Exactly matches a given field as a FieldDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      field - The field to match by its description
      Returns:
      An element matcher that exactly matches the given field in its defined shape.
    • is

      Exactly matches a given field as a FieldDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      field - The field to match by its description
      Returns:
      An element matcher that exactly matches the given field in its defined shape.
    • definedField

      public static <T extends FieldDescription> ElementMatcher.Junction<T> definedField(ElementMatcher<? super FieldDescription.InDefinedShape> matcher)
      Matches a field in its defined shape.
      Type Parameters:
      T - The matched object's type.
      Parameters:
      matcher - The matcher to apply to the matched field's defined shape.
      Returns:
      A matcher that matches a matched field's defined shape.
    • is

      public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Method method)
      Exactly matches a given method as a MethodDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      method - The method to match by its description
      Returns:
      An element matcher that exactly matches the given method in its defined shape.
    • is

      public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Constructor<?> constructor)
      Exactly matches a given constructor as a MethodDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      constructor - The constructor to match by its description
      Returns:
      An element matcher that exactly matches the given constructor in its defined shape.
    • is

      Exactly matches a given method or constructor as a MethodDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      method - The method to match by its description
      Returns:
      An element matcher that exactly matches the given method or constructor in its defined shape.
    • definedMethod

      public static <T extends MethodDescription> ElementMatcher.Junction<T> definedMethod(ElementMatcher<? super MethodDescription.InDefinedShape> matcher)
      Matches a method in its defined shape.
      Type Parameters:
      T - The matched object's type.
      Parameters:
      matcher - The matcher to apply to the matched method's defined shape.
      Returns:
      A matcher that matches a matched method's defined shape.
    • is

      Exactly matches a given parameter as a ParameterDescription in its defined shape.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      parameter - The parameter to match by its description
      Returns:
      An element matcher that exactly matches the given parameter in its defined shape.
    • definedParameter

      public static <T extends ParameterDescription> ElementMatcher.Junction<T> definedParameter(ElementMatcher<? super ParameterDescription.InDefinedShape> matcher)
      Matches a parameter in its defined shape.
      Type Parameters:
      T - The matched object's type.
      Parameters:
      matcher - The matcher to apply to the matched parameter's defined shape.
      Returns:
      A matcher that matches a matched parameter's defined shape.
    • hasType

      public static <T extends ParameterDescription> ElementMatcher.Junction<T> hasType(ElementMatcher<? super TypeDescription> matcher)
      Matches a parameter's type by the given matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to the parameter's type.
      Returns:
      A matcher that matches a parameter's type by the given matcher.
    • hasGenericType

      public static <T extends ParameterDescription> ElementMatcher.Junction<T> hasGenericType(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches a method parameter by its generic type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to a parameter's generic type.
      Returns:
      A matcher that matches the matched parameter's generic type.
    • isMandated

      public static <T extends ParameterDescription> ElementMatcher.Junction<T> isMandated()
      Matches a parameter description for a mandated parameter.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a mandated parameter.
    • is

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> is(Type type)
      Exactly matches a given type as a TypeDescription.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to match by its description
      Returns:
      An element matcher that exactly matches the given type.
    • is

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> is(Annotation annotation)
      Exactly matches a given annotation as an AnnotationDescription.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      annotation - The annotation to match by its description.
      Returns:
      An element matcher that exactly matches the given annotation.
    • not

      public static <T> ElementMatcher.Junction<T> not(ElementMatcher<? super T> matcher)
      Inverts another matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to invert.
      Returns:
      An inverted version of the given matcher.
    • any

      public static <T> ElementMatcher.Junction<T> any()
      Creates a matcher that always returns true.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches anything.
    • none

      public static <T> ElementMatcher.Junction<T> none()
      Creates a matcher that always returns false.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches nothing.
    • anyOf

      public static <T> ElementMatcher.Junction<T> anyOf(Object... value)

      Creates a matcher that matches any of the given objects by the Object.equals(Object) method. None of the values must be null.

      Important: This method cannot be used interchangeably with any of its overloaded versions which also apply a type conversion.

      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T> ElementMatcher.Junction<T> anyOf(Iterable<?> values)

      Creates a matcher that matches any of the given objects by the Object.equals(Object) method. None of the values must be null.

      Important: This method cannot be used interchangeably with any of the overloaded versions of anyOf(Object...) which also apply a type conversion.

      Type Parameters:
      T - The type of the matched object.
      Parameters:
      values - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> anyOf(Type... value)
      Creates a matcher that matches any of the given types as TypeDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T extends MethodDescription> ElementMatcher.Junction<T> anyOf(Constructor<?>... value)
      Creates a matcher that matches any of the given constructors as MethodDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T extends MethodDescription> ElementMatcher.Junction<T> anyOf(Method... value)
      Creates a matcher that matches any of the given methods as MethodDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T extends FieldDescription> ElementMatcher.Junction<T> anyOf(Field... value)
      Creates a matcher that matches any of the given fields as FieldDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • anyOf

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> anyOf(Annotation... value)
      Creates a matcher that matches any of the given annotations as AnnotationDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • noneOf

      public static <T> ElementMatcher.Junction<T> noneOf(Object... value)
      Creates a matcher that matches none of the given objects by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T> ElementMatcher.Junction<T> noneOf(Iterable<?> values)
      Creates a matcher that matches none of the given objects by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      values - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> noneOf(Type... value)
      Creates a matcher that matches none of the given types as TypeDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T extends MethodDescription> ElementMatcher.Junction<T> noneOf(Constructor<?>... value)
      Creates a matcher that matches none of the given constructors as MethodDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T extends MethodDescription> ElementMatcher.Junction<T> noneOf(Method... value)
      Creates a matcher that matches none of the given methods as MethodDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T extends FieldDescription> ElementMatcher.Junction<T> noneOf(Field... value)
      Creates a matcher that matches none of the given methods as FieldDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with none of the given objects.
    • noneOf

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> noneOf(Annotation... value)
      Creates a matcher that matches none of the given annotations as AnnotationDescriptions by the Object.equals(Object) method. None of the values must be null.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      value - The input values to be compared against.
      Returns:
      A matcher that checks for the equality with any of the given objects.
    • whereAny

      public static <T> ElementMatcher.Junction<Iterable<? extends T>> whereAny(ElementMatcher<? super T> matcher)
      Matches an iterable by assuring that at least one element of the iterable collection matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to each element.
      Returns:
      A matcher that matches an iterable if at least one element matches the provided matcher.
    • whereNone

      public static <T> ElementMatcher.Junction<Iterable<? extends T>> whereNone(ElementMatcher<? super T> matcher)
      Matches an iterable by assuring that no element of the iterable collection matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to each element.
      Returns:
      A matcher that matches an iterable if no element matches the provided matcher.
    • erasure

      public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> erasure(Class<?> type)
      Matches a generic type's erasure against the provided type. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to match a generic type's erasure against.
      Returns:
      A matcher that matches a generic type's raw type against the provided non-generic type.
    • erasure

      public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> erasure(TypeDescription type)
      Matches a generic type's erasure against the provided type. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to match a generic type's erasure against.
      Returns:
      A matcher that matches a generic type's raw type against the provided non-generic type.
    • erasure

      public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> erasure(ElementMatcher<? super TypeDescription> matcher)
      Converts a matcher for a type description into a matcher for the matched type's erasure. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to match the matched object's raw type against.
      Returns:
      A type matcher for a generic type that matches the matched type's raw type against the given type description matcher.
    • erasures

      public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures(Class<?>... type)
      Matches an iteration of generic types' erasures against the provided types. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The types to match.
      Returns:
      A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
    • erasures

      public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures(TypeDescription... type)
      Matches an iteration of generic types' erasures against the provided types. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The types to match.
      Returns:
      A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
    • erasures

      public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures(Iterable<? extends TypeDescription> types)
      Matches an iteration of generic types' erasures against the provided types. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      types - The types to match.
      Returns:
      A matcher that matches an iteration of generic types' raw types against the provided non-generic types.
    • erasures

      public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures(ElementMatcher<? super Iterable<? extends TypeDescription>> matcher)
      Applies the provided matchers to an iteration og generic types' erasures. As a wildcard does not define an erasure, a runtime exception is thrown when this matcher is applied to a wildcard.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply at the erased types.
      Returns:
      A matcher that matches an iteration of generic types' raw types against the provided matcher.
    • isVariable

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(String symbol)
      Matches a type variable with the given name.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      symbol - The name of the type variable to be match.
      Returns:
      A matcher that matches type variables with the given name.
    • isVariable

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(ElementMatcher<? super NamedElement> matcher)
      Matches a type variable with the given name.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for the type variable's name.
      Returns:
      A matcher that matches type variables with the given name.
    • named

      public static <T extends NamedElement> ElementMatcher.Junction<T> named(String name)
      Matches a NamedElement for its exact name.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      name - The expected name.
      Returns:
      An element matcher for a named element's exact name.
    • namedOneOf

      public static <T extends NamedElement> ElementMatcher.Junction<T> namedOneOf(String... names)
      Matches a NamedElement for its membership of a set.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      names - The set of expected names.
      Returns:
      An element matcher which matches if the element's name is found in the set.
    • namedIgnoreCase

      public static <T extends NamedElement> ElementMatcher.Junction<T> namedIgnoreCase(String name)
      Matches a NamedElement for its name. The name's capitalization is ignored.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      name - The expected name.
      Returns:
      An element matcher for a named element's name.
    • nameStartsWith

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWith(String prefix)
      Matches a NamedElement for its name's prefix.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      prefix - The expected name's prefix.
      Returns:
      An element matcher for a named element's name's prefix.
    • nameStartsWithIgnoreCase

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWithIgnoreCase(String prefix)
      Matches a NamedElement for its name's prefix. The name's capitalization is ignored.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      prefix - The expected name's prefix.
      Returns:
      An element matcher for a named element's name's prefix.
    • nameEndsWith

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameEndsWith(String suffix)
      Matches a NamedElement for its name's suffix.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      suffix - The expected name's suffix.
      Returns:
      An element matcher for a named element's name's suffix.
    • nameEndsWithIgnoreCase

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameEndsWithIgnoreCase(String suffix)
      Matches a NamedElement for its name's suffix. The name's capitalization is ignored.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      suffix - The expected name's suffix.
      Returns:
      An element matcher for a named element's name's suffix.
    • nameContains

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameContains(String infix)
      Matches a NamedElement for an infix of its name.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      infix - The expected infix of the name.
      Returns:
      An element matcher for a named element's name's infix.
    • nameContainsIgnoreCase

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameContainsIgnoreCase(String infix)
      Matches a NamedElement for an infix of its name. The name's capitalization is ignored.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      infix - The expected infix of the name.
      Returns:
      An element matcher for a named element's name's infix.
    • nameMatches

      public static <T extends NamedElement> ElementMatcher.Junction<T> nameMatches(String regex)
      Matches a NamedElement name against a regular expression.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      regex - The regular expression to match the name against.
      Returns:
      An element matcher for a named element's name's against the given regular expression.
    • isNamed

      public static <T extends NamedElement.WithOptionalName> ElementMatcher.Junction<T> isNamed()
      Matches a NamedElement.WithOptionalName for having an explicit name.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      An element matcher that checks if the matched optionally named element has an explicit name.
    • hasDescriptor

      public static <T extends NamedElement.WithDescriptor> ElementMatcher.Junction<T> hasDescriptor(String descriptor)
      Matches a NamedElement.WithDescriptor's descriptor against a given value.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      descriptor - The expected descriptor.
      Returns:
      A matcher for the given descriptor.
    • isDeclaredBy

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(Class<?> type)
      Matches a ByteCodeElement for being declared by a given Class. This matcher matches a declared element's raw declaring type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that is expected to declare the matched byte code element.
      Returns:
      A matcher for byte code elements being declared by the given type.
    • isDeclaredBy

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(TypeDescription type)
      Matches a ByteCodeElement for being declared by a given TypeDescription. This matcher matches a declared element's raw declaring type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that is expected to declare the matched byte code element.
      Returns:
      A matcher for byte code elements being declared by the given type.
    • isDeclaredBy

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredBy(ElementMatcher<? super TypeDescription> matcher)
      Matches a ByteCodeElement for being declared by a TypeDescription that is matched by the given matcher. This matcher matches a declared element's raw declaring type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for the declaring type of the matched byte code element as long as it is not null.
      Returns:
      A matcher for byte code elements being declared by a type matched by the given matcher.
    • isDeclaredByGeneric

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(Type type)
      Matches a ByteCodeElement for being declared by a given generic Type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that is expected to declare the matched byte code element.
      Returns:
      A matcher for byte code elements being declared by the given type.
    • isDeclaredByGeneric

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(TypeDescription.Generic type)
      Matches a ByteCodeElement for being declared by a given TypeDescription.Generic.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that is expected to declare the matched byte code element.
      Returns:
      A matcher for byte code elements being declared by the given type.
    • isDeclaredByGeneric

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isDeclaredByGeneric(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches a ByteCodeElement for being declared by a TypeDescription.Generic that is matched by the given matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for the declaring type of the matched byte code element as long as it is not null.
      Returns:
      A matcher for byte code elements being declared by a type matched by the given matcher.
    • isVisibleTo

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isVisibleTo(Class<?> type)
      Matches a ByteCodeElement that is visible to a given Class.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that a matched byte code element is expected to be visible to.
      Returns:
      A matcher for a byte code element to be visible to a given type.
    • isVisibleTo

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isVisibleTo(TypeDescription type)
      Matches a ByteCodeElement that is visible to a given TypeDescription.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that a matched byte code element is expected to be visible to.
      Returns:
      A matcher for a byte code element to be visible to a given type.
    • isAccessibleTo

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isAccessibleTo(Class<?> type)
      Matches a ByteCodeElement that is accessible to a given Class.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that a matched byte code element is expected to be accessible to.
      Returns:
      A matcher for a byte code element to be accessible to a given type.
    • isAccessibleTo

      public static <T extends ByteCodeElement> ElementMatcher.Junction<T> isAccessibleTo(TypeDescription type)
      Matches a ByteCodeElement that is accessible to a given Class.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type that a matched byte code element is expected to be accessible to.
      Returns:
      A matcher for a byte code element to be accessible to a given type.
    • isAbstract

      public static <T extends ModifierReviewable.OfAbstraction> ElementMatcher.Junction<T> isAbstract()
      Matches a ModifierReviewable.OfAbstraction that is abstract.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a abstract modifier reviewable.
    • isEnum

      public static <T extends ModifierReviewable.OfEnumeration> ElementMatcher.Junction<T> isEnum()
      Matches a ModifierReviewable.OfEnumeration that is an enum or a field holding an enum.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for an enum.
    • isAnnotatedWith

      public static <T extends AnnotationSource> ElementMatcher.Junction<T> isAnnotatedWith(Class<? extends Annotation> type)
      Matches an AnnotationSource for declared annotations. This matcher does not match inherited annotations which only exist for classes. Use inheritsAnnotation(Class) for matching inherited annotations.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The annotation type to match against.
      Returns:
      A matcher that validates that an annotated element is annotated with an annotation of type.
    • isAnnotatedWith

      public static <T extends AnnotationSource> ElementMatcher.Junction<T> isAnnotatedWith(TypeDescription type)
      Matches an AnnotationSource for declared annotations. This matcher does not match inherited annotations which only exist for classes. Use inheritsAnnotation(TypeDescription) for matching inherited annotations.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The annotation type to match against.
      Returns:
      A matcher that validates that an annotated element is annotated with an annotation of type.
    • isAnnotatedWith

      public static <T extends AnnotationSource> ElementMatcher.Junction<T> isAnnotatedWith(ElementMatcher<? super TypeDescription> matcher)
      Matches an AnnotationSource for declared annotations. This matcher does not match inherited annotations which only exist for classes. Use inheritsAnnotation(net.bytebuddy.matcher.ElementMatcher) for matching inherited annotations.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to any annotation's type found on the matched annotated element.
      Returns:
      A matcher that validates that an annotated element is annotated with an annotation of a type that matches the given matcher.
    • declaresAnnotation

      public static <T extends AnnotationSource> ElementMatcher.Junction<T> declaresAnnotation(ElementMatcher<? super AnnotationDescription> matcher)
      Matches an AnnotationSource to declare any annotation that matches the given matcher. Note that this matcher does not match inherited annotations that only exist for types. Use inheritsAnnotation(net.bytebuddy.matcher.ElementMatcher) for matching inherited annotations.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to apply on any declared annotation of the matched annotated element.
      Returns:
      A matcher that validates that an annotated element is annotated with an annotation that matches the given matcher.
    • isPublic

      public static <T extends ModifierReviewable.OfByteCodeElement> ElementMatcher.Junction<T> isPublic()
      Matches a ModifierReviewable that is public.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a public modifier reviewable.
    • isProtected

      public static <T extends ModifierReviewable.OfByteCodeElement> ElementMatcher.Junction<T> isProtected()
      Matches a ModifierReviewable that is protected.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a protected modifier reviewable.
    • isPackagePrivate

      public static <T extends ModifierReviewable.OfByteCodeElement> ElementMatcher.Junction<T> isPackagePrivate()
      Matches a ModifierReviewable that is package-private.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a package-private modifier reviewable.
    • isPrivate

      public static <T extends ModifierReviewable.OfByteCodeElement> ElementMatcher.Junction<T> isPrivate()
      Matches a ModifierReviewable that is private.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a private modifier reviewable.
    • isStatic

      public static <T extends ModifierReviewable.OfByteCodeElement> ElementMatcher.Junction<T> isStatic()
      Matches a ModifierReviewable that is static.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a static modifier reviewable.
    • isFinal

      public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isFinal()
      Matches a ModifierReviewable that is final.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a final modifier reviewable.
    • isSynthetic

      public static <T extends ModifierReviewable> ElementMatcher.Junction<T> isSynthetic()
      Matches a ModifierReviewable that is synthetic.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a synthetic modifier reviewable.
    • isSynchronized

      public static <T extends ModifierReviewable.ForMethodDescription> ElementMatcher.Junction<T> isSynchronized()
      Matches a MethodDescription that is synchronized.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a synchronized method description.
    • isNative

      public static <T extends ModifierReviewable.ForMethodDescription> ElementMatcher.Junction<T> isNative()
      Matches a MethodDescription that is native.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a native method description.
    • isStrict

      public static <T extends ModifierReviewable.ForMethodDescription> ElementMatcher.Junction<T> isStrict()
      Matches a MethodDescription that is strictfp.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a strictfp method description.
    • isVarArgs

      public static <T extends ModifierReviewable.ForMethodDescription> ElementMatcher.Junction<T> isVarArgs()
      Matches a MethodDescription that is a var-args.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a var-args method description.
    • isBridge

      public static <T extends ModifierReviewable.ForMethodDescription> ElementMatcher.Junction<T> isBridge()
      Matches a MethodDescription that is a bridge.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a bridge method.
    • returnsGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(Type type)
      Matches MethodDescriptions that return a given generic type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The generic type the matched method is expected to return.
      Returns:
      An element matcher that matches a given generic return type for a method description.
    • returnsGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(TypeDescription.Generic type)
      Matches MethodDescriptions that returns a given TypeDescription.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type the matched method is expected to return.
      Returns:
      An element matcher that matches a given return type for a method description.
    • returns

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(Class<?> type)
      Matches MethodDescriptions that return a given erasure type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The raw type the matched method is expected to return.
      Returns:
      An element matcher that matches a given return type for a method description.
    • returns

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(TypeDescription type)
      Matches MethodDescriptions that return a given erasure type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The raw type the matched method is expected to return.
      Returns:
      An element matcher that matches a given return type for a method description.
    • returns

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returns(ElementMatcher<? super TypeDescription> matcher)
      Matches a method's return type's erasure by the given matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to a method's return type's erasure.
      Returns:
      A matcher that matches the matched method's return type's erasure.
    • returnsGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches MethodDescriptions that match a matched method's return type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to apply onto a matched method's return type.
      Returns:
      An element matcher that matches a given return type against another matcher.
    • takesGenericArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, Type type)
      Matches MethodDescriptions that define a given generic type as a parameter at the given index.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      type - The generic type the matched method is expected to define as a parameter type.
      Returns:
      An element matcher that matches a given generic return type for a method description.
    • takesGenericArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, TypeDescription.Generic type)
      Matches MethodDescriptions that define a given generic type as a parameter at the given index.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      type - The generic type the matched method is expected to define as a parameter type.
      Returns:
      An element matcher that matches a given generic return type for a method description.
    • takesGenericArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches MethodDescriptions that define a given generic type as a parameter at the given index.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      matcher - A matcher for the generic type the matched method is expected to define as a parameter type.
      Returns:
      An element matcher that matches a given generic return type for a method description.
    • takesGenericArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(Type... type)
      Matches a method description that takes the provided generic arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's generic parameter types against the supplied arguments.
    • takesGenericArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(TypeDefinition... type)
      Matches a method description that takes the provided generic arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's generic parameter types against the supplied arguments.
    • takesGenericArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(List<? extends TypeDefinition> types)
      Matches a method description that takes the provided generic arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      types - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's generic parameter types against the supplied arguments.
    • takesGenericArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(ElementMatcher<? super Iterable<? extends TypeDescription.Generic>> matchers)
      Matches a MethodDescription by applying an iterable collection of element matcher on any parameter's TypeDescription.Generic.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matchers - The matcher that are applied onto the parameter types of the matched method description.
      Returns:
      A matcher that matches a method description by applying another element matcher onto each parameter's type.
    • takesArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgument(int index, Class<?> type)
      Matches MethodDescriptions that define a given generic type as a parameter at the given index.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      type - The erasure of the type the matched method is expected to define as a parameter type.
      Returns:
      An element matcher that matches a given argument type for a method description.
    • takesArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgument(int index, TypeDescription type)
      Matches MethodDescriptions that define a given type erasure as a parameter at the given index.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      type - The erasure of the type the matched method is expected to define as a parameter type.
      Returns:
      An element matcher that matches a given argument type for a method description.
    • takesArgument

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgument(int index, ElementMatcher<? super TypeDescription> matcher)
      Matches MethodDescriptions that define a type erasure as a parameter at the given index that matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      index - The index of the parameter.
      matcher - A matcher to apply to the argument at the specified index.
      Returns:
      An element matcher that matches a given argument type for a method description.
    • takesArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Class<?>... type)
      Matches a method description that takes the provided raw arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's raw parameter types against the supplied arguments.
    • takesArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(TypeDescription... type)
      Matches a method description that takes the provided raw arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's raw parameter types against the supplied arguments.
    • takesArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Iterable<? extends TypeDescription> types)
      Matches a method description that takes the provided raw arguments.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      types - The arguments to match against the matched method.
      Returns:
      A method matcher that matches a method's raw parameter types against the supplied arguments.
    • takesArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(ElementMatcher<? super Iterable<? extends TypeDescription>> matchers)
      Matches a MethodDescription by applying an iterable collection of element matcher on any parameter's TypeDescription.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matchers - The matcher that are applied onto the parameter types of the matched method description.
      Returns:
      A matcher that matches a method description by applying another element matcher onto each parameter's type.
    • takesArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(int length)
      Matches a MethodDescription by the number of its parameters.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      length - The expected length.
      Returns:
      A matcher that matches a method description by the number of its parameters.
    • takesNoArguments

      public static <T extends MethodDescription> ElementMatcher.Junction<T> takesNoArguments()
      Matches a MethodDescription with no parameters.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches a method description by the number of its parameters.
    • hasParameters

      public static <T extends MethodDescription> ElementMatcher.Junction<T> hasParameters(ElementMatcher<? super Iterable<? extends ParameterDescription>> matcher)
      Matches a MethodDescription by validating that its parameters fulfill a given constraint.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply for validating the parameters.
      Returns:
      A matcher that matches a method description's parameters against the given constraint.
    • canThrow

      public static <T extends MethodDescription> ElementMatcher.Junction<T> canThrow(Class<? extends Throwable> exceptionType)
      Matches a MethodDescription by its capability to throw a given checked exception. For specifying a non-checked exception, any method is matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The type of the exception that should be declared by the method to be matched.
      Returns:
      A matcher that matches a method description by its declaration of throwing a checked exception.
    • canThrow

      public static <T extends MethodDescription> ElementMatcher.Junction<T> canThrow(TypeDescription exceptionType)
      Matches a MethodDescription by its capability to throw a given checked exception. For specifying a non-checked exception, any method is matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The type of the exception that should be declared by the method to be matched.
      Returns:
      A matcher that matches a method description by its declaration of throwing a checked exception.
    • declaresGenericException

      public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(Type exceptionType)
      Matches a method that declares the given generic exception type. For non-generic type, this matcher behaves identically to declaresException(Class). For exceptions that are expressed as type variables, only exceptions that are represented as this type variable are matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The generic exception type that is matched exactly.
      Returns:
      A matcher that matches any method that exactly matches the provided generic exception.
    • declaresGenericException

      public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(TypeDescription.Generic exceptionType)
      Matches a method that declares the given generic exception type. For non-generic type, this matcher behaves identically to declaresException(TypeDescription). For exceptions that are expressed as type variables, only exceptions that are represented as this type variable are matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The generic exception type that is matched exactly.
      Returns:
      A matcher that matches any method that exactly matches the provided generic exception.
    • declaresException

      public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresException(Class<? extends Throwable> exceptionType)
      Matches a method that declares the given generic exception type as a (erased) exception type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The exception type that is matched.
      Returns:
      A matcher that matches any method that exactly matches the provided exception.
    • declaresException

      public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresException(TypeDescription exceptionType)
      Matches a method that declares the given generic exception type as a (erased) exception type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      exceptionType - The exception type that is matched.
      Returns:
      A matcher that matches any method that exactly matches the provided exception.
    • declaresGenericException

      public static <T extends MethodDescription> ElementMatcher.Junction<T> declaresGenericException(ElementMatcher<? super Iterable<? extends TypeDescription.Generic>> matcher)
      Matches a method's generic exception types against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The exception matcher to apply onto the matched method's generic exceptions.
      Returns:
      A matcher that applies the provided matcher to a method's generic exception types.
    • isOverriddenFrom

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFrom(Class<?> type)
      Matches any virtual method with a signature that is compatible to a method that is declared the supplied type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The super type of interest for which to check if it declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isOverriddenFrom

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFrom(TypeDescription type)
      Matches any virtual method with a signature that is compatible to a method that is declared the supplied type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The super type of interest for which to check if it declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isOverriddenFrom

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFrom(ElementMatcher<? super TypeDescription> matcher)
      Matches any virtual method with a signature that is compatible to a method that is declared by a type that matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for a method's declaring type that needs to be matched if that type declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isOverriddenFromGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFromGeneric(Type type)
      Matches any virtual method with a signature that is compatible to a method that is declared the supplied type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The super type of interest for which to check if it declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isOverriddenFromGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFromGeneric(TypeDescription.Generic type)
      Matches any virtual method with a signature that is compatible to a method that is declared the supplied type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The super type of interest for which to check if it declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isOverriddenFromGeneric

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFromGeneric(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches any virtual method with a signature that is compatible to a method that is declared by a type that matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for a method's declaring type that needs to be matched if that type declares a method with the same signature as the matched method.
      Returns:
      A matcher that checks a method's signature equality for any method declared by the declaring type.
    • isInterface

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isInterface()
      Matches a TypeDescription that is an interface. Annotation types are also considered interface types.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for an interface.
      See Also:
    • isAnnotation

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isAnnotation()
      Matches a TypeDescription that is an annotation type.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for an annotation type.
    • isMethod

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isMethod()
      Only matches method descriptions that represent a Method.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches method descriptions that represent a Java method.
    • isConstructor

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isConstructor()
      Only matches method descriptions that represent a Constructor.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches method descriptions that represent a Java constructor.
    • isTypeInitializer

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isTypeInitializer()
      Only matches method descriptions that represent a Class type initializer.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches method descriptions that represent the type initializer.
    • isVirtual

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isVirtual()
      Matches any method that is virtual, i.e. non-constructors that are non-static and non-private.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for virtual methods.
    • isDefaultMethod

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultMethod()
      Only matches Java 8 default methods.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches Java 8 default methods.
    • isDefaultConstructor

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultConstructor()
      Matches a default constructor, i.e. a constructor without arguments.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches a default constructor.
    • isMain

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isMain()
      Matches a Java main method as an application entry point.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches a Java main method.
    • isDefaultFinalizer

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultFinalizer()
      Only matches the Object.finalize() method if it was not overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches a non-overridden Object.finalize() method.
    • isFinalizer

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isFinalizer()
      Only matches the Object.finalize() method, even if it was overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the Object.finalize() method.
    • isHashCode

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isHashCode()
      Only matches the Object.hashCode() method, also if it was overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the Object.hashCode() method.
    • isEquals

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isEquals()
      Only matches the Object.equals(Object) method, also if it was overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the Object.equals(Object) method.
    • isClone

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isClone()
      Only matches the Object.clone() method, also if it was overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the Object.clone() method.
    • isToString

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isToString()
      Only matches the Object.toString() method, also if it was overridden.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the Object.toString() method.
    • isSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter()
      Matches any Java bean setter method.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches any setter method.
    • isSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(String property)
      An element matcher that matches any setter for the given property. When given an empty string, any setter named set is matched despite that such a setter is not fulfilling the Java bean naming conventions.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      property - The property to match a setter for.
      Returns:
      A matcher that matches any setter method for the supplied property.
    • isSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(Class<?> type)
      Matches any Java bean setter method which takes an argument the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required setter type.
      Returns:
      A matcher that matches any setter method.
    • isGenericSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericSetter(Type type)
      Matches any Java bean setter method which takes an argument the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required setter type.
      Returns:
      A matcher that matches any setter method.
    • isSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(TypeDescription type)
      Matches any Java bean setter method which takes an argument the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required setter type.
      Returns:
      A matcher that matches a setter method with the specified argument type.
    • isGenericSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericSetter(TypeDescription.Generic type)
      Matches any Java bean setter method which takes an argument the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required setter type.
      Returns:
      A matcher that matches a setter method with the specified argument type.
    • isSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(ElementMatcher<? super TypeDescription> matcher)
      Matches any Java bean setter method which takes an argument that matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to be allied to a setter method's argument type.
      Returns:
      A matcher that matches a setter method with an argument type that matches the supplied matcher.
    • isGenericSetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericSetter(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches any Java bean setter method which takes an argument that matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to be allied to a setter method's argument type.
      Returns:
      A matcher that matches a setter method with an argument type that matches the supplied matcher.
    • isGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter()
      Matches any Java bean getter method.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that matches any getter method.
    • isGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(String property)
      An element matcher that matches any getter for the given property. When given an empty string, any getter named get is matched despite that such a getter is not fulfilling the Java bean naming conventions. If a getter's type is boolean or Boolean, is is also accepted as a prefix.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      property - The property to match a getter for.
      Returns:
      A matcher that matches any getter method for the supplied property.
    • isGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(Class<?> type)
      Matches any Java bean getter method which returns the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required getter type.
      Returns:
      A matcher that matches a getter method with the given type.
    • isGenericGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericGetter(Type type)
      Matches any Java bean getter method which returns the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required getter type.
      Returns:
      A matcher that matches a getter method with the given type.
    • isGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(TypeDescription type)
      Matches any Java bean getter method which returns the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required getter type.
      Returns:
      A matcher that matches a getter method with the given type.
    • isGenericGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericGetter(TypeDescription.Generic type)
      Matches any Java bean getter method which returns the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The required getter type.
      Returns:
      A matcher that matches a getter method with the given type.
    • isGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(ElementMatcher<? super TypeDescription> matcher)
      Matches any Java bean getter method which returns a value with a type matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to be allied to a getter method's argument type.
      Returns:
      A matcher that matches a getter method with a return type that matches the supplied matcher.
    • isGenericGetter

      public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericGetter(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches any Java bean getter method which returns a value with a type matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to be allied to a getter method's argument type.
      Returns:
      A matcher that matches a getter method with a return type that matches the supplied matcher.
    • hasMethodName

      public static <T extends MethodDescription> ElementMatcher.Junction<T> hasMethodName(String internalName)
      Matches a method against its internal name such that constructors and type initializers are matched appropriately.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      internalName - The internal name of the method.
      Returns:
      A matcher for a method with the provided internal name.
    • hasSignature

      public static <T extends MethodDescription> ElementMatcher.Junction<T> hasSignature(MethodDescription.SignatureToken token)
      Only matches method descriptions that yield the provided signature token.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      token - The signature token to match against.
      Returns:
      A matcher for a method with the provided signature token.
    • isSubTypeOf

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isSubTypeOf(Class<?> type)
      Matches any type description that is a subtype of the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to be checked for being a subtype of the matched type.
      Returns:
      A matcher that matches any type description that represents a sub type of the given type.
    • isSubTypeOf

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isSubTypeOf(TypeDescription type)
      Matches any type description that is a subtype of the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to be checked for being a subtype of the matched type.
      Returns:
      A matcher that matches any type description that represents a sub type of the given type.
    • isSuperTypeOf

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isSuperTypeOf(Class<?> type)
      Matches any type description that is a super type of the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to be checked for being a subtype of the matched type.
      Returns:
      A matcher that matches any type description that represents a super type of the given type.
    • isSuperTypeOf

      public static <T extends TypeDescription> ElementMatcher.Junction<T> isSuperTypeOf(TypeDescription type)
      Matches any type description that is a super type of the given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The type to be checked for being a subtype of the matched type.
      Returns:
      A matcher that matches any type description that represents a super type of the given type.
    • hasSuperClass

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasSuperClass(ElementMatcher<? super TypeDescription> matcher)
      Matches any type description that declares a super class (but not interface) that matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The type to be checked for being a super class of the matched type.
      Returns:
      A matcher that matches any type description that declares a super class that matches the provided matcher.
    • hasGenericSuperClass

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasGenericSuperClass(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches any type description that declares a super class (but not interface) that matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The type to be checked for being a super class of the matched type.
      Returns:
      A matcher that matches any type description that declares a super class that matches the provided matcher.
    • hasSuperType

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasSuperType(ElementMatcher<? super TypeDescription> matcher)
      Matches any type description that declares a super type that matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The type to be checked for being a super type of the matched type.
      Returns:
      A matcher that matches any type description that declares a super type that matches the provided matcher.
    • hasGenericSuperType

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasGenericSuperType(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches any type description that declares a super type that matches the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The type to be checked for being a super type of the matched type.
      Returns:
      A matcher that matches any type description that declares a super type that matches the provided matcher.
    • inheritsAnnotation

      public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(Class<?> type)
      Matches any annotations by their type on a type that declared these annotations or inherited them from its super classes.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The annotation type to be matched.
      Returns:
      A matcher that matches any inherited annotation by their type.
    • inheritsAnnotation

      public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(TypeDescription type)
      Matches any annotations by their type on a type that declared these annotations or inherited them from its super classes.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The annotation type to be matched.
      Returns:
      A matcher that matches any inherited annotation by their type.
    • inheritsAnnotation

      public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(ElementMatcher<? super TypeDescription> matcher)
      Matches any annotations by a given matcher on a type that declared these annotations or inherited them from its super classes.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to apply onto the inherited annotations.
      Returns:
      A matcher that matches any inherited annotation by a given matcher.
    • hasAnnotation

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasAnnotation(ElementMatcher<? super AnnotationDescription> matcher)
      Matches a list of annotations by a given matcher on a type that declared these annotations or inherited them from its super classes.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher to apply onto a list of inherited annotations.
      Returns:
      A matcher that matches a list of inherited annotation by a given matcher.
    • hasClassFileVersionAtLeast

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasClassFileVersionAtLeast(ClassFileVersion classFileVersion)
      Matches a type to have a minimal class file version. If a type description is not implying a class file version, it is not matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      classFileVersion - The minimal class file version to match.
      Returns:
      A matcher that matches a type description by its class file version.
    • hasClassFileVersionAtMost

      public static <T extends TypeDescription> ElementMatcher.Junction<T> hasClassFileVersionAtMost(ClassFileVersion classFileVersion)
      Matches a type to have a maximal class file version. If a type description is not implying a class file version, it is not matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      classFileVersion - The maximal class file version to match.
      Returns:
      A matcher that matches a type description by its class file version.
    • declaresField

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresField(ElementMatcher<? super FieldDescription> matcher)
      Matches a type by another matcher that is applied on any of its declared fields.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher that is applied onto each declared field.
      Returns:
      A matcher that matches any type where another matcher is matched positively on at least on declared field.
    • declaresMethod

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresMethod(ElementMatcher<? super MethodDescription> matcher)
      Matches a type by another matcher that is applied on any of its declared methods.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher that is applied onto each declared method.
      Returns:
      A matcher that matches any type where another matcher is matched positively on at least on declared methods.
    • ofSort

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> ofSort(TypeDefinition.Sort sort)
      Matches generic type descriptions of the given sort.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      sort - The generic type sort to match.
      Returns:
      A matcher that matches generic types of the given sort.
    • ofSort

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> ofSort(ElementMatcher<? super TypeDefinition.Sort> matcher)
      Matches generic type descriptions of the given sort.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - A matcher for a generic type's sort.
      Returns:
      A matcher that matches generic types of the given sort.
    • isPrimitive

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> isPrimitive()
      Matches a type if it is primitive.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that determines if a type is primitive.
    • isArray

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> isArray()
      Matches a type if it is an array type.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that determines if a type is an array type.
    • isRecord

      public static <T extends TypeDefinition> ElementMatcher.Junction<T> isRecord()
      Matches a type if it is a record type.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that determines if a type is a record type.
    • genericFieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(Type fieldType)
      Matches a field's generic type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      fieldType - The field type to match.
      Returns:
      A matcher matching the provided field type.
    • genericFieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(TypeDescription.Generic fieldType)
      Matches a field's generic type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      fieldType - The field type to match.
      Returns:
      A matcher matching the provided field type.
    • genericFieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> genericFieldType(ElementMatcher<? super TypeDescription.Generic> matcher)
      Matches a field's generic type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to the field's type.
      Returns:
      A matcher matching the provided field type.
    • fieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(Class<?> fieldType)
      Matches a field's raw type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      fieldType - The field type to match.
      Returns:
      A matcher matching the provided field type.
    • fieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(TypeDescription fieldType)
      Matches a field's raw type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      fieldType - The field type to match.
      Returns:
      A matcher matching the provided field type.
    • fieldType

      public static <T extends FieldDescription> ElementMatcher.Junction<T> fieldType(ElementMatcher<? super TypeDescription> matcher)
      Matches a field's raw type against the provided matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to the field's type.
      Returns:
      A matcher matching the provided field type.
    • isVolatile

      public static <T extends FieldDescription> ElementMatcher.Junction<T> isVolatile()
      Matches a volatile field.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a volatile field.
    • isTransient

      public static <T extends FieldDescription> ElementMatcher.Junction<T> isTransient()
      Matches a transient field.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher for a transient field.
    • annotationType

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(Class<? extends Annotation> type)
      Matches if an annotation is of a given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The expected annotation type.
      Returns:
      A matcher that matches the annotation's type for being equal to the given type.
    • annotationType

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(TypeDescription type)
      Matches if an annotation is of a given type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      type - The expected annotation type.
      Returns:
      A matcher that matches the annotation's type for being equal to the given type.
    • annotationType

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(ElementMatcher<? super TypeDescription> matcher)
      Matches if an annotation's type matches the supplied matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to match the annotation's type against.
      Returns:
      A matcher that matches the annotation's type.
    • targetsElement

      public static <T extends AnnotationDescription> ElementMatcher.Junction<T> targetsElement(ElementType elementType)
      Matches if an annotation can target a given element type.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      elementType - The element type we target.
      Returns:
      A matcher that matches annotations that target an element type.
    • isBootstrapClassLoader

      public static <T extends ClassLoader> ElementMatcher.Junction<T> isBootstrapClassLoader()
      Matches exactly the bootstrap ClassLoader. The returned matcher is a synonym to a matcher matching null.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the bootstrap class loader.
    • isSystemClassLoader

      public static <T extends ClassLoader> ElementMatcher.Junction<T> isSystemClassLoader()
      Matches exactly the system ClassLoader. The returned matcher is a synonym to a matcher matching ClassLoader.gerSystemClassLoader().
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the system class loader.
    • isExtensionClassLoader

      public static <T extends ClassLoader> ElementMatcher.Junction<T> isExtensionClassLoader()
      Matches exactly the extension ClassLoader. The returned matcher is a synonym to a matcher matching ClassLoader.gerSystemClassLoader().getParent().
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that only matches the extension class loader.
    • isChildOf

      public static <T extends ClassLoader> ElementMatcher.Junction<T> isChildOf(@MaybeNull ClassLoader classLoader)
      Matches any class loader that is either the given class loader or a child of the given class loader.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      classLoader - The class loader of which child class loaders are matched.
      Returns:
      A matcher that matches the given class loader and any class loader that is a child of the given class loader.
    • hasChild

      public static <T extends ClassLoader> ElementMatcher.Junction<T> hasChild(ElementMatcher<? super ClassLoader> matcher)
      Matches all class loaders in the hierarchy of the matched class loader against a given matcher.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to all class loaders in the hierarchy of the matched class loader.
      Returns:
      A matcher that matches all class loaders in the hierarchy of the matched class loader.
    • isParentOf

      public static <T extends ClassLoader> ElementMatcher.Junction<T> isParentOf(@MaybeNull ClassLoader classLoader)
      Matches any class loader that is either the given class loader or a parent of the given class loader.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      classLoader - The class loader of which parent class loaders are matched.
      Returns:
      A matcher that matches the given class loader and any class loader that is a parent of the given class loader.
    • ofType

      public static <T extends ClassLoader> ElementMatcher.Junction<T> ofType(ElementMatcher<? super TypeDescription> matcher)
      Matches a class loader's type unless it is the bootstrap class loader which is never matched.
      Type Parameters:
      T - The type of the matched object.
      Parameters:
      matcher - The matcher to apply to the class loader's type.
      Returns:
      A matcher that matches the class loader's type.
    • supportsModules

      public static <T extends JavaModule> ElementMatcher.Junction<T> supportsModules()
      Matches a module if it exists, i.e. not null.
      Type Parameters:
      T - The type of the matched object.
      Returns:
      A matcher that validates a module's existence.