/** * Filter on methods with the given parameter types. */ public Builder<T> argTypes(Class<?>... argTypes) { addFilter("argTypes=" + Arrays.toString(argTypes), method -> ObjectUtils.isEmpty(argTypes) ? method.getParameterCount() == 0 : Arrays.equals(method.getParameterTypes(), argTypes)); return this; }
/** * Filter on methods with the given name. */ public Builder<T> named(String methodName) { addFilter("methodName=" + methodName, method -> method.getName().equals(methodName)); return this; }
/** * Filter on methods annotated with the given annotation type. * @see #annot(Predicate[]) * See {@link org.springframework.web.method.MvcAnnotationPredicates}. */ @SafeVarargs public final Builder<T> annotPresent(Class<? extends Annotation>... annotationTypes) { String message = "annotationPresent=" + Arrays.toString(annotationTypes); addFilter(message, method -> Arrays.stream(annotationTypes).allMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(method, annotType) != null)); return this; }
/** * Filter on methods not annotated with the given annotation type. */ @SafeVarargs public final Builder<T> annotNotPresent(Class<? extends Annotation>... annotationTypes) { String message = "annotationNotPresent=" + Arrays.toString(annotationTypes); addFilter(message, method -> { if (annotationTypes.length != 0) { return Arrays.stream(annotationTypes).noneMatch(annotType -> AnnotatedElementUtils.findMergedAnnotation(method, annotType) != null); } else { return method.getAnnotations().length == 0; } }); return this; }
/** * Filter on methods returning the given type. * @param returnType the return type */ public Builder<T> returning(ResolvableType returnType) { String expected = returnType.toString(); String message = "returnType=" + expected; addFilter(message, m -> expected.equals(ResolvableType.forMethodReturnType(m).toString())); return this; }