import org.aspectj.weaver.AnnotationAJ;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
-import org.aspectj.weaver.WeakClassLoaderReference;
import org.aspectj.weaver.World;
import org.aspectj.weaver.bcel.BcelAnnotation;
+import org.aspectj.weaver.bcel.BcelWeakClassLoaderReference;
/**
* Find the given annotation (if present) on the given object
public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder {
private Repository bcelRepository;
- private WeakClassLoaderReference classLoaderRef;
+ private BcelWeakClassLoaderReference classLoaderRef;
private World world;
// must have no-arg constructor for reflective construction
// TODO: No easy way to ask the world factory for the right kind of
// repository so
// default to the safe one! (pr160674)
- this.classLoaderRef = new WeakClassLoaderReference(aLoader);
- this.bcelRepository = new NonCachingClassLoaderRepository(
- classLoaderRef);
+ this.classLoaderRef = new BcelWeakClassLoaderReference(aLoader);
+ this.bcelRepository = new NonCachingClassLoaderRepository(classLoaderRef);
}
public void setWorld(World aWorld) {
/*
* (non-Javadoc)
*
- * @see
- * org.aspectj.weaver.reflect.AnnotationFinder#getAnnotation(org.aspectj
- * .weaver.ResolvedType, java.lang.Object)
+ * @see org.aspectj.weaver.reflect.AnnotationFinder#getAnnotation(org.aspectj .weaver.ResolvedType, java.lang.Object)
*/
public Object getAnnotation(ResolvedType annotationType, Object onObject) {
try {
- Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class
- .forName(annotationType.getName(), false, getClassLoader());
+ Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(),
+ false, getClassLoader());
if (onObject.getClass().isAnnotationPresent(annotationClass)) {
return onObject.getClass().getAnnotation(annotationClass);
}
return null;
}
- public Object getAnnotationFromClass(ResolvedType annotationType,
- Class aClass) {
+ public Object getAnnotationFromClass(ResolvedType annotationType, Class aClass) {
try {
- Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class
- .forName(annotationType.getName(), false, getClassLoader());
+ Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) Class.forName(annotationType.getName(),
+ false, getClassLoader());
if (aClass.isAnnotationPresent(annotationClass)) {
return aClass.getAnnotation(annotationClass);
}
return null;
}
- public Object getAnnotationFromMember(ResolvedType annotationType,
- Member aMember) {
+ public Object getAnnotationFromMember(ResolvedType annotationType, Member aMember) {
if (!(aMember instanceof AccessibleObject))
return null;
AccessibleObject ao = (AccessibleObject) aMember;
try {
- Class annotationClass = Class.forName(annotationType.getName(),
- false, getClassLoader());
+ Class annotationClass = Class.forName(annotationType.getName(), false, getClassLoader());
if (ao.isAnnotationPresent(annotationClass)) {
return ao.getAnnotation(annotationClass);
}
return classLoaderRef.getClassLoader();
}
- public AnnotationAJ getAnnotationOfType(UnresolvedType ofType,
- Member onMember) {
+ public AnnotationAJ getAnnotationOfType(UnresolvedType ofType, Member onMember) {
if (!(onMember instanceof AccessibleObject))
return null;
// here we really want both the runtime visible AND the class visible
// don't hog
// memory.
try {
- JavaClass jc = bcelRepository.loadClass(onMember
- .getDeclaringClass());
+ JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[] anns = new org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[0];
if (onMember instanceof Method) {
- org.aspectj.apache.bcel.classfile.Method bcelMethod = jc
- .getMethod((Method) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) onMember);
if (bcelMethod == null) {
// pr220430
// System.err.println(
anns = bcelMethod.getAnnotations();
}
} else if (onMember instanceof Constructor) {
- org.aspectj.apache.bcel.classfile.Method bcelCons = jc
- .getMethod((Constructor) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelCons = jc.getMethod((Constructor) onMember);
anns = bcelCons.getAnnotations();
} else if (onMember instanceof Field) {
- org.aspectj.apache.bcel.classfile.Field bcelField = jc
- .getField((Field) onMember);
+ org.aspectj.apache.bcel.classfile.Field bcelField = jc.getField((Field) onMember);
anns = bcelField.getAnnotations();
}
// the answer is cached and we don't want to hold on to memory
public String getAnnotationDefaultValue(Member onMember) {
try {
- JavaClass jc = bcelRepository.loadClass(onMember
- .getDeclaringClass());
+ JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
if (onMember instanceof Method) {
- org.aspectj.apache.bcel.classfile.Method bcelMethod = jc
- .getMethod((Method) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) onMember);
if (bcelMethod == null) {
// pr220430
// don't hog
// memory.
try {
- JavaClass jc = bcelRepository.loadClass(onMember
- .getDeclaringClass());
+ JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[] anns = new org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[0];
if (onMember instanceof Method) {
- org.aspectj.apache.bcel.classfile.Method bcelMethod = jc
- .getMethod((Method) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) onMember);
if (bcelMethod == null) {
// fallback on reflection - see pr220430
// System.err.println(
anns = bcelMethod.getAnnotations();
}
} else if (onMember instanceof Constructor) {
- org.aspectj.apache.bcel.classfile.Method bcelCons = jc
- .getMethod((Constructor) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelCons = jc.getMethod((Constructor) onMember);
anns = bcelCons.getAnnotations();
} else if (onMember instanceof Field) {
- org.aspectj.apache.bcel.classfile.Field bcelField = jc
- .getField((Field) onMember);
+ org.aspectj.apache.bcel.classfile.Field bcelField = jc.getField((Field) onMember);
anns = bcelField.getAnnotations();
}
// the answer is cached and we don't want to hold on to memory
// convert to our Annotation type
Set<ResolvedType> annSet = new HashSet<ResolvedType>();
for (int i = 0; i < anns.length; i++) {
- annSet.add(world.resolve(UnresolvedType.forSignature(anns[i]
- .getTypeSignature())));
+ annSet.add(world.resolve(UnresolvedType.forSignature(anns[i].getTypeSignature())));
}
return annSet;
} catch (ClassNotFoundException cnfEx) {
Annotation[] anns = ao.getDeclaredAnnotations();
Set<UnresolvedType> annSet = new HashSet<UnresolvedType>();
for (int i = 0; i < anns.length; i++) {
- annSet.add(UnresolvedType.forName(
- anns[i].annotationType().getName()).resolve(world));
+ annSet.add(UnresolvedType.forName(anns[i].annotationType().getName()).resolve(world));
}
return annSet;
}
// memory.
try {
JavaClass jc = bcelRepository.loadClass(forClass);
- org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[] anns = jc
- .getAnnotations();
+ org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[] anns = jc.getAnnotations();
bcelRepository.clear();
if (anns == null)
return new ResolvedType[0];
ResolvedType[] ret = new ResolvedType[anns.length];
for (int i = 0; i < ret.length; i++) {
- ret[i] = inWorld.resolve(UnresolvedType.forSignature(anns[i]
- .getTypeSignature()));
+ ret[i] = inWorld.resolve(UnresolvedType.forSignature(anns[i].getTypeSignature()));
}
return ret;
} catch (ClassNotFoundException cnfEx) {
Annotation[] classAnnotations = forClass.getAnnotations();
ResolvedType[] ret = new ResolvedType[classAnnotations.length];
for (int i = 0; i < classAnnotations.length; i++) {
- ret[i] = inWorld.resolve(classAnnotations[i].annotationType()
- .getName());
+ ret[i] = inWorld.resolve(classAnnotations[i].annotationType().getName());
}
return ret;
return null;
try {
- JavaClass jc = bcelRepository.loadClass(forMember
- .getDeclaringClass());
+ JavaClass jc = bcelRepository.loadClass(forMember.getDeclaringClass());
LocalVariableTable lvt = null;
int numVars = 0;
if (forMember instanceof Method) {
- org.aspectj.apache.bcel.classfile.Method bcelMethod = jc
- .getMethod((Method) forMember);
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) forMember);
lvt = bcelMethod.getLocalVariableTable();
numVars = bcelMethod.getArgumentTypes().length;
} else if (forMember instanceof Constructor) {
- org.aspectj.apache.bcel.classfile.Method bcelCons = jc
- .getMethod((Constructor) forMember);
+ org.aspectj.apache.bcel.classfile.Method bcelCons = jc.getMethod((Constructor) forMember);
lvt = bcelCons.getLocalVariableTable();
numVars = bcelCons.getArgumentTypes().length;
}
return null;
}
- private String[] getParameterNamesFromLVT(LocalVariableTable lvt,
- int numVars) {
+ private String[] getParameterNamesFromLVT(LocalVariableTable lvt, int numVars) {
if (lvt == null)
return null;// pr222987 - prevent NPE
LocalVariable[] vars = lvt.getLocalVariableTable();
// don't hog
// memory.
try {
- JavaClass jc = bcelRepository.loadClass(onMember
- .getDeclaringClass());
+ JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[][] anns = null;
if (onMember instanceof Method) {
- org.aspectj.apache.bcel.classfile.Method bcelMethod = jc
- .getMethod((Method) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) onMember);
if (bcelMethod == null) {
// pr220430
// System.err.println(
anns = bcelMethod.getParameterAnnotations();
}
} else if (onMember instanceof Constructor) {
- org.aspectj.apache.bcel.classfile.Method bcelCons = jc
- .getMethod((Constructor) onMember);
+ org.aspectj.apache.bcel.classfile.Method bcelCons = jc.getMethod((Constructor) onMember);
anns = bcelCons.getParameterAnnotations();
} else if (onMember instanceof Field) {
// anns = null;
if (anns[i] != null) {
result[i] = new ResolvedType[anns[i].length];
for (int j = 0; j < anns[i].length; j++) {
- result[i][j] = world.resolve(UnresolvedType
- .forSignature(anns[i][j].getTypeSignature()));
+ result[i][j] = world.resolve(UnresolvedType.forSignature(anns[i][j].getTypeSignature()));
}
}
}
if (anns[i] != null) {
result[i] = new ResolvedType[anns[i].length];
for (int j = 0; j < anns[i].length; j++) {
- result[i][j] = UnresolvedType.forName(
- anns[i][j].annotationType().getName()).resolve(
- world);
+ result[i][j] = UnresolvedType.forName(anns[i][j].annotationType().getName()).resolve(world);
}
}
}