Java Code Examples for org.springframework.core.annotation.AnnotationUtils#isInJavaLangAnnotationPackage()

The following examples show how to use org.springframework.core.annotation.AnnotationUtils#isInJavaLangAnnotationPackage() . 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: AnnotationAttributesReadingVisitor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) {
	Class<? extends Annotation> annotationType = annotation.annotationType();
	String annotationName = annotationType.getName();
	if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) {
		try {
			// Only do attribute scanning for public annotations; we'd run into
			// IllegalAccessExceptions otherwise, and we don't want to mess with
			// accessibility in a SecurityManager environment.
			if (Modifier.isPublic(annotationType.getModifiers())) {
				this.attributesMap.add(annotationName,
						AnnotationUtils.getAnnotationAttributes(annotation, false, true));
			}
			for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) {
				recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
			}
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex);
			}
		}
	}
}
 
Example 2
Source File: AnnotationAttributesReadingVisitor.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) {
	Class<? extends Annotation> annotationType = annotation.annotationType();
	String annotationName = annotationType.getName();
	if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) {
		try {
			// Only do attribute scanning for public annotations; we'd run into
			// IllegalAccessExceptions otherwise, and we don't want to mess with
			// accessibility in a SecurityManager environment.
			if (Modifier.isPublic(annotationType.getModifiers())) {
				this.attributesMap.add(annotationName,
						AnnotationUtils.getAnnotationAttributes(annotation, false, true));
			}
			for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) {
				recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
			}
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Failed to introspect meta-annotations on " + annotation + ": " + ex);
			}
		}
	}
}
 
Example 3
Source File: AnnotationAttributesReadingVisitor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void recursivelyCollectMetaAnnotations(Set<Annotation> visited, Annotation annotation) {
	Class<? extends Annotation> annotationType = annotation.annotationType();
	String annotationName = annotationType.getName();
	if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) && visited.add(annotation)) {
		try {
			// Only do attribute scanning for public annotations; we'd run into
			// IllegalAccessExceptions otherwise, and we don't want to mess with
			// accessibility in a SecurityManager environment.
			if (Modifier.isPublic(annotationType.getModifiers())) {
				this.attributesMap.add(annotationName,
						AnnotationUtils.getAnnotationAttributes(annotation, false, true));
			}
			for (Annotation metaMetaAnnotation : annotationType.getAnnotations()) {
				recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
			}
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Failed to introspect meta-annotations on [" + annotation + "]: " + ex);
			}
		}
	}
}
 
Example 4
Source File: AnnotationAttributesReadingVisitor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void doVisitEnd(Class<?> annotationClass) {
	super.doVisitEnd(annotationClass);
	List<AnnotationAttributes> attributes = this.attributesMap.get(this.annotationType);
	if (attributes == null) {
		this.attributesMap.add(this.annotationType, this.attributes);
	}
	else {
		attributes.add(0, this.attributes);
	}
	Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
	Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
	if (!ObjectUtils.isEmpty(metaAnnotations)) {
		for (Annotation metaAnnotation : metaAnnotations) {
			if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
				recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
			}
		}
	}
	if (this.metaAnnotationMap != null) {
		this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
	}
}
 
Example 5
Source File: AnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
	if (!visible) {
		return null;
	}
	String className = Type.getType(desc).getClassName();
	if (AnnotationUtils.isInJavaLangAnnotationPackage(className)) {
		return null;
	}
	this.annotationSet.add(className);
	return new AnnotationAttributesReadingVisitor(
			className, this.attributesMap, this.metaAnnotationMap, this.classLoader);
}
 
Example 6
Source File: AnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean hasMetaAnnotation(String metaAnnotationType) {
	if (AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotationType)) {
		return false;
	}
	Collection<Set<String>> allMetaTypes = this.metaAnnotationMap.values();
	for (Set<String> metaTypes : allMetaTypes) {
		if (metaTypes.contains(metaAnnotationType)) {
			return true;
		}
	}
	return false;
}
 
