]> source.dussan.org Git - aspectj.git/commitdiff
annoValMatch: able to ask annotation about its values and their settings
authoraclement <aclement>
Mon, 25 Feb 2008 21:26:01 +0000 (21:26 +0000)
committeraclement <aclement>
Mon, 25 Feb 2008 21:26:01 +0000 (21:26 +0000)
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java

index 4b609fd0686ca17acdc8978b3b4b6ce4d1458d51..ac81ec8051326b531b6f7e9d397f46feb2231388 100644 (file)
@@ -30,6 +30,7 @@ import org.aspectj.apache.bcel.classfile.Utility;
  */
 public class Annotation {
        private int typeIndex;
+       // OPTIMIZE don't need a new list instance for every annotation instance!
        private List /* ElementNameValuePair */ evs = new ArrayList();
        private ConstantPool cpool;
        private boolean isRuntimeVisible;
@@ -127,4 +128,28 @@ public class Annotation {
                }
                return result.toString();
        }
+
+       /**
+     * Return true if the annotation has a value with the specified name (n) and value (v)
+     */
+       public boolean hasNameValuePair(String n, String v) {
+               for (int i=0;i<evs.size();i++) {
+                       ElementNameValuePair pair = (ElementNameValuePair)evs.get(i);
+                       if (pair.getNameString().equals(n)) {
+                               if (pair.getValue().stringifyValue().equals(v)) return true;
+                       }
+               }
+               return false;
+       }
+
+    /**
+     * Return true if the annotation has a value with the specified name (n)
+     */
+       public boolean hasNamedValue(String n) {
+               for (int i=0;i<evs.size();i++) {
+                       ElementNameValuePair pair = (ElementNameValuePair)evs.get(i);
+                       if (pair.getNameString().equals(n)) return true;
+               }
+               return false;
+       }
 }
index c08418cc88e1348d1eb007dfbad7605bf5fb827a..4960949e59e27f232886a75122e878f79a1815a5 100644 (file)
@@ -40,9 +40,16 @@ public class EnumElementValue extends ElementValue {
                dos.writeShort(valueIdx); // u2
     }
     
+    /**
+     * return signature and value, something like Lp/Color;RED
+     */
     public String stringifyValue() {
-       ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8);
-               return cu8.getBytes();
+       StringBuffer sb = new StringBuffer();
+       ConstantUtf8 cu8 = (ConstantUtf8)cpool.getConstant(typeIdx,Constants.CONSTANT_Utf8);
+       sb.append(cu8.getBytes());
+       cu8 = (ConstantUtf8)cpool.getConstant(valueIdx,Constants.CONSTANT_Utf8);
+       sb.append(cu8.getBytes());
+       return sb.toString();
     }
     
     public String getEnumTypeString() {