/** * {@inheritDoc} */ public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) { return (ElementMatcher<? super MethodDescription>) not(ignoredMethods.resolve(typeDescription)) .and(isVirtual().and(not(isFinal())).or(isDeclaredBy(typeDescription))) .or(isDeclaredBy(typeDescription).and(not(predefinedMethodSignatures))); } }
/** * Only matches the {@link Object#toString()} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#toString()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isHashCode() { return named("hashCode").and(takesArguments(0)).and(returns(int.class)); }
/** * Matches any Java bean setter method. * * @param <T> The type of the matched object. * @return A matcher that matches any setter method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter() { return nameStartsWith("set").and(takesArguments(1)).and(returns(TypeDescription.VOID)); }
/** * Matches a default constructor, i.e. a constructor without arguments. * * @param <T> The type of the matched object. * @return A matcher that matches a default constructor. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultConstructor() { return isConstructor().and(takesArguments(0)); }
/** * Only matches the {@link Object#finalize()} method if it was not overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches a non-overridden {@link Object#finalize()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isDefaultFinalizer() { return isFinalizer().and(isDeclaredBy(TypeDescription.OBJECT)); }
/** * Matches a module if it exists, i.e. not {@code null}. * * @param <T> The type of the matched object. * @return A matcher that validates a module's existence. */ public static <T extends JavaModule> ElementMatcher.Junction<T> supportsModules() { return not(new NullMatcher<T>()); } }
/** * Matches a type variable with the given name. * * @param matcher A matcher for the type variable's name. * @param <T> The type of the matched object. * @return A matcher that matches type variables with the given name. */ public static <T extends TypeDefinition> ElementMatcher.Junction<T> isVariable(ElementMatcher<? super NamedElement> matcher) { return new TypeSortMatcher<T>(anyOf(TypeDefinition.Sort.VARIABLE, TypeDefinition.Sort.VARIABLE_SYMBOLIC)).and(matcher); }
/** * Matches a {@link MethodDescription} by applying an iterable collection of element matcher on any parameter's {@link TypeDescription}. * * @param matchers The matcher that are applied onto the parameter types of the matched method description. * @param <T> The type of the matched object. * @return A matcher that matches a method description by applying another element matcher onto each parameter's type. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(ElementMatcher<? super Iterable<? extends TypeDescription>> matchers) { return new MethodParametersMatcher<T>(new MethodParameterTypesMatcher<ParameterList<?>>(erasures(matchers))); }
/** * Matches a {@link NamedElement} for its name's prefix. * * @param prefix The expected name's prefix. * @param <T> The type of the matched object. * @return An element matcher for a named element's name's prefix. */ public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWith(String prefix) { return new NameMatcher<T>(new StringMatcher(prefix, StringMatcher.Mode.STARTS_WITH)); }
/** * Exactly matches a given method or constructor as a {@link MethodDescription} in its defined shape. * * @param method The method to match by its description * @param <T> The type of the matched object. * @return An element matcher that exactly matches the given method or constructor in its defined shape. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> is(MethodDescription.InDefinedShape method) { return definedMethod(new EqualityMatcher<MethodDescription.InDefinedShape>(method)); }
/** * Matches a list of annotations by a given matcher on a type that declared these annotations or inherited them * from its super classes. * * @param matcher A matcher to apply onto a list of inherited annotations. * @param <T> The type of the matched object. * @return A matcher that matches a list of inherited annotation by a given matcher. */ public static <T extends TypeDescription> ElementMatcher.Junction<T> hasAnnotation(ElementMatcher<? super AnnotationDescription> matcher) { return new InheritedAnnotationMatcher<T>(new CollectionItemMatcher<AnnotationDescription>(matcher)); }
/** * Matches a type by a another matcher that is applied on any of its declared fields. * * @param matcher The matcher that is applied onto each declared field. * @param <T> The type of the matched object. * @return A matcher that matches any type where another matcher is matched positively on at least on declared field. */ public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresField(ElementMatcher<? super FieldDescription> matcher) { return new DeclaringFieldMatcher<T>(new CollectionItemMatcher<FieldDescription>(matcher)); }
/** * Matches a type by a another matcher that is applied on any of its declared methods. * * @param matcher The matcher that is applied onto each declared method. * @param <T> The type of the matched object. * @return A matcher that matches any type where another matcher is matched positively on at least on declared methods. */ public static <T extends TypeDefinition> ElementMatcher.Junction<T> declaresMethod(ElementMatcher<? super MethodDescription> matcher) { return new DeclaringMethodMatcher<T>(new CollectionItemMatcher<MethodDescription>(matcher)); }
/** * Only matches the {@link Object#equals(Object)} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#equals(Object)} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isEquals() { return named("equals").and(takesArguments(TypeDescription.OBJECT)).and(returns(boolean.class)); }
/** * {@inheritDoc} */ public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) { // Casting is required by JDK 6. return (ElementMatcher<? super MethodDescription>) isVirtual().and(not(isFinal())) .and(isVisibleTo(typeDescription)) .and(not(ignoredMethods.resolve(typeDescription))) .or(isDeclaredBy(typeDescription)); } }
/** * Matches a {@link NamedElement} for its name's suffix. * * @param suffix The expected name's suffix. * @param <T> The type of the matched object. * @return An element matcher for a named element's name's suffix. */ public static <T extends NamedElement> ElementMatcher.Junction<T> nameEndsWith(String suffix) { return new NameMatcher<T>(new StringMatcher(suffix, StringMatcher.Mode.ENDS_WITH)); }
/** * Only matches the {@link Object#toString()} method, also if it was overridden. * * @param <T> The type of the matched object. * @return A matcher that only matches the {@link Object#toString()} method. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isToString() { return named("toString").and(takesArguments(0)).and(returns(TypeDescription.STRING)); }
/** * Matches a {@link NamedElement} for its exact name. * * @param name The expected name. * @param <T> The type of the matched object. * @return An element matcher for a named element's exact name. */ public static <T extends NamedElement> ElementMatcher.Junction<T> named(String name) { return new NameMatcher<T>(new StringMatcher(name, StringMatcher.Mode.EQUALS_FULLY)); }