|
|
|
@@ -20,6 +20,7 @@ import java.lang.annotation.Annotation;
|
|
|
|
import java.lang.reflect.Array;
|
|
|
|
import java.lang.reflect.Array;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
import java.lang.reflect.Modifier;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
@@ -28,6 +29,7 @@ import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.asm.AnnotationVisitor;
|
|
|
|
import org.springframework.asm.AnnotationVisitor;
|
|
|
|
import org.springframework.asm.SpringAsmInfo;
|
|
|
|
import org.springframework.asm.SpringAsmInfo;
|
|
|
|
import org.springframework.asm.Type;
|
|
|
|
import org.springframework.asm.Type;
|
|
|
|
@@ -51,14 +53,12 @@ abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
|
|
|
|
|
|
|
|
|
|
|
|
protected final ClassLoader classLoader;
|
|
|
|
protected final ClassLoader classLoader;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public AbstractRecursiveAnnotationVisitor(ClassLoader classLoader, AnnotationAttributes attributes) {
|
|
|
|
public AbstractRecursiveAnnotationVisitor(ClassLoader classLoader, AnnotationAttributes attributes) {
|
|
|
|
super(SpringAsmInfo.ASM_VERSION);
|
|
|
|
super(SpringAsmInfo.ASM_VERSION);
|
|
|
|
this.classLoader = classLoader;
|
|
|
|
this.classLoader = classLoader;
|
|
|
|
this.attributes = attributes;
|
|
|
|
this.attributes = attributes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void visit(String attributeName, Object attributeValue) {
|
|
|
|
public void visit(String attributeName, Object attributeValue) {
|
|
|
|
this.attributes.put(attributeName, attributeValue);
|
|
|
|
this.attributes.put(attributeName, attributeValue);
|
|
|
|
@@ -114,14 +114,12 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
|
|
|
|
|
|
|
|
|
|
|
|
private final List<AnnotationAttributes> allNestedAttributes = new ArrayList<AnnotationAttributes>();
|
|
|
|
private final List<AnnotationAttributes> allNestedAttributes = new ArrayList<AnnotationAttributes>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RecursiveAnnotationArrayVisitor(
|
|
|
|
public RecursiveAnnotationArrayVisitor(
|
|
|
|
String attributeName, AnnotationAttributes attributes, ClassLoader classLoader) {
|
|
|
|
String attributeName, AnnotationAttributes attributes, ClassLoader classLoader) {
|
|
|
|
super(classLoader, attributes);
|
|
|
|
super(classLoader, attributes);
|
|
|
|
this.attributeName = attributeName;
|
|
|
|
this.attributeName = attributeName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void visit(String attributeName, Object attributeValue) {
|
|
|
|
public void visit(String attributeName, Object attributeValue) {
|
|
|
|
Object newValue = attributeValue;
|
|
|
|
Object newValue = attributeValue;
|
|
|
|
@@ -170,24 +168,21 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
|
|
|
|
|
|
|
|
|
|
|
|
private final String annotationType;
|
|
|
|
private final String annotationType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RecursiveAnnotationAttributesVisitor(
|
|
|
|
public RecursiveAnnotationAttributesVisitor(
|
|
|
|
String annotationType, AnnotationAttributes attributes, ClassLoader classLoader) {
|
|
|
|
String annotationType, AnnotationAttributes attributes, ClassLoader classLoader) {
|
|
|
|
super(classLoader, attributes);
|
|
|
|
super(classLoader, attributes);
|
|
|
|
this.annotationType = annotationType;
|
|
|
|
this.annotationType = annotationType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public final void visitEnd() {
|
|
|
|
public final void visitEnd() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Class<?> annotationClass = this.classLoader.loadClass(this.annotationType);
|
|
|
|
Class<?> annotationClass = this.classLoader.loadClass(this.annotationType);
|
|
|
|
this.doVisitEnd(annotationClass);
|
|
|
|
doVisitEnd(annotationClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ClassNotFoundException ex) {
|
|
|
|
catch (ClassNotFoundException ex) {
|
|
|
|
this.logger.debug("Failed to classload type while reading annotation " +
|
|
|
|
this.logger.debug("Failed to class-load type while reading annotation metadata. " +
|
|
|
|
"metadata. This is a non-fatal error, but certain annotation " +
|
|
|
|
"This is a non-fatal error, but certain annotation metadata may be unavailable.", ex);
|
|
|
|
"metadata may be unavailable.", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -196,6 +191,9 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerDefaultValues(Class<?> annotationClass) {
|
|
|
|
private void registerDefaultValues(Class<?> annotationClass) {
|
|
|
|
|
|
|
|
// Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
|
|
|
|
|
|
|
|
// otherwise, and don't want to mess with accessibility in a SecurityManager environment.
|
|
|
|
|
|
|
|
if (Modifier.isPublic(annotationClass.getModifiers())) {
|
|
|
|
// Check declared default values of attributes in the annotation type.
|
|
|
|
// Check declared default values of attributes in the annotation type.
|
|
|
|
Method[] annotationAttributes = annotationClass.getMethods();
|
|
|
|
Method[] annotationAttributes = annotationClass.getMethods();
|
|
|
|
for (Method annotationAttribute : annotationAttributes) {
|
|
|
|
for (Method annotationAttribute : annotationAttributes) {
|
|
|
|
@@ -220,6 +218,7 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@@ -267,19 +266,23 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
|
|
|
|
Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
|
|
|
|
for (Annotation metaAnnotation : annotationClass.getAnnotations()) {
|
|
|
|
for (Annotation metaAnnotation : annotationClass.getAnnotations()) {
|
|
|
|
recusivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
|
|
|
|
recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.metaAnnotationMap != null) {
|
|
|
|
if (this.metaAnnotationMap != null) {
|
|
|
|
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
|
|
|
|
this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void recusivelyCollectMetaAnnotations(Set<String> visited, Annotation annotation) {
|
|
|
|
private void recursivelyCollectMetaAnnotations(Set<String> visited, Annotation annotation) {
|
|
|
|
if (visited.add(annotation.annotationType().getName())) {
|
|
|
|
if (visited.add(annotation.annotationType().getName())) {
|
|
|
|
|
|
|
|
// Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
|
|
|
|
|
|
|
|
// otherwise, and don't want to mess with accessibility in a SecurityManager environment.
|
|
|
|
|
|
|
|
if (Modifier.isPublic(annotation.annotationType().getModifiers())) {
|
|
|
|
this.attributesMap.add(annotation.annotationType().getName(),
|
|
|
|
this.attributesMap.add(annotation.annotationType().getName(),
|
|
|
|
AnnotationUtils.getAnnotationAttributes(annotation, true, true));
|
|
|
|
AnnotationUtils.getAnnotationAttributes(annotation, true, true));
|
|
|
|
for (Annotation metaMetaAnnotation : annotation.annotationType().getAnnotations()) {
|
|
|
|
for (Annotation metaMetaAnnotation : annotation.annotationType().getAnnotations()) {
|
|
|
|
recusivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
|
|
|
|
recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|