--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+package org.aspectj.weaver;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This type represents the weavers abstraction of an annotation - it is
+ * not tied to any underlying BCI toolkit. The weaver actualy handles these
+ * through AnnotationX wrapper objects - until we start transforming the
+ * BCEL annotations into this form (expensive) or offer a clever
+ * visitor mechanism over the BCEL annotation stuff that builds these
+ * annotation types directly.
+ *
+ * @author AndyClement
+ */
+public class AnnotationAJ {
+
+ private String type;
+ private boolean isRuntimeVisible;
+
+ private List /*of AnnotationNVPair*/ nvPairs = null;
+
+ public AnnotationAJ(String type,boolean isRuntimeVisible) {
+ this.type = type;
+ this.isRuntimeVisible = isRuntimeVisible;
+ }
+
+ public String getTypeSignature() {
+ return type;
+ }
+
+ public List getNameValuePairs() {
+ return nvPairs;
+ }
+
+ public boolean hasNameValuePairs() {
+ return nvPairs!=null && nvPairs.size()!=0;
+ }
+
+ public boolean isRuntimeVisible() {
+ return isRuntimeVisible;
+ }
+
+ public String stringify() {
+ return "xxxxxxxxxxx";
+ }
+
+ public String getStringValueOf(Object name) {
+ if (!hasNameValuePairs()) return null;
+ for (Iterator iter = nvPairs.iterator(); iter.hasNext();) {
+ AnnotationNameValuePair nvpair = (AnnotationNameValuePair) iter.next();
+ if (nvpair.getName().equals(name)) return nvpair.getValue().stringify();
+ }
+ return null;
+ }
+
+ public void addNameValuePair(AnnotationNameValuePair pair) {
+ if (nvPairs==null) nvPairs=new ArrayList();
+ nvPairs.add(pair);
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("ANNOTATION ["+getTypeSignature()+"] ["+
+ (isRuntimeVisible?"runtimeVisible":"runtimeInvisible")+"] [");
+ if (nvPairs!=null) {
+ for (Iterator iter = nvPairs.iterator(); iter.hasNext();) {
+ AnnotationNameValuePair element = (AnnotationNameValuePair) iter.next();
+ sb.append(element.toString());
+ if (iter.hasNext()) sb.append(",");
+ }
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+public class AnnotationAnnotationValue extends AnnotationValue {
+
+ private AnnotationAJ value;
+
+ public AnnotationAnnotationValue(AnnotationAJ value) {
+ super(AnnotationValue.ANNOTATION);
+ this.value = value;
+ }
+
+ public AnnotationAJ getAnnotation() {
+ return value;
+ }
+
+ public String stringify() {
+ return value.stringify();
+ }
+
+ public String toString() {
+ return value.toString();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+public class AnnotationNameValuePair {
+
+ private String name;
+
+ private AnnotationValue val;
+
+ public AnnotationNameValuePair(String name,AnnotationValue val) {
+ this.name = name;
+ this.val = val;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public AnnotationValue getValue() {
+ return val;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(name+"="+val.toString());
+ return sb.toString();
+ }
+}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+
+public abstract class AnnotationValue {
+
+ protected int valueKind;
+
+ public static final int STRING = 's';
+ public static final int ENUM_CONSTANT = 'e';
+ public static final int CLASS = 'c';
+ public static final int ANNOTATION = '@';
+ public static final int ARRAY = '[';
+
+ public static final int PRIMITIVE_INT = 'I';
+ public static final int PRIMITIVE_BYTE = 'B';
+ public static final int PRIMITIVE_CHAR = 'C';
+ public static final int PRIMITIVE_DOUBLE = 'D';
+ public static final int PRIMITIVE_FLOAT = 'F';
+ public static final int PRIMITIVE_LONG = 'J';
+ public static final int PRIMITIVE_SHORT = 'S';
+ public static final int PRIMITIVE_BOOLEAN= 'Z';
+
+ public abstract String stringify();
+
+ public AnnotationValue(int kind) {
+ valueKind = kind;
+ }
+
+ public static String whatKindIsThis(int kind) {
+ switch (kind) {
+ case PRIMITIVE_BYTE: // byte
+ return "byte";
+ case PRIMITIVE_CHAR: // char
+ return "char";
+ case PRIMITIVE_DOUBLE: // double
+ return "double";
+ case PRIMITIVE_FLOAT: // float
+ return "float";
+ case PRIMITIVE_INT: // int
+ return "int";
+ case PRIMITIVE_LONG: // long
+ return "long";
+ case PRIMITIVE_SHORT: // short
+ return "short";
+ case PRIMITIVE_BOOLEAN: // boolean
+ return "boolean";
+ case 's': // String
+ return "string";
+ case 'e': // Enum constant
+ return "enum";
+ case 'c': // Class
+ return "class";
+ case '@': // Annotation
+ return "annotation";
+ case '[': // Array
+ return "array";
+ default:
+ throw new RuntimeException("Dont know what this is : "+kind);
+ }
+ }
+}
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.apache.bcel.classfile.Utility;
/**
- * An AnnotationX is the 'holder' for a BCEL annotation - we have this holder
- * so that types about the bcel weaver package can work with something not
- * BCEL specific.
+ * AnnotationX instances are holders for an annotation from either Bcel or
+ * ASM. We have this holder so that types about the bcel weaver package
+ * can work with something not bytecode toolkit specific.
*/
public class AnnotationX {
- private Annotation theRealAnnotation;
+ public static final AnnotationX[] NONE = new AnnotationX[0];
+
+ private Annotation theRealBcelAnnotation;
+ private AnnotationAJ theRealASMAnnotation;
+ private int mode = -1;
+ private final static int MODE_ASM = 1;
+ private final static int MODE_BCEL = 2;
+
private ResolvedType signature = null;
// @target meta-annotation related stuff, built lazily
private Set supportedTargets = null;
public AnnotationX(Annotation a,World world) {
- theRealAnnotation = a;
- signature = UnresolvedType.forSignature(theRealAnnotation.getTypeSignature()).resolve(world);
+ theRealBcelAnnotation = a;
+ signature = UnresolvedType.forSignature(theRealBcelAnnotation.getTypeSignature()).resolve(world);
+ mode = MODE_BCEL;
+ }
+
+ public AnnotationX(AnnotationAJ a,World world) {
+ theRealASMAnnotation = a;
+ signature = UnresolvedType.forSignature(theRealASMAnnotation.getTypeSignature()).resolve(world);
+ mode= MODE_ASM;
}
public Annotation getBcelAnnotation() {
- return theRealAnnotation;
+ return theRealBcelAnnotation;
}
public UnresolvedType getSignature() {
}
public String toString() {
- return theRealAnnotation.toString();
+ if (mode==MODE_BCEL) return theRealBcelAnnotation.toString();
+ else return theRealASMAnnotation.toString();
}
public String getTypeName() {
- return theRealAnnotation.getTypeName();
+ if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeName();
+ else return Utility.signatureToString(theRealASMAnnotation.getTypeSignature());
}
public String getTypeSignature() {
- return theRealAnnotation.getTypeSignature();
+ if (mode==MODE_BCEL) return theRealBcelAnnotation.getTypeSignature();
+ else return theRealASMAnnotation.getTypeSignature();
}
* return true if this annotation can target an annotation type
*/
public boolean allowedOnAnnotationType() {
- ensureAtTargetInitialized();
- if (atTargetAnnotation == null) return true; // if no target specified, then return true
- return supportedTargets.contains("ANNOTATION_TYPE");
+ ensureAtTargetInitialized();
+ if (atTargetAnnotation == null) return true; // if no target specified, then return true
+ return supportedTargets.contains("ANNOTATION_TYPE");
}
/**
}
public boolean isRuntimeVisible() {
- return theRealAnnotation.isRuntimeVisible();
+ return theRealBcelAnnotation.isRuntimeVisible();
}
}
\ No newline at end of file
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+public class ArrayAnnotationValue extends AnnotationValue {
+
+ private AnnotationValue[] values;
+
+ public ArrayAnnotationValue() {
+ super(AnnotationValue.ARRAY);
+ }
+
+ public void setValues(AnnotationValue[] values) {
+ this.values = values;
+ }
+
+ public ArrayAnnotationValue(AnnotationValue[] values) {
+ super(AnnotationValue.ARRAY);
+ this.values = values;
+ }
+
+ public AnnotationValue[] getValues() {
+ return values;
+ }
+
+ public String stringify() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[");
+ for (int i = 0; i < values.length; i++) {
+ sb.append(values[i].stringify());
+ if (i+1<values.length) sb.append(",");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("{");
+ for (int i = 0; i < values.length; i++) {
+ sb.append(values[i].toString());
+ if ((i+1)<values.length) sb.append(",");
+ }
+ sb.append("}");
+ return sb.toString();
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+public class ClassAnnotationValue extends AnnotationValue {
+
+ private String signature;
+
+ public ClassAnnotationValue(String sig) {
+ super(AnnotationValue.CLASS);
+ this.signature = sig;
+ }
+
+ public String stringify() {
+ return signature;
+ }
+
+ public String toString() {
+ return signature;
+ }
+
+}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2006 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement IBM initial implementation
+ * ******************************************************************/
+ package org.aspectj.weaver;
+
+public class EnumAnnotationValue extends AnnotationValue {
+
+ private String type;
+ private String value;
+
+ public EnumAnnotationValue(String type,String value) {
+ super(AnnotationValue.ENUM_CONSTANT);
+ this.type = type;
+ this.value = value;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String stringify() {
+ return value;
+ }
+
+ public String toString() {
+ return value;
+ }
+
+}