/** * Matches a method description that takes the provided generic arguments. * * @param types The arguments to match against the matched method. * @param <T> The type of the matched object. * @return A method matcher that matches a method's generic parameter types against the supplied arguments. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> takesGenericArguments(List<? extends TypeDefinition> types) { List<ElementMatcher<? super TypeDescription.Generic>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription.Generic>>(); for (TypeDefinition type : types) { typeMatchers.add(is(type)); } return takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(typeMatchers)); }
/** * Matches a method description that takes the provided raw arguments. * * @param types The arguments to match against the matched method. * @param <T> The type of the matched object. * @return A method matcher that matches a method's raw parameter types against the supplied arguments. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Iterable<? extends TypeDescription> types) { List<ElementMatcher<? super TypeDescription.Generic>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription.Generic>>(); for (TypeDescription type : types) { typeMatchers.add(erasure(type)); } return takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(typeMatchers)); }
/** * 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. * * @param types The types to match. * @param <T> The type of the matched object. * @return A matcher that matches an iteration of generic types' raw types against the provided non-generic types. */ public static <T extends Iterable<? extends TypeDescription.Generic>> ElementMatcher.Junction<T> erasures( Iterable<? extends TypeDescription> types) { List<ElementMatcher<? super TypeDescription>> typeMatchers = new ArrayList<ElementMatcher<? super TypeDescription>>(); for (TypeDescription type : types) { typeMatchers.add(is(type)); } return erasures(new CollectionOneToOneMatcher<TypeDescription>(typeMatchers)); }
/** * Matches any Java bean setter method which takes an argument that matches the supplied matcher. * * @param matcher A matcher to be allied to a setter method's argument type. * @param <T> The type of the matched object. * @return A matcher that matches a setter method with an argument type that matches the supplied matcher. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGenericSetter(ElementMatcher<? super TypeDescription.Generic> matcher) { return isSetter().and(takesGenericArguments(new CollectionOneToOneMatcher<TypeDescription.Generic>(Collections.singletonList(matcher)))); }