/** * Return whether the parameter is declared with the given annotation type. * @param annotationType the annotation type to look for * @since 4.3 * @see AnnotatedElementUtils#hasAnnotation */ public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType) { return AnnotatedElementUtils.hasAnnotation(this.method, annotationType); }
/** * {@inheritDoc} * Expects a handler to have a type-level @{@link Controller} annotation. */ @Override protected boolean isHandler(Class<?> beanType) { return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) || AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class)); }
/** * {@inheritDoc} * <p>Expects a handler to have either a type-level @{@link Controller} * annotation or a type-level @{@link RequestMapping} annotation. */ @Override protected boolean isHandler(Class<?> beanType) { return (AnnotatedElementUtils.hasAnnotation(beanType, Controller.class) || AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class)); }
/** * Return whether the parameter is declared with the given annotation type. * @param annotationType the annotation type to look for * @since 4.3 * @see AnnotatedElementUtils#hasAnnotation */ public <A extends Annotation> boolean hasMethodAnnotation(Class<A> annotationType) { return AnnotatedElementUtils.hasAnnotation(this.method, annotationType); }
@Override protected boolean isHandler(Class<?> beanType) { return AnnotatedElementUtils.hasAnnotation(beanType, Controller.class); }
@Override public boolean supportsMethod(Method method) { return AnnotatedElementUtils.hasAnnotation(method, TransactionalEventListener.class); }
public static boolean isBeanAnnotated(Method method) { return AnnotatedElementUtils.hasAnnotation(method, Bean.class); }
@Override public boolean matches(Class<?> clazz) { return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(clazz, this.annotationType) : clazz.isAnnotationPresent(this.annotationType)); }
@Override protected boolean isHandler(Class<?> beanType) { return AnnotatedElementUtils.hasAnnotation(beanType, AdminController.class); }
private boolean matchesMethod(Method method) { return (this.checkInherited ? AnnotatedElementUtils.hasAnnotation(method, this.annotationType) : method.isAnnotationPresent(this.annotationType)); }
/** * Determine if the supplied {@link Parameter} can potentially be * autowired from an {@link ApplicationContext}. * <p>Returns {@code true} if the supplied parameter is of type * {@link ApplicationContext} (or a sub-type thereof) or is annotated or * meta-annotated with {@link Autowired @Autowired}, * {@link Qualifier @Qualifier}, or {@link Value @Value}. * @param parameter the parameter whose dependency should be autowired * @param parameterIndex the index of the parameter * @see #resolveDependency */ static boolean isAutowirable(Parameter parameter, int parameterIndex) { if (ApplicationContext.class.isAssignableFrom(parameter.getType())) { return true; } AnnotatedElement annotatedParameter = getEffectiveAnnotatedParameter(parameter, parameterIndex); return (AnnotatedElementUtils.hasAnnotation(annotatedParameter, Autowired.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Qualifier.class) || AnnotatedElementUtils.hasAnnotation(annotatedParameter, Value.class)); }
/** * Returns {@link WebDelegatingSmartContextLoader} if the supplied class is * annotated with {@link WebAppConfiguration @WebAppConfiguration} and * otherwise delegates to the superclass. */ @Override protected Class<? extends ContextLoader> getDefaultContextLoaderClass(Class<?> testClass) { if (AnnotatedElementUtils.hasAnnotation(testClass, WebAppConfiguration.class)) { return WebDelegatingSmartContextLoader.class; } else { return super.getDefaultContextLoaderClass(testClass); } }
/** * Get all methods in the supplied {@link Class class} and its superclasses * which are annotated with the supplied {@code annotationType} but * which are not <em>shadowed</em> by methods overridden in subclasses. * <p>Default methods on interfaces are also detected. * @param clazz the class for which to retrieve the annotated methods * @param annotationType the annotation type for which to search * @return all annotated methods in the supplied class and its superclasses * as well as annotated interface default methods */ private List<Method> getAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType) { return Arrays.stream(ReflectionUtils.getUniqueDeclaredMethods(clazz)) .filter(method -> AnnotatedElementUtils.hasAnnotation(method, annotationType)) .collect(Collectors.toList()); }
/** * Determine if the supplied {@link Class} meets the criteria for being * considered a <em>default configuration class</em> candidate. * <p>Specifically, such candidates: * <ul> * <li>must not be {@code null}</li> * <li>must not be {@code private}</li> * <li>must not be {@code final}</li> * <li>must be {@code static}</li> * <li>must be annotated or meta-annotated with {@code @Configuration}</li> * </ul> * @param clazz the class to check * @return {@code true} if the supplied class meets the candidate criteria */ private static boolean isDefaultConfigurationClassCandidate(@Nullable Class<?> clazz) { return (clazz != null && isStaticNonPrivateAndNonFinal(clazz) && AnnotatedElementUtils.hasAnnotation(clazz, Configuration.class)); }
private boolean isActivated(TestContext testContext) { return (Boolean.TRUE.equals(testContext.getAttribute(ACTIVATE_LISTENER)) || AnnotatedElementUtils.hasAnnotation(testContext.getTestClass(), WebAppConfiguration.class)); }
@Override public boolean supportsReturnType(MethodParameter returnType) { return (AnnotatedElementUtils.hasAnnotation(returnType.getContainingClass(), ResponseBody.class) || returnType.hasMethodAnnotation(ResponseBody.class)); }
@Override public boolean supportsReturnType(MethodParameter returnType) { return (returnType.hasMethodAnnotation(SendTo.class) || AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendTo.class) || returnType.hasMethodAnnotation(SendToUser.class) || AnnotatedElementUtils.hasAnnotation(returnType.getDeclaringClass(), SendToUser.class) || !this.annotationRequired); }
private int countAnnotatedMethods(Class<? extends Annotation> annotationType) { return (int) Arrays.stream(this.testClasses) .map(ReflectionUtils::getUniqueDeclaredMethods) .flatMap(Arrays::stream) .filter(method -> hasAnnotation(method, annotationType)) .count(); }
@Override public boolean supports(HandlerResult result) { MethodParameter returnType = result.getReturnTypeSource(); Class<?> containingClass = returnType.getContainingClass(); return (AnnotatedElementUtils.hasAnnotation(containingClass, ResponseBody.class) || returnType.hasMethodAnnotation(ResponseBody.class)); }
/** * Determine if the value for the {@link Parameter} in the supplied {@link ParameterContext} * should be autowired from the test's {@link ApplicationContext}. * <p>Returns {@code true} if the parameter is declared in a {@link Constructor} * that is annotated with {@link Autowired @Autowired} and otherwise delegates to * {@link ParameterAutowireUtils#isAutowirable}. * <p><strong>WARNING</strong>: If the parameter is declared in a {@code Constructor} * that is annotated with {@code @Autowired}, Spring will assume the responsibility * for resolving all parameters in the constructor. Consequently, no other registered * {@link ParameterResolver} will be able to resolve parameters. * @see #resolveParameter * @see ParameterAutowireUtils#isAutowirable */ @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Executable executable = parameter.getDeclaringExecutable(); return (executable instanceof Constructor && AnnotatedElementUtils.hasAnnotation(executable, Autowired.class)) || ParameterAutowireUtils.isAutowirable(parameter, index); }