org.springframework.core.annotation.AnnotationUtils#isInJavaLangAnnotationPackage ( )源码实例Demo

下面列出了org.springframework.core.annotation.AnnotationUtils#isInJavaLangAnnotationPackage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
			}
		}
	}
}
 
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);
			}
		}
	}
}
 
源代码3 项目: lams   文件: AnnotationAttributesReadingVisitor.java
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);
			}
		}
	}
}
 
@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);
	}
}
 
@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);
}
 
@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;
}
 
@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);
				}
			}
		}
	}
}
 
@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);
				}
			}
		}
	}
}
 
源代码9 项目: lams   文件: AnnotationAttributesReadingVisitor.java
@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);
		}
	}
}
 
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);
			}
		}
	}
}
 
/**
 * 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);
}
 
/**
 * 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);
}
 
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
源代码15 项目: lams   文件: AnnotationMetadataReadingVisitor.java
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}
 
@Override
public boolean isAnnotated(String annotationName) {
	return (!AnnotationUtils.isInJavaLangAnnotationPackage(annotationName) &&
			this.attributesMap.containsKey(annotationName));
}