aboutsummaryrefslogtreecommitdiffstats
path: root/weaver5
diff options
context:
space:
mode:
authoraclement <aclement>2008-01-25 19:08:24 +0000
committeraclement <aclement>2008-01-25 19:08:24 +0000
commit7026369f6087de42b881509b7637b25ea9681871 (patch)
treee5542330b9675a6706611092d2100c8c5bc1191f /weaver5
parent9e0bc9339fbdf019947ec8d51d74e39260a30e8d (diff)
downloadaspectj-7026369f6087de42b881509b7637b25ea9681871.tar.gz
aspectj-7026369f6087de42b881509b7637b25ea9681871.zip
paramannos: aware of parameter annotation matching
Diffstat (limited to 'weaver5')
-rw-r--r--weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java61
1 files changed, 60 insertions, 1 deletions
diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
index 12d211591..e87a89c43 100644
--- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
+++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
@@ -26,7 +26,6 @@ import org.aspectj.apache.bcel.classfile.LocalVariable;
import org.aspectj.apache.bcel.classfile.LocalVariableTable;
import org.aspectj.apache.bcel.util.NonCachingClassLoaderRepository;
import org.aspectj.apache.bcel.util.Repository;
-import org.aspectj.apache.bcel.util.ClassLoaderRepository;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
@@ -201,4 +200,64 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder {
}
return ret;
}
+ public static final ResolvedType[][] NO_PARAMETER_ANNOTATIONS = new ResolvedType[][]{};
+
+ public ResolvedType[][] getParameterAnnotationTypes(Member onMember) {
+ if (!(onMember instanceof AccessibleObject)) return NO_PARAMETER_ANNOTATIONS;
+ // here we really want both the runtime visible AND the class visible annotations
+ // so we bail out to Bcel and then chuck away the JavaClass so that we don't hog
+ // memory.
+ try {
+ JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
+ org.aspectj.apache.bcel.classfile.annotation.Annotation[][] anns = null;
+ if (onMember instanceof Method) {
+ org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method)onMember);
+ anns = bcelMethod.getParameterAnnotations();
+ } else if (onMember instanceof Constructor) {
+ org.aspectj.apache.bcel.classfile.Method bcelCons = jc.getMethod((Constructor)onMember);
+ anns = bcelCons.getParameterAnnotations();
+ } else if (onMember instanceof Field) {
+ anns = null;
+ }
+ // the answer is cached and we don't want to hold on to memory
+ bcelRepository.clear();
+ if (anns == null) return NO_PARAMETER_ANNOTATIONS;
+ ResolvedType[][] result = new ResolvedType[anns.length][];
+ // CACHING??
+ for (int i=0;i<anns.length;i++) {
+ 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()));
+ }
+ }
+ }
+ return result;
+ } catch (ClassNotFoundException cnfEx) {
+ // just use reflection then
+ }
+
+ // reflection...
+ AccessibleObject ao = (AccessibleObject) onMember;
+ Annotation[][] anns = null;
+ if (onMember instanceof Method) {
+ anns = ((Method)ao).getParameterAnnotations();
+ } else if (onMember instanceof Constructor) {
+ anns = ((Constructor)ao).getParameterAnnotations();
+ } else if (onMember instanceof Field) {
+ anns = null;
+ }
+ if (anns == null) return NO_PARAMETER_ANNOTATIONS;
+ ResolvedType[][] result = new ResolvedType[anns.length][];
+ // CACHING??
+ for (int i=0;i<anns.length;i++) {
+ 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);
+ }
+ }
+ }
+ return result;
+ }
}