Example 7
Source File: AnnotationAttributesReadingVisitor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void visitEnd() {
	super.visitEnd();

	Class<? extends Annotation> annotationClass = this.attributes.annotationType();
	if (annotationClass != null) {
		List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
		if (attributeList == null) {
			this.attributesMap.add(this.annotationType, this.attributes);
		}
		else {
			attributeList.add(0, this.attributes);
		}
		if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) {
			try {
				Annotation[] metaAnnotations = annotationClass.getAnnotations();
				if (!ObjectUtils.isEmpty(metaAnnotations)) {
					Set<Annotation> visited = new LinkedHashSet<>();
					for (Annotation metaAnnotation : metaAnnotations) {
						recursivelyCollectMetaAnnotations(visited, metaAnnotation);
					}
					if (!visited.isEmpty()) {
						Set<String> metaAnnotationTypeNames = new LinkedHashSet<>(visited.size());
						for (Annotation ann : visited) {
							metaAnnotationTypeNames.add(ann.annotationType().getName());
						}
						this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
					}
				}
			}
			catch (Throwable ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Failed to introspect meta-annotations on " + annotationClass + ": " + ex);
				}
			}
		}
	}
}
 
Example 8
Source File: AnnotationAttributesReadingVisitor.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void visitEnd() {
	super.visitEnd();

	Class<? extends Annotation> annotationClass = this.attributes.annotationType();
	if (annotationClass != null) {
		List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
		if (attributeList == null) {
			this.attributesMap.add(this.annotationType, this.attributes);
		}
		else {
			attributeList.add(0, this.attributes);
		}
		if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationClass.getName())) {
			try {
				Annotation[] metaAnnotations = annotationClass.getAnnotations();
				if (!ObjectUtils.isEmpty(metaAnnotations)) {
					Set<Annotation> visited = new LinkedHashSet<>();
					for (Annotation metaAnnotation : metaAnnotations) {
						recursivelyCollectMetaAnnotations(visited, metaAnnotation);
					}
					if (!visited.isEmpty()) {
						Set<String> metaAnnotationTypeNames = new LinkedHashSet<>(visited.size());
						for (Annotation ann : visited) {
							metaAnnotationTypeNames.add(ann.annotationType().getName());
						}
						this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
					}
				}
			}
			catch (Throwable ex) {
				if (logger.isDebugEnabled()) {
					logger.debug("Failed to introspect meta-annotations on " + annotationClass + ": " + ex);
				}
			}
		}
	}
}
 
Example 9
Source File: AnnotationAttributesReadingVisitor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitEnd() {
	super.visitEnd();

	Class<?> annotationClass = this.attributes.annotationType();
	if (annotationClass != null) {
		List<AnnotationAttributes> attributeList = this.attributesMap.get(this.annotationType);
		if (attributeList == null) {
			this.attributesMap.add(this.annotationType, this.attributes);
		}
		else {
			attributeList.add(0, this.attributes);
		}
		Set<Annotation> visited = new LinkedHashSet<Annotation>();
		Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
		if (!ObjectUtils.isEmpty(metaAnnotations)) {
			for (Annotation metaAnnotation : metaAnnotations) {
				if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
					recursivelyCollectMetaAnnotations(visited, metaAnnotation);
				}
			}
		}
		if (this.metaAnnotationMap != null) {
			Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>(visited.size());
			for (Annotation ann : visited) {
				metaAnnotationTypeNames.add(ann.annotationType().getName());
			}
			this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
		}
	}
}
 
Example 10
Source File: AnnotationAttributesReadingVisitor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void recursivelyCollectMetaAnnotations(Set<String> visited, Annotation annotation) {
	String annotationName = annotation.annotationType().getName();
	if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation) && visited.add(annotationName)) {
		// Only do further scanning for public annotations; we'd run into
		// IllegalAccessExceptions otherwise, and we don't want to mess with
		// accessibility in a SecurityManager environment.
		if (Modifier.isPublic(annotation.annotationType().getModifiers())) {
			this.attributesMap.add(annotationName, AnnotationUtils.getAnnotationAttributes(annotation, false, true));
			for (Annotation metaMetaAnnotation : annotation.annotationType().getAnnotations()) {
				recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
			}
		}
	}
}
 
Example 11
Source File: MetaAnnotationUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source File: MetaAnnotationUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: AnnotationMetadataReadingVisitor.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
Example 14
Source File: AnnotationMetadataReadingVisitor.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
Example 15
Source File: AnnotationMetadataReadingVisitor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
Example 16
Source File: AnnotationMetadataReadingVisitor.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}