/** * Matches any Java bean getter method which returns the given type. * * @param type The required getter type. * @param <T> The type of the matched object. * @return A matcher that matches a getter method with the given type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(TypeDescription type) { return isGetter(is(type)); }
/** * Matches any Java bean setter method which takes an argument the given type. * * @param type The required setter type. * @param <T> The type of the matched object. * @return A matcher that matches a setter method with the specified argument type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericSetter(TypeDescription.Generic type) { return isGenericSetter(is(type)); }
/** * Matches any Java bean setter method which takes an argument the given type. * * @param type The required setter type. * @param <T> The type of the matched object. * @return A matcher that matches a setter method with the specified argument type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(TypeDescription type) { return isSetter(is(type)); }
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isPublic().and(isConstructor()))).asTokenList(is(instrumentedType)); }
/** * Exactly matches a given field as a {@link FieldDescription} in its defined shape. * * @param field The field to match by its description * @param <T> The type of the matched object. * @return An element matcher that exactly matches the given field in its defined shape. */ public static <T extends FieldDescription> ElementMatcher.Junction<T> is(Field field) { return is(new FieldDescription.ForLoadedField(field)); }
@Override protected List<MethodDescription.Token> doExtractConstructors(TypeDescription instrumentedType) { TypeDescription.Generic superClass = instrumentedType.getSuperClass(); return (superClass == null ? new MethodList.Empty<MethodDescription.InGenericShape>() : superClass.getDeclaredMethods().filter(isConstructor().and(isVisibleTo(instrumentedType)))).asTokenList(is(instrumentedType)); }
/** * Matches any virtual method with a signature that is compatible to a method that is declared the supplied type. * * @param type The super type of interest for which to check if it declares a method with the same signature as the matched method. * @param <T> The type of the matched object. * @return A matcher that checks a method's signature equality for any method declared by the declaring type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isOverriddenFromGeneric(TypeDescription.Generic type) { return isOverriddenFromGeneric(is(type)); }
/** * Matches any Java bean getter method which returns the given type. * * @param type The required getter type. * @param <T> The type of the matched object. * @return A matcher that matches a getter method with the given type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericGetter(TypeDescription.Generic type) { return isGenericGetter(is(type)); }
/** * Matches if an annotation is of a given type. * * @param type The expected annotation type. * @param <T> The type of the matched object. * @return A matcher that matches the annotation's type for being equal to the given type. */ public static <T extends AnnotationDescription> ElementMatcher.Junction<T> annotationType(TypeDescription type) { return annotationType(is(type)); }
/** * Returns a new detachment visitor that detaches any type matching the supplied type description. * * @param typeDefinition The type to detach. * @return A detachment visitor for the supplied type description. */ public static Visitor<Generic> of(TypeDefinition typeDefinition) { return new ForDetachment(is(typeDefinition)); }
/** * Exactly matches a given annotation as an {@link AnnotationDescription}. * * @param annotation The annotation to match by its description. * @param <T> The type of the matched object. * @return An element matcher that exactly matches the given annotation. */ public static <T extends AnnotationDescription> ElementMatcher.Junction<T> is(Annotation annotation) { return is(AnnotationDescription.ForLoadedAnnotation.of(annotation)); }
/** * 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. * * @param type The type to match a generic type's erasure against. * @param <T> The type of the matched object. * @return A matcher that matches a generic type's raw type against the provided non-generic type. */ public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> erasure(Class<?> type) { return erasure(is(type)); }
/** * Matches {@link MethodDescription}s that define a given generic type as a parameter at the given index. * * @param index The index of the parameter. * @param type The generic type the matched method is expected to define as a parameter type. * @param <T> The type of the matched object. * @return An element matcher that matches a given generic return type for a method description. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArgument(int index, TypeDescription.Generic type) { return takesGenericArgument(index, is(type)); }
/** * Matches any annotations by their type on a type that declared these annotations or inherited them from its * super classes. * * @param type The annotation type to be matched. * @param <T> The type of the matched object. * @return A matcher that matches any inherited annotation by their type. */ public static <T extends TypeDescription> ElementMatcher.Junction<T> inheritsAnnotation(TypeDescription type) { return inheritsAnnotation(is(type)); }
/** * Exactly matches a given constructor as a {@link MethodDescription} in its defined shape. * * @param constructor The constructor to match by its description * @param <T> The type of the matched object. * @return An element matcher that exactly matches the given constructor in its defined shape. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Constructor<?> constructor) { return is(new MethodDescription.ForLoadedConstructor(constructor)); }
/** * 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. * * @param type The type to match a generic type's erasure against. * @param <T> The type of the matched object. * @return A matcher that matches a generic type's raw type against the provided non-generic type. */ public static <T extends TypeDescription.Generic> ElementMatcher.Junction<T> erasure(TypeDescription type) { return erasure(is(type)); }
/** * Matches {@link MethodDescription}s that returns a given * {@link TypeDescription}. * * @param type The type the matched method is expected to return. * @param <T> The type of the matched object. * @return An element matcher that matches a given return type for a method description. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> returnsGeneric(TypeDescription.Generic type) { return returnsGeneric(is(type)); }
/** * Returns a matcher that filters any method that should not be rebased. * * @param instrumentedType The instrumented type. * @param instrumentedMethods All instrumented methods. * @return A suitable matcher that filters all methods that should not be rebased. */ protected static ElementMatcher<MethodDescription.Token> of(TypeDescription instrumentedType, MethodList<?> instrumentedMethods) { return new RebaseableMatcher(new HashSet<MethodDescription.Token>(instrumentedMethods.asTokenList(is(instrumentedType)))); }
/** * {@inheritDoc} */ public ParameterList<ParameterDescription.InDefinedShape> getParameters() { return new ParameterList.ForTokens(this, bridgeTarget.getParameters().asTokenList(is(instrumentedType))); }
/** * {@inheritDoc} */ public DynamicType.Builder<?> apply(DynamicType.Builder<?> builder, FieldDescription fieldDescription, Assigner assigner, MethodAccessorFactory methodAccessorFactory) { return builder.method(definedMethod(is(getterMethod))).intercept(new FieldGetter(fieldDescription, assigner, methodAccessorFactory)); } }