+ Updated all projects to use the re-introduced org.springframework.asm instead of org.objectweb.asm (.java, template.mf, ivy.xml, and .classpath files have been updated)

+ Finished support for @Import, including detection of circular imports
This commit is contained in:
Chris Beams
2009-03-21 19:00:57 +00:00
parent 9182cab52f
commit 3ae3de19a9
50 changed files with 1108 additions and 299 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,13 +29,12 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.EmptyVisitor;
import org.springframework.asm.ClassReader;
import org.springframework.asm.Label;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
import org.springframework.asm.Type;
import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.util.ClassUtils;
/**

View File

@@ -137,7 +137,7 @@ public abstract class AnnotationUtils {
return annotation;
}
}
Class superClass = clazz.getSuperclass();
Class<?> superClass = clazz.getSuperclass();
if (superClass == null || superClass == Object.class) {
return null;
}

View File

@@ -26,14 +26,13 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.EmptyVisitor;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Type;
import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.ReflectionUtils;
import org.springframework.core.type.MethodMetadata;
import org.springframework.util.ReflectionUtils;
/**
* ASM class visitor which looks for the class name and implemented types as
@@ -49,9 +48,9 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
private final Map<String, Map<String, Object>> attributesMap = new LinkedHashMap<String, Map<String, Object>>();
private final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<String, Set<String>>();
private final Set<MethodMetadata> methodMetadataSet = new LinkedHashSet<MethodMetadata>();
private final ClassLoader classLoader;
@@ -59,7 +58,7 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
this.classLoader = classLoader;
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
@@ -75,7 +74,6 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
final String className = Type.getType(desc).getClassName();
final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
final Map<String, Object> metaAttributes = new LinkedHashMap<String, Object>();
return new EmptyVisitor() {
@Override
public void visit(String name, Object value) {
@@ -95,7 +93,7 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
public void visitEnum(String name, String desc, String value) {
Object valueToUse = value;
try {
Class enumType = classLoader.loadClass(Type.getType(desc).getClassName());
Class<?> enumType = classLoader.loadClass(Type.getType(desc).getClassName());
Field enumConstant = ReflectionUtils.findField(enumType, value);
if (enumConstant != null) {
valueToUse = enumConstant.get(null);
@@ -109,7 +107,7 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
@Override
public void visitEnd() {
try {
Class annotationClass = classLoader.loadClass(className);
Class<?> annotationClass = classLoader.loadClass(className);
// Check declared default values of attributes in the annotation type.
Method[] annotationAttributes = annotationClass.getMethods();
for (Method annotationAttribute : annotationAttributes) {
@@ -123,7 +121,7 @@ class AnnotationMetadataReadingVisitor extends ClassMetadataReadingVisitor imple
Annotation[] metaAnnotations = annotationClass.getAnnotations();
Set<String> metaAnnotationTypeNames = new HashSet<String>();
for (Annotation metaAnnotation : metaAnnotations) {
metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
}
metaAnnotationMap.put(className, metaAnnotationTypeNames);
}

View File

@@ -25,7 +25,7 @@ import org.springframework.core.io.ResourceLoader;
/**
* Caching implementation of the {@link MetadataReaderFactory} interface,
* caching an ASM {@link org.objectweb.asm.ClassReader} per Spring Resource handle
* caching an ASM {@link org.springframework.asm.ClassReader} per Spring Resource handle
* (i.e. per ".class" file).
*
* @author Juergen Hoeller

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,9 @@
package org.springframework.core.type.classreading;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.EmptyVisitor;
import org.springframework.asm.ClassAdapter;
import org.springframework.asm.Opcodes;
import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.core.type.ClassMetadata;
import org.springframework.util.ClassUtils;

View File

@@ -21,7 +21,7 @@ import org.springframework.core.type.ClassMetadata;
/**
* Simple facade for accessing class metadata,
* as read by an ASM {@link org.objectweb.asm.ClassReader}.
* as read by an ASM {@link org.springframework.asm.ClassReader}.
*
* @author Juergen Hoeller
* @since 2.5

View File

@@ -1,139 +1,154 @@
package org.springframework.core.type.classreading;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.EmptyVisitor;
import org.springframework.core.type.MethodMetadata;
public class MethodMetadataReadingVisitor extends MethodAdapter implements MethodMetadata {
private final Map<String, Map<String, Object>> attributesMap = new LinkedHashMap<String, Map<String, Object>>();
private final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<String, Set<String>>();
private ClassLoader classLoader;
private String name;
private int access;
private boolean isStatic;
public MethodMetadataReadingVisitor(ClassLoader classLoader, String name, int access) {
super(new EmptyVisitor());
this.classLoader = classLoader;
this.name = name;
this.access = access;
this.isStatic = ((access & Opcodes.ACC_STATIC) != 0);
}
public Map<String, Object> getAnnotationAttributes(String annotationType) {
return this.attributesMap.get(annotationType);
}
public Set<String> getAnnotationTypes() {
return this.attributesMap.keySet();
}
public String getMethodName() {
return name;
}
public int getModifiers() {
return access;
}
public boolean hasAnnotation(String annotationType) {
return this.attributesMap.containsKey(annotationType);
}
public Set<String> getMetaAnnotationTypes(String annotationType) {
return this.metaAnnotationMap.get(annotationType);
}
public boolean hasMetaAnnotation(String metaAnnotationType) {
Collection<Set<String>> allMetaTypes = this.metaAnnotationMap.values();
for (Set<String> metaTypes : allMetaTypes) {
if (metaTypes.contains(metaAnnotationType)) {
return true;
}
}
return false;
}
public boolean isStatic() {
return isStatic;
}
public Set<String> getAnnotationTypesWithMetaAnnotation(String metaAnnotationType) {
///metaAnnotationMap.put(className, metaAnnotationTypeNames);
Set<String> annotationTypes = new LinkedHashSet<String>();
Set< Map.Entry<String, Set<String>> > metaValues = metaAnnotationMap.entrySet();
Iterator<Map.Entry<String, Set<String>> > metaIterator = metaValues.iterator();
while (metaIterator.hasNext())
{
Map.Entry<String, Set<String>> entry = metaIterator.next();
String attributeType = entry.getKey();
Set<String> metaAttributes = entry.getValue();
if (metaAttributes.contains(metaAnnotationType))
{
annotationTypes.add(attributeType);
}
}
return annotationTypes;
}
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
final String className = Type.getType(desc).getClassName();
final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
return new EmptyVisitor() {
@Override
public void visit(String name, Object value) {
// Explicitly defined annotation attribute value.
attributes.put(name, value);
}
@Override
public void visitEnd() {
try {
Class annotationClass = classLoader.loadClass(className);
// Check declared default values of attributes in the annotation type.
Method[] annotationAttributes = annotationClass.getMethods();
for (int i = 0; i < annotationAttributes.length; i++) {
Method annotationAttribute = annotationAttributes[i];
String attributeName = annotationAttribute.getName();
Object defaultValue = annotationAttribute.getDefaultValue();
if (defaultValue != null && !attributes.containsKey(attributeName)) {
attributes.put(attributeName, defaultValue);
}
}
// Register annotations that the annotation type is annotated with.
Annotation[] metaAnnotations = annotationClass.getAnnotations();
Set<String> metaAnnotationTypeNames = new HashSet<String>();
for (Annotation metaAnnotation : metaAnnotations) {
metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
}
metaAnnotationMap.put(className, metaAnnotationTypeNames);
}
catch (ClassNotFoundException ex) {
// Class not found
}
attributesMap.put(className, attributes);
}
};
}
}
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.type.classreading;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.MethodAdapter;
import org.springframework.asm.Opcodes;
import org.springframework.asm.Type;
import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.core.type.MethodMetadata;
public class MethodMetadataReadingVisitor extends MethodAdapter implements MethodMetadata {
private final Map<String, Map<String, Object>> attributesMap = new LinkedHashMap<String, Map<String, Object>>();
private final Map<String, Set<String>> metaAnnotationMap = new LinkedHashMap<String, Set<String>>();
private ClassLoader classLoader;
private String name;
private int access;
private boolean isStatic;
public MethodMetadataReadingVisitor(ClassLoader classLoader, String name, int access) {
super(new EmptyVisitor());
this.classLoader = classLoader;
this.name = name;
this.access = access;
this.isStatic = ((access & Opcodes.ACC_STATIC) != 0);
}
public Map<String, Object> getAnnotationAttributes(String annotationType) {
return this.attributesMap.get(annotationType);
}
public Set<String> getAnnotationTypes() {
return this.attributesMap.keySet();
}
public String getMethodName() {
return name;
}
public int getModifiers() {
return access;
}
public boolean hasAnnotation(String annotationType) {
return this.attributesMap.containsKey(annotationType);
}
public Set<String> getMetaAnnotationTypes(String annotationType) {
return this.metaAnnotationMap.get(annotationType);
}
public boolean hasMetaAnnotation(String metaAnnotationType) {
Collection<Set<String>> allMetaTypes = this.metaAnnotationMap.values();
for (Set<String> metaTypes : allMetaTypes) {
if (metaTypes.contains(metaAnnotationType)) {
return true;
}
}
return false;
}
public boolean isStatic() {
return isStatic;
}
public Set<String> getAnnotationTypesWithMetaAnnotation(String metaAnnotationType) {
///metaAnnotationMap.put(className, metaAnnotationTypeNames);
Set<String> annotationTypes = new LinkedHashSet<String>();
Set< Map.Entry<String, Set<String>> > metaValues = metaAnnotationMap.entrySet();
Iterator<Map.Entry<String, Set<String>> > metaIterator = metaValues.iterator();
while (metaIterator.hasNext())
{
Map.Entry<String, Set<String>> entry = metaIterator.next();
String attributeType = entry.getKey();
Set<String> metaAttributes = entry.getValue();
if (metaAttributes.contains(metaAnnotationType))
{
annotationTypes.add(attributeType);
}
}
return annotationTypes;
}
@Override
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
final String className = Type.getType(desc).getClassName();
final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
return new EmptyVisitor() {
@Override
public void visit(String name, Object value) {
// Explicitly defined annotation attribute value.
attributes.put(name, value);
}
@Override
public void visitEnd() {
try {
Class<?> annotationClass = classLoader.loadClass(className);
// Check declared default values of attributes in the annotation type.
Method[] annotationAttributes = annotationClass.getMethods();
for (int i = 0; i < annotationAttributes.length; i++) {
Method annotationAttribute = annotationAttributes[i];
String attributeName = annotationAttribute.getName();
Object defaultValue = annotationAttribute.getDefaultValue();
if (defaultValue != null && !attributes.containsKey(attributeName)) {
attributes.put(attributeName, defaultValue);
}
}
// Register annotations that the annotation type is annotated with.
Annotation[] metaAnnotations = annotationClass.getAnnotations();
Set<String> metaAnnotationTypeNames = new HashSet<String>();
for (Annotation metaAnnotation : metaAnnotations) {
metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
}
metaAnnotationMap.put(className, metaAnnotationTypeNames);
}
catch (ClassNotFoundException ex) {
// Class not found
}
attributesMap.put(className, attributes);
}
};
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,13 @@
package org.springframework.core.type.classreading;
import org.objectweb.asm.ClassReader;
import org.springframework.asm.ClassReader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
/**
* {@link MetadataReader} implementation based on an ASM
* {@link org.objectweb.asm.ClassReader}.
* {@link org.springframework.asm.ClassReader}.
*
* <p>Package-visible in order to allow for repackaging the ASM library
* without effect on users of the <code>core.type</code> package.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +19,7 @@ package org.springframework.core.type.classreading;
import java.io.IOException;
import java.io.InputStream;
import org.objectweb.asm.ClassReader;
import org.springframework.asm.ClassReader;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
@@ -28,7 +27,7 @@ import org.springframework.util.ClassUtils;
/**
* Simple implementation of the {@link MetadataReaderFactory} interface,
* creating a new ASM {@link org.objectweb.asm.ClassReader} for every request.
* creating a new ASM {@link org.springframework.asm.ClassReader} for every request.
*
* @author Juergen Hoeller
* @since 2.5

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Core support package for type introspection through ASM-based class reading.
*/
package org.springframework.core.type.classreading;

View File

@@ -1,7 +0,0 @@
<html>
<body>
Core support package for type introspection through ASM-based class reading.
</body>
</html>