import java.util.Iterator;
import java.util.List;
+import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair;
+
/**
* This type represents the weavers abstraction of an annotation - it is
* not tied to any underlying BCI toolkit. The weaver actualy handles these
sb.append("]");
return sb.toString();
}
+
+ public boolean hasNamedValue(String n) {
+ if (nvPairs==null) return false;
+ for (int i=0;i<nvPairs.size();i++) {
+ AnnotationNameValuePair pair = (AnnotationNameValuePair)nvPairs.get(i);
+ if (pair.getName().equals(n)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return true if the annotation has a value with the specified name (n) and value (v)
+ */
+ public boolean hasNameValuePair(String n, String v) {
+ if (nvPairs==null) return false;
+ for (int i=0;i<nvPairs.size();i++) {
+ AnnotationNameValuePair pair = (AnnotationNameValuePair)nvPairs.get(i);
+ if (pair.getName().equals(n)) {
+ if (pair.getValue().stringify().equals(v)) return true;
+ }
+ }
+ return false;
+ }
}
/**
* AnnotationX instances are holders for an annotation from either Bcel or
- * ASM. We have this holder so that types about the bcel weaver package
+ * eclipse. We have this holder so that types about the bcel weaver package
* can work with something not bytecode toolkit specific.
*/
public class AnnotationX {
public static final AnnotationX[] NONE = new AnnotationX[0];
private Annotation theRealBcelAnnotation;
- private AnnotationAJ theRealASMAnnotation;
+ private AnnotationAJ theRealEclipseAnnotation;
private int mode = -1;
- private final static int MODE_ASM = 1;
+ private final static int MODE_ECLIPSE = 1;
private final static int MODE_BCEL = 2;
private ResolvedType signature = null;
}
public AnnotationX(AnnotationAJ a,World world) {
- theRealASMAnnotation = a;
- signature = UnresolvedType.forSignature(theRealASMAnnotation.getTypeSignature()).resolve(world);
- mode= MODE_ASM;
+ theRealEclipseAnnotation = a;
+ signature = UnresolvedType.forSignature(theRealEclipseAnnotation.getTypeSignature()).resolve(world);
+ mode= MODE_ECLIPSE;
}
public Annotation getBcelAnnotation() {
public String toString() {
if (mode==MODE_BCEL) return theRealBcelAnnotation.toString();
- else return theRealASMAnnotation.toString();
+ else return theRealEclipseAnnotation.toString();
}
public String getTypeName() {
if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeName();
- else return Utility.signatureToString(theRealASMAnnotation.getTypeSignature());
+ else return Utility.signatureToString(theRealEclipseAnnotation.getTypeSignature());
}
public String getTypeSignature() {
if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeSignature();
- else return theRealASMAnnotation.getTypeSignature();
+ else return theRealEclipseAnnotation.getTypeSignature();
}
supportedTargets.add(ev.getEnumValueString());
}
} else {
- List values = theRealASMAnnotation.getNameValuePairs();
+ List values = theRealEclipseAnnotation.getNameValuePairs();
AnnotationNameValuePair nvp = (AnnotationNameValuePair)values.get(0);
ArrayAnnotationValue aav = (ArrayAnnotationValue)nvp.getValue();
AnnotationValue[] avs = aav.getValues();
public void print(StringBuffer sb) {
if (mode==MODE_BCEL) sb.append(theRealBcelAnnotation.toString());
- else sb.append(theRealASMAnnotation.stringify());
+ else sb.append(theRealEclipseAnnotation.stringify());
}
public boolean hasNameValuePair(String n, String v) {
if (mode==MODE_BCEL) return theRealBcelAnnotation.hasNameValuePair(n,v);
- else throw new RuntimeException("Cannot be anything else");
+ else return theRealEclipseAnnotation.hasNameValuePair(n,v);
}
public boolean hasNamedValue(String n) {
if (mode==MODE_BCEL) return theRealBcelAnnotation.hasNamedValue(n);
- else throw new RuntimeException("Cannot be anything else");
+ else return theRealEclipseAnnotation.hasNamedValue(n);
}
}
\ No newline at end of file