summaryrefslogtreecommitdiffstats
path: root/weaver5/java5-src/org/aspectj/weaver/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'weaver5/java5-src/org/aspectj/weaver/reflect')
-rw-r--r--weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java71
-rw-r--r--weaver5/java5-src/org/aspectj/weaver/reflect/ReflectiveAnnotationAJ.java103
2 files changed, 172 insertions, 2 deletions
diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
index a978d9605..5de589f15 100644
--- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
+++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
@@ -26,6 +26,7 @@ import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.LocalVariable;
import org.aspectj.apache.bcel.classfile.LocalVariableTable;
+import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
import org.aspectj.apache.bcel.util.NonCachingClassLoaderRepository;
import org.aspectj.apache.bcel.util.Repository;
import org.aspectj.weaver.AnnotationAJ;
@@ -321,8 +322,7 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder {
// 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.
+ // don't hog memory.
try {
JavaClass jc = bcelRepository.loadClass(onMember.getDeclaringClass());
org.aspectj.apache.bcel.classfile.annotation.AnnotationGen[][] anns = null;
@@ -386,5 +386,72 @@ public class Java15AnnotationFinder implements AnnotationFinder, ArgNameFinder {
}
return result;
}
+
+ public Object getParamAnnotation(Member onMember, int argsIndex, int paramAnnoIndex) {
+ if (!(onMember instanceof AccessibleObject))
+ return null;
+ // 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.AnnotationGen[][] anns = null;
+// if (onMember instanceof Method) {
+// org.aspectj.apache.bcel.classfile.Method bcelMethod = jc.getMethod((Method) onMember);
+// if (bcelMethod == null) {
+// // pr220430
+// // System.err.println(
+// // "Unexpected problem in Java15AnnotationFinder: cannot retrieve annotations on method '"
+// // + onMember.getName()+"' in class '"+jc.getClassName()+"'");
+// } else {
+// 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 null;
+//
+// if (argsIndex>=anns.length) {
+// return null;
+// }
+// AnnotationGen[] parameterAnnotationsOnParticularArg = anns[argsIndex];
+// if (parameterAnnotationsOnParticularArg==null || paramAnnoIndex>=parameterAnnotationsOnParticularArg.length) {
+// return null;
+// }
+// AnnotationGen parameterAnnotation = parameterAnnotationsOnParticularArg[paramAnnoIndex];
+//// if (parameterAnnotation.getTypeSignature().equals(ofType.getSignature())) {
+// return new BcelAnnotation(parameterAnnotation, world);
+//// } else {
+//// return null;
+//// }
+// } 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 || argsIndex>=anns.length) {
+ return null;
+ }
+ Annotation[] parameterAnnotationsOnParticularArg = anns[argsIndex];
+ if (parameterAnnotationsOnParticularArg==null || paramAnnoIndex>=parameterAnnotationsOnParticularArg.length) {
+ return null;
+ }
+ return parameterAnnotationsOnParticularArg[paramAnnoIndex];
+ }
}
diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/ReflectiveAnnotationAJ.java b/weaver5/java5-src/org/aspectj/weaver/reflect/ReflectiveAnnotationAJ.java
new file mode 100644
index 000000000..0b486b7ed
--- /dev/null
+++ b/weaver5/java5-src/org/aspectj/weaver/reflect/ReflectiveAnnotationAJ.java
@@ -0,0 +1,103 @@
+/* *******************************************************************
+ * Copyright (c) 2016 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement Initial implementation
+ * ******************************************************************/
+package org.aspectj.weaver.reflect;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import org.aspectj.weaver.AnnotationAJ;
+import org.aspectj.weaver.ResolvedType;
+
+/**
+ * An AnnotationAJ that wraps a java.lang.reflect Annotation.
+ *
+ * @author Andy Clement
+ */
+public class ReflectiveAnnotationAJ implements AnnotationAJ {
+
+ private Annotation anno;
+
+ public ReflectiveAnnotationAJ(Annotation anno) {
+ this.anno = anno;
+ }
+
+ public String getTypeSignature() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getTypeName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ResolvedType getType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean allowedOnAnnotationType() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean allowedOnField() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean allowedOnRegularType() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public Set<String> getTargets() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasNamedValue(String name) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean hasNameValuePair(String name, String value) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getValidTargets() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String stringify() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean specifiesTarget() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isRuntimeVisible() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getStringFormOfValue(String name) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}