]> source.dussan.org Git - aspectj.git/commitdiff
annoValMatch: implementation
authoraclement <aclement>
Mon, 25 Feb 2008 21:41:57 +0000 (21:41 +0000)
committeraclement <aclement>
Mon, 25 Feb 2008 21:41:57 +0000 (21:41 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelMethod.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java

index 7aa623b20b175e799d2e44bc3a91549ed37c3963..771245cef2f4dc18cd1e19763bcbcd7394e19cea 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import org.aspectj.apache.bcel.classfile.AnnotationDefault;
 import org.aspectj.apache.bcel.classfile.Attribute;
 import org.aspectj.apache.bcel.classfile.ExceptionTable;
 import org.aspectj.apache.bcel.classfile.GenericSignatureParser;
@@ -221,6 +222,18 @@ public final class BcelMethod extends ResolvedMemberImpl {
                return null;
        }
        
+       public String getAnnotationDefaultValue() {
+               Attribute[] attrs = method.getAttributes();
+               for (int i = 0; i < attrs.length; i++) {
+                       Attribute attribute = attrs[i];                 
+                       if (attribute.getName().equals("AnnotationDefault")) {
+                               AnnotationDefault def = (AnnotationDefault)attribute;
+                               return def.getElementValue().stringifyValue();
+                       }
+               }
+               return null;
+       }
+       
        // for testing - use with the method above
        public String[] getAttributeNames(boolean onlyIncludeAjOnes) {
                Attribute[] as = method.getAttributes();
@@ -287,7 +300,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
        }
        
        public boolean hasAnnotation(UnresolvedType ofType) {
-               ensureAnnotationTypesRetrieved();
+               ensureAnnotationsRetrieved();
                for (Iterator iter = annotationTypes.iterator(); iter.hasNext();) {
                        ResolvedType aType = (ResolvedType) iter.next();
                        if (aType.equals(ofType)) return true;          
@@ -296,19 +309,28 @@ public final class BcelMethod extends ResolvedMemberImpl {
        }
        
        public AnnotationX[] getAnnotations() {
-               ensureAnnotationTypesRetrieved();
+               ensureAnnotationsRetrieved();
                return annotations;
        }
        
         public ResolvedType[] getAnnotationTypes() {
-           ensureAnnotationTypesRetrieved();
+           ensureAnnotationsRetrieved();
            ResolvedType[] ret = new ResolvedType[annotationTypes.size()];
            annotationTypes.toArray(ret);
            return ret;
      }
         
+
+        public AnnotationX getAnnotationOfType(UnresolvedType ofType) {
+                ensureAnnotationsRetrieved();
+                for (int i=0; i<annotations.length; i++) {
+                        if (annotations[i].getTypeName().equals(ofType.getName())) return annotations[i];
+                }
+                return null;
+        }
+        
         public void addAnnotation(AnnotationX annotation) {
-           ensureAnnotationTypesRetrieved();   
+           ensureAnnotationsRetrieved();       
                // Add it to the set of annotations
                int len = annotations.length;
                AnnotationX[] ret = new AnnotationX[len+1];
@@ -323,7 +345,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
                method.addAnnotation(annotation.getBcelAnnotation());
         }
         
-        private void ensureAnnotationTypesRetrieved() {
+        private void ensureAnnotationsRetrieved() {
                if (method == null) return; // must be ok, we have evicted it
                if (annotationTypes == null || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us!
                Annotation annos[] = method.getAnnotations();
@@ -474,7 +496,7 @@ public final class BcelMethod extends ResolvedMemberImpl {
                 if (method != null) {
                         unpackGenericSignature();
                         unpackJavaAttributes();
-                        ensureAnnotationTypesRetrieved();
+                        ensureAnnotationsRetrieved();
                         ensureParameterAnnotationsRetrieved();
                         determineParameterNames();
 //                      this.sourceContext = SourceContextImpl.UNKNOWN_SOURCE_CONTEXT;
index 6943339679ca1895042d91c7bfc6340a47a6c601..8c710422d2eb55c56d1a1746052be2246dc066d0 100644 (file)
@@ -30,6 +30,7 @@ import org.aspectj.apache.bcel.classfile.annotation.Annotation;
 import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue;
 import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
 import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
+import org.aspectj.apache.bcel.classfile.annotation.EnumElementValue;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.weaver.AbstractReferenceTypeDelegate;
 import org.aspectj.weaver.AjAttribute;
@@ -567,8 +568,8 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                List values = ax.getBcelAnnotation().getValues();
                                for (Iterator it = values.iterator(); it.hasNext();) {
                                ElementNameValuePair element = (ElementNameValuePair) it.next();
-                               ElementValue v = element.getValue();
-                               retentionPolicy = v.stringifyValue();
+                               EnumElementValue v = (EnumElementValue)element.getValue();
+                               retentionPolicy = v.getEnumValueString();
                                return retentionPolicy;
                            }
                                        }
@@ -603,7 +604,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                        ElementValue[] evs = arrayValue.getElementValuesArray();
                        if (evs!=null) {
                                for (int j = 0; j < evs.length; j++) {
-                                                       String targetKind = evs[j].stringifyValue();
+                                                       String targetKind = ((EnumElementValue)evs[j]).getEnumValueString();
                                                        if (targetKind.equals("ANNOTATION_TYPE")) {       targetKinds.add(AnnotationTargetKind.ANNOTATION_TYPE);
                                                        } else if (targetKind.equals("CONSTRUCTOR")) {    targetKinds.add(AnnotationTargetKind.CONSTRUCTOR);
                                                        } else if (targetKind.equals("FIELD")) {          targetKinds.add(AnnotationTargetKind.FIELD);