Java Code Examples for org.springframework.core.annotation.AnnotationUtils#isAnnotationDeclaredLocally()
The following examples show how to use
org.springframework.core.annotation.AnnotationUtils#isAnnotationDeclaredLocally() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleConditionService.java From spring-init with Apache License 2.0 | 6 votes |
@Override public boolean matches(Class<?> factory, Class<?> type) { AnnotationMetadata metadata = getMetadata(factory); Set<MethodMetadata> assignable = new HashSet<>(); for (MethodMetadata method : metadata.getAnnotatedMethods(Bean.class.getName())) { Class<?> candidate = ClassUtils.resolveClassName(method.getReturnTypeName(), this.classLoader); // Look for exact match first if (type.equals(candidate)) { return !this.evaluator.shouldSkip(method); } if (type.isAssignableFrom(candidate)) { assignable.add(method); } } if (assignable.size() == 1) { return !this.evaluator.shouldSkip(assignable.iterator().next()); } // TODO: fail if size() > 1 Class<?> base = factory.getSuperclass(); if (AnnotationUtils.isAnnotationDeclaredLocally(Configuration.class, base)) { return matches(base, type); } return false; }
Example 2
Source File: ClassPathScanningCandidateComponentProvider.java From spring-analysis-note with MIT License | 5 votes |
/** * Determine if the specified include {@link TypeFilter} is supported by the index. * @param filter the filter to check * @return whether the index supports this include filter * @since 5.0 * @see #extractStereotype(TypeFilter) */ private boolean indexSupportsIncludeFilter(TypeFilter filter) { if (filter instanceof AnnotationTypeFilter) { Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType(); return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) || annotation.getName().startsWith("javax.")); } if (filter instanceof AssignableTypeFilter) { Class<?> target = ((AssignableTypeFilter) filter).getTargetType(); return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target); } return false; }
Example 3
Source File: ClassPathScanningCandidateComponentProvider.java From java-technology-stack with MIT License | 5 votes |
/** * Determine if the specified include {@link TypeFilter} is supported by the index. * @param filter the filter to check * @return whether the index supports this include filter * @since 5.0 * @see #extractStereotype(TypeFilter) */ private boolean indexSupportsIncludeFilter(TypeFilter filter) { if (filter instanceof AnnotationTypeFilter) { Class<? extends Annotation> annotation = ((AnnotationTypeFilter) filter).getAnnotationType(); return (AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, annotation) || annotation.getName().startsWith("javax.")); } if (filter instanceof AssignableTypeFilter) { Class<?> target = ((AssignableTypeFilter) filter).getTargetType(); return AnnotationUtils.isAnnotationDeclaredLocally(Indexed.class, target); } return false; }
Example 4
Source File: QConfigAnnotationProcessor.java From qconfig with MIT License | 5 votes |
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Class<?> clazz = getRealClass(bean); if (AnnotationUtils.isAnnotationDeclaredLocally(DisableQConfig.class, clazz)) return bean; AnnotationManager manager = getOrCreateManager(clazz); manager.init(clazz); manager.processBean(bean); return bean; }
Example 5
Source File: GlobalResponseController.java From FATE-Serving with Apache License 2.0 | 5 votes |
@Override public boolean supports(MethodParameter methodParameter, Class converterType) { Boolean isRest = AnnotationUtils.isAnnotationDeclaredLocally( RestController.class, methodParameter.getContainingClass()); ResponseBody responseBody = AnnotationUtils.findAnnotation( methodParameter.getMethod(), ResponseBody.class); if (responseBody != null || isRest) { return true; } else { return false; } }
Example 6
Source File: MetaAnnotationUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Perform the search algorithm for {@link #findAnnotationDescriptor(Class, Class)}, * avoiding endless recursion by tracking which annotations have already been * <em>visited</em>. * @param clazz the class to look for annotations on * @param visited the set of annotations that have already been visited * @param annotationType the type of annotation to look for * @return the corresponding annotation descriptor if the annotation was found; * otherwise {@code null} */ private static <T extends Annotation> AnnotationDescriptor<T> findAnnotationDescriptor(Class<?> clazz, Set<Annotation> visited, Class<T> annotationType) { Assert.notNull(annotationType, "Annotation type must not be null"); if (clazz == null || Object.class == clazz) { return null; } // Declared locally? if (AnnotationUtils.isAnnotationDeclaredLocally(annotationType, clazz)) { return new AnnotationDescriptor<T>(clazz, clazz.getAnnotation(annotationType)); } // Declared on a composed annotation (i.e., as a meta-annotation)? for (Annotation composedAnnotation : clazz.getDeclaredAnnotations()) { if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedAnnotation) && visited.add(composedAnnotation)) { AnnotationDescriptor<T> descriptor = findAnnotationDescriptor(composedAnnotation.annotationType(), visited, annotationType); if (descriptor != null) { return new AnnotationDescriptor<T>(clazz, descriptor.getDeclaringClass(), composedAnnotation, descriptor.getAnnotation()); } } } // Declared on a superclass? return findAnnotationDescriptor(clazz.getSuperclass(), visited, annotationType); }
Example 7
Source File: MetaAnnotationUtils.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Perform the search algorithm for {@link #findAnnotationDescriptorForTypes(Class, Class...)}, * avoiding endless recursion by tracking which annotations have already been * <em>visited</em>. * @param clazz the class to look for annotations on * @param visited the set of annotations that have already been visited * @param annotationTypes the types of annotations to look for * @return the corresponding annotation descriptor if one of the annotations * was found; otherwise {@code null} */ @SuppressWarnings("unchecked") private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class<?> clazz, Set<Annotation> visited, Class<? extends Annotation>... annotationTypes) { assertNonEmptyAnnotationTypeArray(annotationTypes, "The list of annotation types must not be empty"); if (clazz == null || Object.class == clazz) { return null; } // Declared locally? for (Class<? extends Annotation> annotationType : annotationTypes) { if (AnnotationUtils.isAnnotationDeclaredLocally(annotationType, clazz)) { return new UntypedAnnotationDescriptor(clazz, clazz.getAnnotation(annotationType)); } } // Declared on a composed annotation (i.e., as a meta-annotation)? for (Annotation composedAnnotation : clazz.getDeclaredAnnotations()) { if (!AnnotationUtils.isInJavaLangAnnotationPackage(composedAnnotation) && visited.add(composedAnnotation)) { UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes( composedAnnotation.annotationType(), visited, annotationTypes); if (descriptor != null) { return new UntypedAnnotationDescriptor(clazz, descriptor.getDeclaringClass(), composedAnnotation, descriptor.getAnnotation()); } } } // Declared on a superclass? return findAnnotationDescriptorForTypes(clazz.getSuperclass(), visited, annotationTypes); }