import java.io.IOException;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
+import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
/**
* This attribute is attached to a method and indicates the default
*/
public class AnnotationDefault extends Attribute {
- private ElementValueGen value;
+ private ElementValue value;
public AnnotationDefault(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException {
- this(nameIndex, len, ElementValueGen.readElementValue(dis,cpool), cpool);
+ this(nameIndex, len, ElementValue.readElementValue(dis,cpool), cpool);
}
- private AnnotationDefault(int nameIndex, int len, ElementValueGen value, ConstantPool cpool) {
+ private AnnotationDefault(int nameIndex, int len, ElementValue value, ConstantPool cpool) {
super(Constants.ATTR_ANNOTATION_DEFAULT, nameIndex, len, cpool);
this.value = value;
}
// return (EnclosingMethod)clone();
}
- public final ElementValueGen getElementValue() { return value; }
+ public final ElementValue getElementValue() { return value; }
public final void dump(DataOutputStream dos) throws IOException {
super.dump(dos);
import java.io.Serializable;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisParamAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisParamAnnos;
/**
* Abstract super class for <em>Attribute</em> objects. Currently the <em>ConstantValue</em>, <em>SourceFile</em>, <em>Code</em>,
* <em>Exceptiontable</em>, <em>LineNumberTable</em>, <em>LocalVariableTable</em>, <em>InnerClasses</em> and <em>Synthetic</em>
* attributes are supported. The <em>Unknown</em> attribute stands for non-standard-attributes.
*
- * @version $Id: Attribute.java,v 1.6 2009/09/10 15:35:05 aclement Exp $
+ * @version $Id: Attribute.java,v 1.7 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see ConstantValue
* @see SourceFile
case Constants.ATTR_STACK_MAP:
return new StackMap(idx, len, file, cpool);
case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
- return new RuntimeVisibleAnnotations(idx, len, file, cpool);
+ return new RuntimeVisAnnos(idx, len, file, cpool);
case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
- return new RuntimeInvisibleAnnotations(idx, len, file, cpool);
+ return new RuntimeInvisAnnos(idx, len, file, cpool);
case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
- return new RuntimeVisibleParameterAnnotations(idx, len, file, cpool);
+ return new RuntimeVisParamAnnos(idx, len, file, cpool);
case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
- return new RuntimeInvisibleParameterAnnotations(idx, len, file, cpool);
+ return new RuntimeInvisParamAnnos(idx, len, file, cpool);
case Constants.ATTR_ANNOTATION_DEFAULT:
return new AnnotationDefault(idx, len, file, cpool);
case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
return cpool;
}
- /**
- * Use copy() if you want to have a deep copy(), ie. with all references copied correctly.
- *
- * @return shallow copy of this attribute
- */
- @Override
- public Object clone() {
- Object o = null;
-
- try {
- o = super.clone();
- } catch (CloneNotSupportedException e) {
- e.printStackTrace(); // Never occurs
- }
-
- return o;
- }
-
- /**
- * @return deep copy of this attribute
- */
- public abstract Attribute copy(ConstantPool constant_pool);
+ // /**
+ // * Use copy() if you want to have a deep copy(), ie. with all references copied correctly.
+ // *
+ // * @return shallow copy of this attribute
+ // */
+ // @Override
+ // public Object clone() {
+ // Object o = null;
+ //
+ // try {
+ // o = super.clone();
+ // } catch (CloneNotSupportedException e) {
+ // e.printStackTrace(); // Never occurs
+ // }
+ //
+ // return o;
+ // }
+
+ //
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public abstract Attribute copy(ConstantPool constant_pool);
@Override
public String toString() {
}
}
- public static Attribute[] copy(Attribute[] attributes, ConstantPool constant_pool) {
- if (attributes == null || attributes.length == 0) {
- return Attribute.NoAttributes;
- }
- Attribute[] attrs = new Attribute[attributes.length];
- for (int i = 0; i < attributes.length; i++) {
- attrs[i] = attributes[i].copy(constant_pool);
- }
- return attrs;
- }
-
public static Signature getSignatureAttribute(Attribute[] attributes) {
for (int i = 0; i < attributes.length; i++) {
if (attributes[i].tag == Constants.ATTR_SIGNATURE) {
package org.aspectj.apache.bcel.classfile;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisParamAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisParamAnnos;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Implemented by wish of <A HREF="http://www.inf.fu-berlin.de/~bokowski">Boris Bokowski</A>.
*
- * @version $Id: ClassVisitor.java,v 1.3 2009/09/10 03:59:33 aclement Exp $
+ * @version $Id: ClassVisitor.java,v 1.4 2009/09/15 19:40:13 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public interface ClassVisitor {
public void visitEnclosingMethod(EnclosingMethod obj);
- public void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations obj);
+ public void visitRuntimeVisibleAnnotations(RuntimeVisAnnos obj);
- public void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations obj);
+ public void visitRuntimeInvisibleAnnotations(RuntimeInvisAnnos obj);
- public void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations obj);
+ public void visitRuntimeVisibleParameterAnnotations(RuntimeVisParamAnnos obj);
- public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations obj);
+ public void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisParamAnnos obj);
public void visitAnnotationDefault(AnnotationDefault obj);
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
-
-/**
- * This class represents a chunk of Java byte code contained in a
- * method. It is instantiated by the
- * <em>Attribute.readAttribute()</em> method. A <em>Code</em>
- * attribute contains informations about operand stack, local
- * variables, byte code and the exceptions handled within this
- * method.
- *
- * This attribute has attributes itself, namely <em>LineNumberTable</em> which
- * is used for debugging purposes and <em>LocalVariableTable</em> which
- * contains information about the local variables.
- *
- * @version $Id: Code.java,v 1.7 2009/09/10 15:35:05 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Attribute
- * @see CodeException
- * @see LineNumberTable
- * @see LocalVariableTable
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * This class represents a chunk of Java byte code contained in a method. It is instantiated by the
+ * <em>Attribute.readAttribute()</em> method. A <em>Code</em> attribute contains informations about operand stack, local variables,
+ * byte code and the exceptions handled within this method.
+ *
+ * This attribute has attributes itself, namely <em>LineNumberTable</em> which is used for debugging purposes and
+ * <em>LocalVariableTable</em> which contains information about the local variables.
+ *
+ * @version $Id: Code.java,v 1.8 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Attribute
+ * @see CodeException
+ * @see LineNumberTable
+ * @see LocalVariableTable
*/
public final class Code extends Attribute {
- private int maxStack; // Maximum size of stack used by this method
- private int maxLocals; // Number of local variables
- private byte[] code; // Actual byte code
- private CodeException[] exceptionTable;
- private Attribute[] attributes;
- private static final CodeException[] NO_EXCEPTIONS = new CodeException[]{};
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use copy() for a physical copy.
- */
- public Code(Code c) {
- this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(),
- c.getCode(), c.getExceptionTable(), c.getAttributes(),
- c.getConstantPool());
- }
-
-
- Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
- // Initialize with some default values which will be overwritten later
- this(name_index, length,
- file.readUnsignedShort(), file.readUnsignedShort(),
- (byte[])null, (CodeException[])null, (Attribute[])null,
- constant_pool);
-
- int len = file.readInt();
- code = new byte[len]; // Read byte code
- file.readFully(code);
-
- /* Read exception table that contains all regions where an exception
- * handler is active, i.e., a try { ... } catch() block.
- */
- len = file.readUnsignedShort();
- if (len==0) {
- exceptionTable = NO_EXCEPTIONS;
- } else {
- exceptionTable = new CodeException[len];
- for(int i=0; i < len; i++)
- exceptionTable[i] = new CodeException(file);
- }
-
- // Read all attributes, eg: LineNumberTable, LocalVariableTable
- attributes = AttributeUtils.readAttributes(file,constant_pool);
-
- /* Adjust length, because of setAttributes in this(), s.b. length
- * is incorrect, because it didn't take the internal attributes
- * into account yet! Very subtle bug, fixed in 3.1.1.
- */
- this.length = length;
- }
-
- /**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param max_stack Maximum size of stack
- * @param max_locals Number of local variables
- * @param code Actual byte code
- * @param exception_table Table of handled exceptions
- * @param attributes Attributes of code: LineNumber or LocalVariable
- * @param constant_pool Array of constants
- */
- public Code(int name_index, int length,
- int max_stack, int max_locals,
- byte[] code,
- CodeException[] exception_table,
- Attribute[] attributes,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_CODE, name_index, length, constant_pool);
-
- this.maxStack = max_stack;
- this.maxLocals = max_locals;
-
- setCode(code);
- setExceptionTable(exception_table);
- setAttributes(attributes); // Overwrites length!
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitCode(this);
- }
-
- /**
- * Dump code attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
-
- file.writeShort(maxStack);
- file.writeShort(maxLocals);
- file.writeInt(code.length);
- file.write(code, 0, code.length);
-
- file.writeShort(exceptionTable.length);
- for(int i=0; i < exceptionTable.length; i++)
- exceptionTable[i].dump(file);
-
- file.writeShort(attributes.length);
- for(int i=0; i < attributes.length; i++)
- attributes[i].dump(file);
- }
-
- /**
- * @return Collection of code attributes.
- * @see Attribute
- */
- public final Attribute[] getAttributes() { return attributes; }
-
- /**
- * @return LineNumberTable of Code, if it has one
- */
- public LineNumberTable getLineNumberTable() {
- for (int i=0; i < attributes.length; i++)
- if (attributes[i].tag==Constants.ATTR_LINE_NUMBER_TABLE) return (LineNumberTable)attributes[i];
- return null;
- }
-
- /**
- * @return LocalVariableTable of Code, if it has one
- */
- public LocalVariableTable getLocalVariableTable() {
- for(int i=0; i < attributes.length; i++)
- if (attributes[i].tag==Constants.ATTR_LOCAL_VARIABLE_TABLE) return (LocalVariableTable)attributes[i];
- return null;
- }
-
- /**
- * @return Actual byte code of the method.
- */
- public final byte[] getCode() { return code; }
-
- /**
- * @return Table of handled exceptions.
- * @see CodeException
- */
- public final CodeException[] getExceptionTable() { return exceptionTable; }
-
- /**
- * @return Number of local variables.
- */
- public final int getMaxLocals() { return maxLocals; }
-
- /**
- * @return Maximum size of stack used by this method.
- */
-
- public final int getMaxStack() { return maxStack; }
-
- /**
- * @return the internal length of this code attribute (minus the first 6 bytes)
- * and excluding all its attributes
- */
- private final int getInternalLength() {
- return 2 /*max_stack*/ + 2 /*max_locals*/ + 4 /*code length*/
- + (code==null?0:code.length) /*byte-code*/
- + 2 /*exception-table length*/
- + 8 * (exceptionTable==null?0:exceptionTable.length) /* exception table */
- + 2 /* attributes count */;
- }
-
- /**
- * @return the full size of this code attribute, minus its first 6 bytes,
- * including the size of all its contained attributes
- */
- private final int calculateLength() {
- int len = 0;
- if (attributes!=null) {
- for(int i=0; i < attributes.length; i++)
- len += attributes[i].length + 6 /*attribute header size*/;
- }
- return len + getInternalLength();
- }
-
- /**
- * @param attributes.
- */
- public final void setAttributes(Attribute[] attributes) {
- this.attributes = attributes;
- length = calculateLength(); // Adjust length
- }
-
- /**
- * @param code byte code
- */
- public final void setCode(byte[] code) {
- this.code = code;
- }
-
- /**
- * @param exception_table exception table
- */
- public final void setExceptionTable(CodeException[] exception_table) {
- this.exceptionTable = exception_table;
- }
-
- /**
- * @param max_locals maximum number of local variables
- */
- public final void setMaxLocals(int max_locals) {
- this.maxLocals = max_locals;
- }
-
- /**
- * @param max_stack maximum stack size
- */
- public final void setMaxStack(int max_stack) {
- this.maxStack = max_stack;
- }
-
- /**
- * @return String representation of code chunk.
- */
- public final String toString(boolean verbose) {
- StringBuffer buf;
-
- buf = new StringBuffer("Code(max_stack = " + maxStack +
- ", max_locals = " + maxLocals +
- ", code_length = " + code.length + ")\n" +
- Utility.codeToString(code, cpool, 0, -1, verbose));
-
- if(exceptionTable.length > 0) {
- buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n");
-
- for(int i=0; i < exceptionTable.length; i++)
- buf.append(exceptionTable[i].toString(cpool, verbose) + "\n");
- }
-
- if(attributes.length > 0) {
- buf.append("\nAttribute(s) = \n");
-
- for(int i=0; i < attributes.length; i++)
- buf.append(attributes[i].toString() + "\n");
- }
-
- return buf.toString();
- }
-
- /**
- * @return String representation of code chunk.
- */
- public final String toString() {
- return toString(true);
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Code c = (Code)clone();
- c.code = (byte[])code.clone();
- c.cpool = constant_pool;
-
- c.exceptionTable = new CodeException[exceptionTable.length];
- for(int i=0; i < exceptionTable.length; i++)
- c.exceptionTable[i] = exceptionTable[i].copy();
-
- c.attributes = new Attribute[attributes.length];
- for(int i=0; i < attributes.length; i++)
- c.attributes[i] = attributes[i].copy(constant_pool);
-
- return c;
- }
-
- /**
- * Returns the same as toString(true) except that the attribute information
- * isn't included (line numbers).
- * Can be used to check whether two pieces of code are equivalent.
- */
- public String getCodeString() {
- StringBuffer codeString = new StringBuffer();
- codeString.append("Code(max_stack = ").append(maxStack);
- codeString.append(", max_locals = ").append(maxLocals);
- codeString.append(", code_length = ").append(code.length).append(")\n");
- codeString.append(Utility.codeToString(code, cpool, 0, -1,true));
- if (exceptionTable.length>0) {
- codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n");
- for (int i = 0; i < exceptionTable.length; i++) {
- CodeException exc = exceptionTable[i];
- int type = exc.getCatchType();
- String name = "finally";
- if (type!=0) name = this.cpool.getConstantString(type,Constants.CONSTANT_Class);
- codeString.append(name).append("[");
- codeString.append(exc.getStartPC()).append(">").append(exc.getEndPC()).append("]\n");
- }
- }
- return codeString.toString();
- }
+ private int maxStack; // Maximum size of stack used by this method
+ private int maxLocals; // Number of local variables
+ private byte[] code; // Actual byte code
+ private CodeException[] exceptionTable;
+ private Attribute[] attributes;
+ private static final CodeException[] NO_EXCEPTIONS = new CodeException[] {};
+
+ /**
+ * Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical
+ * copy.
+ */
+ public Code(Code c) {
+ this(c.getNameIndex(), c.getLength(), c.getMaxStack(), c.getMaxLocals(), c.getCode(), c.getExceptionTable(), c
+ .getAttributes(), c.getConstantPool());
+ }
+
+ Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ // Initialize with some default values which will be overwritten later
+ this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), (byte[]) null, (CodeException[]) null,
+ (Attribute[]) null, constant_pool);
+
+ int len = file.readInt();
+ code = new byte[len]; // Read byte code
+ file.readFully(code);
+
+ /*
+ * Read exception table that contains all regions where an exception handler is active, i.e., a try { ... } catch() block.
+ */
+ len = file.readUnsignedShort();
+ if (len == 0) {
+ exceptionTable = NO_EXCEPTIONS;
+ } else {
+ exceptionTable = new CodeException[len];
+ for (int i = 0; i < len; i++)
+ exceptionTable[i] = new CodeException(file);
+ }
+
+ // Read all attributes, eg: LineNumberTable, LocalVariableTable
+ attributes = AttributeUtils.readAttributes(file, constant_pool);
+
+ /*
+ * Adjust length, because of setAttributes in this(), s.b. length is incorrect, because it didn't take the internal
+ * attributes into account yet! Very subtle bug, fixed in 3.1.1.
+ */
+ this.length = length;
+ }
+
+ /**
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param max_stack Maximum size of stack
+ * @param max_locals Number of local variables
+ * @param code Actual byte code
+ * @param exception_table Table of handled exceptions
+ * @param attributes Attributes of code: LineNumber or LocalVariable
+ * @param constant_pool Array of constants
+ */
+ public Code(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table,
+ Attribute[] attributes, ConstantPool constant_pool) {
+ super(Constants.ATTR_CODE, name_index, length, constant_pool);
+
+ this.maxStack = max_stack;
+ this.maxLocals = max_locals;
+
+ setCode(code);
+ setExceptionTable(exception_table);
+ setAttributes(attributes); // Overwrites length!
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitCode(this);
+ }
+
+ /**
+ * Dump code attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+
+ file.writeShort(maxStack);
+ file.writeShort(maxLocals);
+ file.writeInt(code.length);
+ file.write(code, 0, code.length);
+
+ file.writeShort(exceptionTable.length);
+ for (int i = 0; i < exceptionTable.length; i++)
+ exceptionTable[i].dump(file);
+
+ file.writeShort(attributes.length);
+ for (int i = 0; i < attributes.length; i++)
+ attributes[i].dump(file);
+ }
+
+ /**
+ * @return Collection of code attributes.
+ * @see Attribute
+ */
+ public final Attribute[] getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * @return LineNumberTable of Code, if it has one
+ */
+ public LineNumberTable getLineNumberTable() {
+ for (int i = 0; i < attributes.length; i++)
+ if (attributes[i].tag == Constants.ATTR_LINE_NUMBER_TABLE)
+ return (LineNumberTable) attributes[i];
+ return null;
+ }
+
+ /**
+ * @return LocalVariableTable of Code, if it has one
+ */
+ public LocalVariableTable getLocalVariableTable() {
+ for (int i = 0; i < attributes.length; i++)
+ if (attributes[i].tag == Constants.ATTR_LOCAL_VARIABLE_TABLE)
+ return (LocalVariableTable) attributes[i];
+ return null;
+ }
+
+ /**
+ * @return Actual byte code of the method.
+ */
+ public final byte[] getCode() {
+ return code;
+ }
+
+ /**
+ * @return Table of handled exceptions.
+ * @see CodeException
+ */
+ public final CodeException[] getExceptionTable() {
+ return exceptionTable;
+ }
+
+ /**
+ * @return Number of local variables.
+ */
+ public final int getMaxLocals() {
+ return maxLocals;
+ }
+
+ /**
+ * @return Maximum size of stack used by this method.
+ */
+
+ public final int getMaxStack() {
+ return maxStack;
+ }
+
+ /**
+ * @return the internal length of this code attribute (minus the first 6 bytes) and excluding all its attributes
+ */
+ private final int getInternalLength() {
+ return 2 /* max_stack */+ 2 /* max_locals */+ 4 /* code length */
+ + (code == null ? 0 : code.length) /* byte-code */
+ + 2 /* exception-table length */
+ + 8 * (exceptionTable == null ? 0 : exceptionTable.length) /* exception table */
+ + 2 /* attributes count */;
+ }
+
+ /**
+ * @return the full size of this code attribute, minus its first 6 bytes, including the size of all its contained attributes
+ */
+ private final int calculateLength() {
+ int len = 0;
+ if (attributes != null) {
+ for (int i = 0; i < attributes.length; i++)
+ len += attributes[i].length + 6 /* attribute header size */;
+ }
+ return len + getInternalLength();
+ }
+
+ /**
+ * @param attributes.
+ */
+ public final void setAttributes(Attribute[] attributes) {
+ this.attributes = attributes;
+ length = calculateLength(); // Adjust length
+ }
+
+ /**
+ * @param code byte code
+ */
+ public final void setCode(byte[] code) {
+ this.code = code;
+ }
+
+ /**
+ * @param exception_table exception table
+ */
+ public final void setExceptionTable(CodeException[] exception_table) {
+ this.exceptionTable = exception_table;
+ }
+
+ /**
+ * @param max_locals maximum number of local variables
+ */
+ public final void setMaxLocals(int max_locals) {
+ this.maxLocals = max_locals;
+ }
+
+ /**
+ * @param max_stack maximum stack size
+ */
+ public final void setMaxStack(int max_stack) {
+ this.maxStack = max_stack;
+ }
+
+ /**
+ * @return String representation of code chunk.
+ */
+ public final String toString(boolean verbose) {
+ StringBuffer buf;
+
+ buf = new StringBuffer("Code(max_stack = " + maxStack + ", max_locals = " + maxLocals + ", code_length = " + code.length
+ + ")\n" + Utility.codeToString(code, cpool, 0, -1, verbose));
+
+ if (exceptionTable.length > 0) {
+ buf.append("\nException handler(s) = \n" + "From\tTo\tHandler\tType\n");
+
+ for (int i = 0; i < exceptionTable.length; i++)
+ buf.append(exceptionTable[i].toString(cpool, verbose) + "\n");
+ }
+
+ if (attributes.length > 0) {
+ buf.append("\nAttribute(s) = \n");
+
+ for (int i = 0; i < attributes.length; i++)
+ buf.append(attributes[i].toString() + "\n");
+ }
+
+ return buf.toString();
+ }
+
+ /**
+ * @return String representation of code chunk.
+ */
+ @Override
+ public final String toString() {
+ return toString(true);
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // Code c = (Code)clone();
+ // c.code = (byte[])code.clone();
+ // c.cpool = constant_pool;
+ //
+ // c.exceptionTable = new CodeException[exceptionTable.length];
+ // for(int i=0; i < exceptionTable.length; i++)
+ // c.exceptionTable[i] = exceptionTable[i].copy();
+ //
+ // c.attributes = new Attribute[attributes.length];
+ // for(int i=0; i < attributes.length; i++)
+ // c.attributes[i] = attributes[i].copy(constant_pool);
+ //
+ // return c;
+ // }
+
+ /**
+ * Returns the same as toString(true) except that the attribute information isn't included (line numbers). Can be used to check
+ * whether two pieces of code are equivalent.
+ */
+ public String getCodeString() {
+ StringBuffer codeString = new StringBuffer();
+ codeString.append("Code(max_stack = ").append(maxStack);
+ codeString.append(", max_locals = ").append(maxLocals);
+ codeString.append(", code_length = ").append(code.length).append(")\n");
+ codeString.append(Utility.codeToString(code, cpool, 0, -1, true));
+ if (exceptionTable.length > 0) {
+ codeString.append("\n").append("Exception entries = ").append(exceptionTable.length).append("\n");
+ for (int i = 0; i < exceptionTable.length; i++) {
+ CodeException exc = exceptionTable[i];
+ int type = exc.getCatchType();
+ String name = "finally";
+ if (type != 0)
+ name = this.cpool.getConstantString(type, Constants.CONSTANT_Class);
+ codeString.append(name).append("[");
+ codeString.append(exc.getStartPC()).append(">").append(exc.getEndPC()).append("]\n");
+ }
+ }
+ return codeString.toString();
+ }
}
* This class is derived from <em>Attribute</em> and represents a constant value, i.e., a default value for initializing a class
* field. This class is instantiated by the <em>Attribute.readAttribute()</em> method.
*
- * @version $Id: ConstantValue.java,v 1.4 2009/09/10 15:35:04 aclement Exp $
+ * @version $Id: ConstantValue.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
return buf;
}
-
- /**
- * @return deep copy of this attribute
- */
- @Override
- public Attribute copy(ConstantPool constant_pool) {
- ConstantValue c = (ConstantValue) clone();
- c.cpool = constant_pool;
- return c;
- }
+ //
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // ConstantValue c = (ConstantValue) clone();
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
/**
- * This class is derived from <em>Attribute</em> and denotes that this is a
- * deprecated method.
- * It is instantiated from the <em>Attribute.readAttribute()</em> method.
- *
- * @version $Id: Deprecated.java,v 1.4 2009/09/10 15:35:04 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Attribute
+ * This class is derived from <em>Attribute</em> and denotes that this is a deprecated method. It is instantiated from the
+ * <em>Attribute.readAttribute()</em> method.
+ *
+ * @version $Id: Deprecated.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Attribute
*/
public final class Deprecated extends Attribute {
- private byte[] bytes;
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public Deprecated(Deprecated c) {
- this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
- }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param bytes Attribute contents
- * @param constant_pool Array of constants
- */
- public Deprecated(int name_index, int length, byte[] bytes,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool);
- this.bytes = bytes;
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- Deprecated(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (byte [])null, constant_pool);
-
- if(length > 0) {
- bytes = new byte[length];
- file.readFully(bytes);
- System.err.println("Deprecated attribute with length > 0");
- }
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitDeprecated(this);
- }
-
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
-
- if(length > 0)
- file.write(bytes, 0, length);
- }
-
- /**
- * @return data bytes.
- */
- public final byte[] getBytes() { return bytes; }
-
- /**
- * @param bytes.
- */
- public final void setBytes(byte[] bytes) {
- this.bytes = bytes;
- }
-
- /**
- * @return attribute name
- */
- public final String toString() {
- return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED];
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Deprecated c = (Deprecated)clone();
-
- if(bytes != null)
- c.bytes = (byte[])bytes.clone();
-
- c.cpool = constant_pool;
- return c;
- }
+ private byte[] bytes;
+
+ /**
+ * Initialize from another object. Note that both objects use the same references (shallow copy). Use clone() for a physical
+ * copy.
+ */
+ public Deprecated(Deprecated c) {
+ this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
+ }
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param bytes Attribute contents
+ * @param constant_pool Array of constants
+ */
+ public Deprecated(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
+ super(Constants.ATTR_DEPRECATED, name_index, length, constant_pool);
+ this.bytes = bytes;
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ Deprecated(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (byte[]) null, constant_pool);
+
+ if (length > 0) {
+ bytes = new byte[length];
+ file.readFully(bytes);
+ System.err.println("Deprecated attribute with length > 0");
+ }
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitDeprecated(this);
+ }
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+
+ if (length > 0)
+ file.write(bytes, 0, length);
+ }
+
+ /**
+ * @return data bytes.
+ */
+ public final byte[] getBytes() {
+ return bytes;
+ }
+
+ /**
+ * @param bytes.
+ */
+ public final void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ /**
+ * @return attribute name
+ */
+ @Override
+ public final String toString() {
+ return Constants.ATTRIBUTE_NAMES[Constants.ATTR_DEPRECATED];
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // Deprecated c = (Deprecated)clone();
+ //
+ // if(bytes != null)
+ // c.bytes = (byte[])bytes.clone();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
-
-/**
- * This class represents the table of exceptions that are thrown by a
- * method. This attribute may be used once per method. The name of
- * this class is <em>ExceptionTable</em> for historical reasons; The
- * Java Virtual Machine Specification, Second Edition defines this
- * attribute using the name <em>Exceptions</em> (which is inconsistent
- * with the other classes).
- *
- * @version $Id: ExceptionTable.java,v 1.4 2009/09/10 15:35:05 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Code
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+
+/**
+ * This class represents the table of exceptions that are thrown by a method. This attribute may be used once per method. The name
+ * of this class is <em>ExceptionTable</em> for historical reasons; The Java Virtual Machine Specification, Second Edition defines
+ * this attribute using the name <em>Exceptions</em> (which is inconsistent with the other classes).
+ *
+ * @version $Id: ExceptionTable.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Code
*/
public final class ExceptionTable extends Attribute {
- private int number_of_exceptions; // Table of indices into
- private int[] exception_index_table; // constant pool
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use copy() for a physical copy.
- */
- public ExceptionTable(ExceptionTable c) {
- this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(),
- c.getConstantPool());
- }
-
- /**
- * @param name_index Index in constant pool
- * @param length Content length in bytes
- * @param exception_index_table Table of indices in constant pool
- * @param constant_pool Array of constants
- */
- public ExceptionTable(int name_index, int length,
- int[] exception_index_table,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool);
- setExceptionIndexTable(exception_index_table);
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- ExceptionTable(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (int[])null, constant_pool);
-
- number_of_exceptions = file.readUnsignedShort();
- exception_index_table = new int[number_of_exceptions];
-
- for(int i=0; i < number_of_exceptions; i++)
- exception_index_table[i] = file.readUnsignedShort();
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitExceptionTable(this);
- }
-
- /**
- * Dump exceptions attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(number_of_exceptions);
- for(int i=0; i < number_of_exceptions; i++)
- file.writeShort(exception_index_table[i]);
- }
-
- /**
- * @return Array of indices into constant pool of thrown exceptions.
- */
- public final int[] getExceptionIndexTable() {return exception_index_table;}
- /**
- * @return Length of exception table.
- */
- public final int getNumberOfExceptions() { return number_of_exceptions; }
-
- /**
- * @return class names of thrown exceptions
- */
- public final String[] getExceptionNames() {
- String[] names = new String[number_of_exceptions];
- for(int i=0; i < number_of_exceptions; i++)
- names[i] = cpool.getConstantString(exception_index_table[i],
- Constants.CONSTANT_Class).
- replace('/', '.');
- return names;
- }
-
- /**
- * @param exception_index_table.
- * Also redefines number_of_exceptions according to table length.
- */
- public final void setExceptionIndexTable(int[] exception_index_table) {
- this.exception_index_table = exception_index_table;
- number_of_exceptions = (exception_index_table == null)? 0 :
- exception_index_table.length;
- }
- /**
- * @return String representation, i.e., a list of thrown exceptions.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer("");
- String str;
-
- for(int i=0; i < number_of_exceptions; i++) {
- str = cpool.getConstantString(exception_index_table[i],
- Constants.CONSTANT_Class);
- buf.append(Utility.compactClassName(str, false));
-
- if(i < number_of_exceptions - 1)
- buf.append(", ");
- }
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- ExceptionTable c = (ExceptionTable)clone();
- c.exception_index_table = (int[])exception_index_table.clone();
- c.cpool = constant_pool;
- return c;
- }
+ private int number_of_exceptions; // Table of indices into
+ private int[] exception_index_table; // constant pool
+
+ /**
+ * Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical
+ * copy.
+ */
+ public ExceptionTable(ExceptionTable c) {
+ this(c.getNameIndex(), c.getLength(), c.getExceptionIndexTable(), c.getConstantPool());
+ }
+
+ /**
+ * @param name_index Index in constant pool
+ * @param length Content length in bytes
+ * @param exception_index_table Table of indices in constant pool
+ * @param constant_pool Array of constants
+ */
+ public ExceptionTable(int name_index, int length, int[] exception_index_table, ConstantPool constant_pool) {
+ super(Constants.ATTR_EXCEPTIONS, name_index, length, constant_pool);
+ setExceptionIndexTable(exception_index_table);
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param name_index Index in constant pool
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ ExceptionTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (int[]) null, constant_pool);
+
+ number_of_exceptions = file.readUnsignedShort();
+ exception_index_table = new int[number_of_exceptions];
+
+ for (int i = 0; i < number_of_exceptions; i++)
+ exception_index_table[i] = file.readUnsignedShort();
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitExceptionTable(this);
+ }
+
+ /**
+ * Dump exceptions attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeShort(number_of_exceptions);
+ for (int i = 0; i < number_of_exceptions; i++)
+ file.writeShort(exception_index_table[i]);
+ }
+
+ /**
+ * @return Array of indices into constant pool of thrown exceptions.
+ */
+ public final int[] getExceptionIndexTable() {
+ return exception_index_table;
+ }
+
+ /**
+ * @return Length of exception table.
+ */
+ public final int getNumberOfExceptions() {
+ return number_of_exceptions;
+ }
+
+ /**
+ * @return class names of thrown exceptions
+ */
+ public final String[] getExceptionNames() {
+ String[] names = new String[number_of_exceptions];
+ for (int i = 0; i < number_of_exceptions; i++)
+ names[i] = cpool.getConstantString(exception_index_table[i], Constants.CONSTANT_Class).replace('/', '.');
+ return names;
+ }
+
+ /**
+ * @param exception_index_table. Also redefines number_of_exceptions according to table length.
+ */
+ public final void setExceptionIndexTable(int[] exception_index_table) {
+ this.exception_index_table = exception_index_table;
+ number_of_exceptions = (exception_index_table == null) ? 0 : exception_index_table.length;
+ }
+
+ /**
+ * @return String representation, i.e., a list of thrown exceptions.
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buf = new StringBuffer("");
+ String str;
+
+ for (int i = 0; i < number_of_exceptions; i++) {
+ str = cpool.getConstantString(exception_index_table[i], Constants.CONSTANT_Class);
+ buf.append(Utility.compactClassName(str, false));
+
+ if (i < number_of_exceptions - 1)
+ buf.append(", ");
+ }
+
+ return buf.toString();
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // ExceptionTable c = (ExceptionTable)clone();
+ // c.exception_index_table = (int[])exception_index_table.clone();
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
/**
* Abstract super class for fields and methods.
*
- * @version $Id: FieldOrMethod.java,v 1.11 2009/09/15 03:33:52 aclement Exp $
+ * @version $Id: FieldOrMethod.java,v 1.12 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class FieldOrMethod extends Modifiers implements Node {
List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>();
for (int i = 0; i < attributes.length; i++) {
Attribute attribute = attributes[i];
- if (attribute instanceof RuntimeAnnotations) {
- RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) attribute;
+ if (attribute instanceof RuntimeAnnos) {
+ RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute;
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations());
}
}
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
/**
- * This class is derived from <em>Attribute</em> and denotes that this class
- * is an Inner class of another.
- * to the source file of this class.
- * It is instantiated from the <em>Attribute.readAttribute()</em> method.
- *
- * @version $Id: InnerClasses.java,v 1.4 2009/09/10 15:35:05 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Attribute
+ * This class is derived from <em>Attribute</em> and denotes that this class is an Inner class of another. to the source file of
+ * this class. It is instantiated from the <em>Attribute.readAttribute()</em> method.
+ *
+ * @version $Id: InnerClasses.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Attribute
*/
public final class InnerClasses extends Attribute {
- private InnerClass[] inner_classes;
- private int number_of_classes;
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public InnerClasses(InnerClasses c) {
- this(c.getNameIndex(), c.getLength(), c.getInnerClasses(),
- c.getConstantPool());
- }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param inner_classes array of inner classes attributes
- * @param constant_pool Array of constants
- * @param sourcefile_index Index in constant pool to CONSTANT_Utf8
- */
- public InnerClasses(int name_index, int length,
- InnerClass[] inner_classes,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool);
- setInnerClasses(inner_classes);
- }
-
- /**
- * Construct object from file stream.
- *
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- InnerClasses(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (InnerClass[])null, constant_pool);
-
- number_of_classes = file.readUnsignedShort();
- inner_classes = new InnerClass[number_of_classes];
-
- for(int i=0; i < number_of_classes; i++)
- inner_classes[i] = new InnerClass(file);
- }
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitInnerClasses(this);
- }
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(number_of_classes);
-
- for(int i=0; i < number_of_classes; i++)
- inner_classes[i].dump(file);
- }
-
- /**
- * @return array of inner class "records"
- */
- public final InnerClass[] getInnerClasses() { return inner_classes; }
-
- /**
- * @param inner_classes.
- */
- public final void setInnerClasses(InnerClass[] inner_classes) {
- this.inner_classes = inner_classes;
- number_of_classes = (inner_classes == null)? 0 : inner_classes.length;
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer();
-
- for(int i=0; i < number_of_classes; i++)
- buf.append(inner_classes[i].toString(cpool) + "\n");
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- InnerClasses c = (InnerClasses)clone();
-
- c.inner_classes = new InnerClass[number_of_classes];
- for(int i=0; i < number_of_classes; i++)
- c.inner_classes[i] = inner_classes[i].copy();
-
- c.cpool = constant_pool;
- return c;
- }
+ private InnerClass[] inner_classes;
+ private int number_of_classes;
+
+ /**
+ * Initialize from another object. Note that both objects use the same references (shallow copy). Use clone() for a physical
+ * copy.
+ */
+ public InnerClasses(InnerClasses c) {
+ this(c.getNameIndex(), c.getLength(), c.getInnerClasses(), c.getConstantPool());
+ }
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param inner_classes array of inner classes attributes
+ * @param constant_pool Array of constants
+ * @param sourcefile_index Index in constant pool to CONSTANT_Utf8
+ */
+ public InnerClasses(int name_index, int length, InnerClass[] inner_classes, ConstantPool constant_pool) {
+ super(Constants.ATTR_INNER_CLASSES, name_index, length, constant_pool);
+ setInnerClasses(inner_classes);
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ InnerClasses(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (InnerClass[]) null, constant_pool);
+
+ number_of_classes = file.readUnsignedShort();
+ inner_classes = new InnerClass[number_of_classes];
+
+ for (int i = 0; i < number_of_classes; i++)
+ inner_classes[i] = new InnerClass(file);
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitInnerClasses(this);
+ }
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeShort(number_of_classes);
+
+ for (int i = 0; i < number_of_classes; i++)
+ inner_classes[i].dump(file);
+ }
+
+ /**
+ * @return array of inner class "records"
+ */
+ public final InnerClass[] getInnerClasses() {
+ return inner_classes;
+ }
+
+ /**
+ * @param inner_classes.
+ */
+ public final void setInnerClasses(InnerClass[] inner_classes) {
+ this.inner_classes = inner_classes;
+ number_of_classes = (inner_classes == null) ? 0 : inner_classes.length;
+ }
+
+ /**
+ * @return String representation.
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buf = new StringBuffer();
+
+ for (int i = 0; i < number_of_classes; i++)
+ buf.append(inner_classes[i].toString(cpool) + "\n");
+
+ return buf.toString();
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // InnerClasses c = (InnerClasses)clone();
+ //
+ // c.inner_classes = new InnerClass[number_of_classes];
+ // for(int i=0; i < number_of_classes; i++)
+ // c.inner_classes[i] = inner_classes[i].copy();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.apache.bcel.util.SyntheticRepository;
* The intent of this class is to represent a parsed or otherwise existing class file. Those interested in programatically
* generating classes should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
*
- * @version $Id: JavaClass.java,v 1.21 2009/09/15 16:39:56 aclement Exp $
+ * @version $Id: JavaClass.java,v 1.22 2009/09/15 19:40:14 aclement Exp $
* @see org.aspectj.apache.bcel.generic.ClassGen
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
List<AnnotationGen> accumulatedAnnotations = new ArrayList<AnnotationGen>();
for (int i = 0; i < attributes.length; i++) {
Attribute attribute = attributes[i];
- if (attribute instanceof RuntimeAnnotations) {
- RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) attribute;
+ if (attribute instanceof RuntimeAnnos) {
+ RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attribute;
accumulatedAnnotations.addAll(runtimeAnnotations.getAnnotations());
}
}
* This class represents a table of line numbers for debugging purposes. This attribute is used by the <em>Code</em> attribute. It
* contains pairs of PCs and line numbers.
*
- * @version $Id: LineNumberTable.java,v 1.7 2009/09/10 15:35:05 aclement Exp $
+ * @version $Id: LineNumberTable.java,v 1.8 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code changes: asc Feb06 Made unpacking lazy
*/
/**
* @return deep copy of this attribute
*/
- @Override
- public Attribute copy(ConstantPool constant_pool) {
- unpack();
- LineNumberTable newTable = (LineNumberTable) clone();
- newTable.table = new LineNumber[tableLength];
- for (int i = 0; i < tableLength; i++) {
- newTable.table[i] = table[i].copy();
- }
- newTable.cpool = constant_pool;
- return newTable;
- }
-
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // unpack();
+ // LineNumberTable newTable = (LineNumberTable) clone();
+ // newTable.table = new LineNumber[tableLength];
+ // for (int i = 0; i < tableLength; i++) {
+ // newTable.table[i] = table[i].copy();
+ // }
+ // newTable.cpool = constant_pool;
+ // return newTable;
+ // }
public final int getTableLength() {
unpack();
return tableLength;
/**
* This class represents collection of local variables in a method. This attribute is contained in the <em>Code</em> attribute.
*
- * @version $Id: LocalVariableTable.java,v 1.7 2009/09/10 15:35:04 aclement Exp $
+ * @version $Id: LocalVariableTable.java,v 1.8 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Code
* @see LocalVariable Updates: Andy 14Feb06 - Made unpacking of the data lazy, depending on someone actually asking for it.
*
* @param v Visitor object
*/
+ @Override
public void accept(ClassVisitor v) {
unpack();
v.visitLocalVariableTable(this);
* @param file Output file stream
* @throws IOException
*/
+ @Override
public final void dump(DataOutputStream file) throws IOException {
super.dump(file);
if (isInPackedState) {
/**
* @return String representation.
*/
+ @Override
public final String toString() {
StringBuffer buf = new StringBuffer("");
unpack();
/**
* @return deep copy of this attribute
*/
- public Attribute copy(ConstantPool constant_pool) {
- unpack();
- LocalVariableTable c = (LocalVariableTable) clone();
-
- c.localVariableTable = new LocalVariable[localVariableTableLength];
- for (int i = 0; i < localVariableTableLength; i++)
- c.localVariableTable[i] = localVariableTable[i].copy();
-
- c.cpool = constant_pool;
- return c;
- }
-
+ // public Attribute copy(ConstantPool constant_pool) {
+ // unpack();
+ // LocalVariableTable c = (LocalVariableTable) clone();
+ //
+ // c.localVariableTable = new LocalVariable[localVariableTableLength];
+ // for (int i = 0; i < localVariableTableLength; i++)
+ // c.localVariableTable[i] = localVariableTable[i].copy();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
public final int getTableLength() {
unpack();
return localVariableTableLength;
* ******************************************************************/
package org.aspectj.apache.bcel.classfile;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
+import org.aspectj.apache.bcel.Constants;
// The new table is used when generic types are about...
// }
// J5TODO: Needs some testing !
public class LocalVariableTypeTable extends Attribute {
- private int local_variable_type_table_length; // Table of local
- private LocalVariable[] local_variable_type_table; // variables
-
- public LocalVariableTypeTable(LocalVariableTypeTable c) {
- this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(),
- c.getConstantPool());
- }
-
- public LocalVariableTypeTable(int name_index, int length,
- LocalVariable[] local_variable_table,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
- setLocalVariableTable(local_variable_table);
- }
-
- LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException {
- this(nameIdx, len, (LocalVariable[])null, cpool);
-
- local_variable_type_table_length = (dis.readUnsignedShort());
- local_variable_type_table = new LocalVariable[local_variable_type_table_length];
-
- for(int i=0; i < local_variable_type_table_length; i++)
- local_variable_type_table[i] = new LocalVariable(dis, cpool);
- }
-
- public void accept(ClassVisitor v) {
- v.visitLocalVariableTypeTable(this);
- }
-
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(local_variable_type_table_length);
- for(int i=0; i < local_variable_type_table_length; i++)
- local_variable_type_table[i].dump(file);
- }
-
- public final LocalVariable[] getLocalVariableTypeTable() {
- return local_variable_type_table;
- }
-
- public final LocalVariable getLocalVariable(int index) {
- for(int i=0; i < local_variable_type_table_length; i++)
- if(local_variable_type_table[i].getIndex() == index)
- return local_variable_type_table[i];
-
- return null;
- }
-
- public final void setLocalVariableTable(LocalVariable[] local_variable_table)
- {
- this.local_variable_type_table = local_variable_table;
- local_variable_type_table_length = (local_variable_table == null)? 0 :
- local_variable_table.length;
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer("");
-
- for(int i=0; i < local_variable_type_table_length; i++) {
- buf.append(local_variable_type_table[i].toString());
-
- if(i < local_variable_type_table_length - 1) buf.append('\n');
- }
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- LocalVariableTypeTable c = (LocalVariableTypeTable)clone();
-
- c.local_variable_type_table = new LocalVariable[local_variable_type_table_length];
- for(int i=0; i < local_variable_type_table_length; i++)
- c.local_variable_type_table[i] = local_variable_type_table[i].copy();
-
- c.cpool = constant_pool;
- return c;
- }
-
- public final int getTableLength() { return local_variable_type_table_length; }
+ private int local_variable_type_table_length; // Table of local
+ private LocalVariable[] local_variable_type_table; // variables
+
+ public LocalVariableTypeTable(LocalVariableTypeTable c) {
+ this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), c.getConstantPool());
+ }
+
+ public LocalVariableTypeTable(int name_index, int length, LocalVariable[] local_variable_table, ConstantPool constant_pool) {
+ super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool);
+ setLocalVariableTable(local_variable_table);
+ }
+
+ LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis, ConstantPool cpool) throws IOException {
+ this(nameIdx, len, (LocalVariable[]) null, cpool);
+
+ local_variable_type_table_length = (dis.readUnsignedShort());
+ local_variable_type_table = new LocalVariable[local_variable_type_table_length];
+
+ for (int i = 0; i < local_variable_type_table_length; i++)
+ local_variable_type_table[i] = new LocalVariable(dis, cpool);
+ }
+
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitLocalVariableTypeTable(this);
+ }
+
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeShort(local_variable_type_table_length);
+ for (int i = 0; i < local_variable_type_table_length; i++)
+ local_variable_type_table[i].dump(file);
+ }
+
+ public final LocalVariable[] getLocalVariableTypeTable() {
+ return local_variable_type_table;
+ }
+
+ public final LocalVariable getLocalVariable(int index) {
+ for (int i = 0; i < local_variable_type_table_length; i++)
+ if (local_variable_type_table[i].getIndex() == index)
+ return local_variable_type_table[i];
+
+ return null;
+ }
+
+ public final void setLocalVariableTable(LocalVariable[] local_variable_table) {
+ this.local_variable_type_table = local_variable_table;
+ local_variable_type_table_length = (local_variable_table == null) ? 0 : local_variable_table.length;
+ }
+
+ /**
+ * @return String representation.
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buf = new StringBuffer("");
+
+ for (int i = 0; i < local_variable_type_table_length; i++) {
+ buf.append(local_variable_type_table[i].toString());
+
+ if (i < local_variable_type_table_length - 1)
+ buf.append('\n');
+ }
+
+ return buf.toString();
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // LocalVariableTypeTable c = (LocalVariableTypeTable)clone();
+ //
+ // c.local_variable_type_table = new LocalVariable[local_variable_type_table_length];
+ // for(int i=0; i < local_variable_type_table_length; i++)
+ // c.local_variable_type_table[i] = local_variable_type_table[i].copy();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
+
+ public final int getTableLength() {
+ return local_variable_type_table_length;
+ }
}
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisParamAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisParamAnnos;
import org.aspectj.apache.bcel.generic.Type;
/**
* This class represents the method info structure, i.e., the representation for a method in the class. See JVM specification for
* details. A method has access flags, a name, a signature and a number of attributes.
*
- * @version $Id: Method.java,v 1.10 2009/09/15 03:33:52 aclement Exp $
+ * @version $Id: Method.java,v 1.11 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public final class Method extends FieldOrMethod {
return;
}
- RuntimeVisibleParameterAnnotations parameterAnnotationsVis = null;
- RuntimeInvisibleParameterAnnotations parameterAnnotationsInvis = null;
+ RuntimeVisParamAnnos parameterAnnotationsVis = null;
+ RuntimeInvisParamAnnos parameterAnnotationsInvis = null;
// Find attributes that contain annotation data
Attribute[] attrs = getAttributes();
for (int i = 0; i < attrs.length; i++) {
Attribute attribute = attrs[i];
- if (attribute instanceof RuntimeVisibleParameterAnnotations) {
- parameterAnnotationsVis = (RuntimeVisibleParameterAnnotations) attribute;
- } else if (attribute instanceof RuntimeInvisibleParameterAnnotations) {
- parameterAnnotationsInvis = (RuntimeInvisibleParameterAnnotations) attribute;
+ if (attribute instanceof RuntimeVisParamAnnos) {
+ parameterAnnotationsVis = (RuntimeVisParamAnnos) attribute;
+ } else if (attribute instanceof RuntimeInvisParamAnnos) {
+ parameterAnnotationsInvis = (RuntimeInvisParamAnnos) attribute;
}
}
* This class is derived from <em>Attribute</em> and represents a reference to a <href="http://wwwipd.ira.uka.de/~pizza/gj/">GJ</a>
* attribute.
*
- * @version $Id: Signature.java,v 1.10 2009/09/10 15:35:04 aclement Exp $
+ * @version $Id: Signature.java,v 1.11 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
return "Signature(" + s + ")";
}
- /**
- * @return deep copy of this attribute
- */
- @Override
- public Attribute copy(ConstantPool constant_pool) {
- return (Signature) clone();
- }
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // return (Signature) clone();
+ // }
}
* attribute should appear per classfile. The intention of this class is that it is instantiated from the
* <em>Attribute.readAttribute()</em> method.
*
- * @version $Id: SourceFile.java,v 1.4 2009/09/10 15:35:04 aclement Exp $
+ * @version $Id: SourceFile.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Attribute
*/
}
/**
- * @return deep copy of this attribute
+ * @return deep copy of this attribute //
*/
- @Override
- public Attribute copy(ConstantPool constant_pool) {
- return (SourceFile) clone();
- }
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // return (SourceFile) clone();
+ // }
}
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
-import java.io.*;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
/**
- * This class represents a stack map attribute used for
- * preverification of Java classes for the <a
- * href="http://java.sun.com/j2me/"> Java 2 Micro Edition</a>
- * (J2ME). This attribute is used by the <a
- * href="http://java.sun.com/products/cldc/">KVM</a> and contained
- * within the Code attribute of a method. See CLDC specification
- * §5.3.1.2
- *
- * @version $Id: StackMap.java,v 1.5 2009/09/10 15:35:04 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Code
- * @see StackMapEntry
- * @see StackMapType
+ * This class represents a stack map attribute used for preverification of Java classes for the <a href="http://java.sun.com/j2me/">
+ * Java 2 Micro Edition</a> (J2ME). This attribute is used by the <a href="http://java.sun.com/products/cldc/">KVM</a> and contained
+ * within the Code attribute of a method. See CLDC specification §5.3.1.2
+ *
+ * @version $Id: StackMap.java,v 1.6 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Code
+ * @see StackMapEntry
+ * @see StackMapType
*/
public final class StackMap extends Attribute {
- private int map_length;
- private StackMapEntry[] map; // Table of stack map entries
-
- /*
- * @param name_index Index of name
- * @param length Content length in bytes
- * @param map Table of stack map entries
- * @param constant_pool Array of constants
- */
- public StackMap(int name_index, int length, StackMapEntry[] map,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
-
- setStackMap(map);
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index of name
- * @param length Content length in bytes
- * @param file Input stream
- * @throws IOException
- * @param constant_pool Array of constants
- */
- StackMap(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (StackMapEntry[])null, constant_pool);
-
- map_length = file.readUnsignedShort();
- map = new StackMapEntry[map_length];
-
- for(int i=0; i < map_length; i++)
- map[i] = new StackMapEntry(file, constant_pool);
- }
-
- /**
- * Dump line number table attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(map_length);
- for(int i=0; i < map_length; i++)
- map[i].dump(file);
- }
-
- /**
- * @return Array of stack map entries
- */
- public final StackMapEntry[] getStackMap() { return map; }
-
- /**
- * @param map Array of stack map entries
- */
- public final void setStackMap(StackMapEntry[] map) {
- this.map = map;
-
- map_length = (map == null)? 0 : map.length;
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer("StackMap(");
-
- for(int i=0; i < map_length; i++) {
- buf.append(map[i].toString());
-
- if(i < map_length - 1)
- buf.append(", ");
- }
-
- buf.append(')');
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- StackMap c = (StackMap)clone();
-
- c.map = new StackMapEntry[map_length];
- for(int i=0; i < map_length; i++)
- c.map[i] = map[i].copy();
-
- c.cpool = constant_pool;
- return c;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitStackMap(this);
- }
-
- public final int getMapLength() { return map_length; }
+ private int map_length;
+ private StackMapEntry[] map; // Table of stack map entries
+
+ /*
+ * @param name_index Index of name
+ *
+ * @param length Content length in bytes
+ *
+ * @param map Table of stack map entries
+ *
+ * @param constant_pool Array of constants
+ */
+ public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) {
+ super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
+
+ setStackMap(map);
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param name_index Index of name
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @throws IOException
+ * @param constant_pool Array of constants
+ */
+ StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (StackMapEntry[]) null, constant_pool);
+
+ map_length = file.readUnsignedShort();
+ map = new StackMapEntry[map_length];
+
+ for (int i = 0; i < map_length; i++)
+ map[i] = new StackMapEntry(file, constant_pool);
+ }
+
+ /**
+ * Dump line number table attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ file.writeShort(map_length);
+ for (int i = 0; i < map_length; i++)
+ map[i].dump(file);
+ }
+
+ /**
+ * @return Array of stack map entries
+ */
+ public final StackMapEntry[] getStackMap() {
+ return map;
+ }
+
+ /**
+ * @param map Array of stack map entries
+ */
+ public final void setStackMap(StackMapEntry[] map) {
+ this.map = map;
+
+ map_length = (map == null) ? 0 : map.length;
+ }
+
+ /**
+ * @return String representation.
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buf = new StringBuffer("StackMap(");
+
+ for (int i = 0; i < map_length; i++) {
+ buf.append(map[i].toString());
+
+ if (i < map_length - 1)
+ buf.append(", ");
+ }
+
+ buf.append(')');
+
+ return buf.toString();
+ }
+
+ //
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // StackMap c = (StackMap)clone();
+ //
+ // c.map = new StackMapEntry[map_length];
+ // for(int i=0; i < map_length; i++)
+ // c.map[i] = map[i].copy();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitStackMap(this);
+ }
+
+ public final int getMapLength() {
+ return map_length;
+ }
}
* <http://www.apache.org/>.
*/
-import org.aspectj.apache.bcel.Constants;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
-import java.io.*;
+import org.aspectj.apache.bcel.Constants;
/**
- * This class is derived from <em>Attribute</em> and declares this class as
- * `synthetic', i.e., it needs special handling. The JVM specification
- * states "A class member that does not appear in the source code must be
- * marked using a Synthetic attribute." It may appear in the ClassFile
- * attribute table, a field_info table or a method_info table. This class
- * is intended to be instantiated from the
- * <em>Attribute.readAttribute()</em> method.
- *
- * @version $Id: Synthetic.java,v 1.4 2009/09/10 15:35:04 aclement Exp $
- * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
- * @see Attribute
+ * This class is derived from <em>Attribute</em> and declares this class as `synthetic', i.e., it needs special handling. The JVM
+ * specification states "A class member that does not appear in the source code must be marked using a Synthetic attribute." It may
+ * appear in the ClassFile attribute table, a field_info table or a method_info table. This class is intended to be instantiated
+ * from the <em>Attribute.readAttribute()</em> method.
+ *
+ * @version $Id: Synthetic.java,v 1.5 2009/09/15 19:40:12 aclement Exp $
+ * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @see Attribute
*/
public final class Synthetic extends Attribute {
- private byte[] bytes;
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use copy() for a physical copy.
- */
- public Synthetic(Synthetic c) {
- this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
- }
-//
-// public Synthetic(ConstantPoolGen cpool) {
-// super(Constants.ATTR_SYNTHETIC, cpool.addUtf8("Synthetic"), 0, cpool);
-// ConstantPoolGen cpg = myGen.getConstantPool();
-// int index = ;
-// Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool());
-// }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8, which
- * should represent the string "Synthetic".
- * @param length Content length in bytes - should be zero.
- * @param bytes Attribute contents
- * @param constant_pool The constant pool this attribute is associated
- * with.
- */
- public Synthetic(int name_index, int length, byte[] bytes,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool);
- this.bytes = bytes;
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- Synthetic(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (byte [])null, constant_pool);
-
- if(length > 0) {
- bytes = new byte[length];
- file.readFully(bytes);
- System.err.println("Synthetic attribute with length > 0");
- }
- }
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(ClassVisitor v) {
- v.visitSynthetic(this);
- }
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- if(length > 0)
- file.write(bytes, 0, length);
- }
- /**
- * @return data bytes.
- */
- public final byte[] getBytes() { return bytes; }
-
- /**
- * @param bytes.
- */
- public final void setBytes(byte[] bytes) {
- this.bytes = bytes;
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer("Synthetic");
-
- if(length > 0)
- buf.append(" " + Utility.toHexString(bytes));
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Synthetic c = (Synthetic)clone();
-
- if(bytes != null)
- c.bytes = (byte[])bytes.clone();
-
- c.cpool = constant_pool;
- return c;
- }
+ private byte[] bytes;
+
+ /**
+ * Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical
+ * copy.
+ */
+ public Synthetic(Synthetic c) {
+ this(c.getNameIndex(), c.getLength(), c.getBytes(), c.getConstantPool());
+ }
+
+ //
+ // public Synthetic(ConstantPoolGen cpool) {
+ // super(Constants.ATTR_SYNTHETIC, cpool.addUtf8("Synthetic"), 0, cpool);
+ // ConstantPoolGen cpg = myGen.getConstantPool();
+ // int index = ;
+ // Attribute synthetic = new Synthetic(index, 0, new byte[0], cpg.getConstantPool());
+ // }
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8, which should represent the string "Synthetic".
+ * @param length Content length in bytes - should be zero.
+ * @param bytes Attribute contents
+ * @param constant_pool The constant pool this attribute is associated with.
+ */
+ public Synthetic(int name_index, int length, byte[] bytes, ConstantPool constant_pool) {
+ super(Constants.ATTR_SYNTHETIC, name_index, length, constant_pool);
+ this.bytes = bytes;
+ }
+
+ /**
+ * Construct object from file stream.
+ *
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(name_index, length, (byte[]) null, constant_pool);
+
+ if (length > 0) {
+ bytes = new byte[length];
+ file.readFully(bytes);
+ System.err.println("Synthetic attribute with length > 0");
+ }
+ }
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the
+ * hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ @Override
+ public void accept(ClassVisitor v) {
+ v.visitSynthetic(this);
+ }
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ @Override
+ public final void dump(DataOutputStream file) throws IOException {
+ super.dump(file);
+ if (length > 0)
+ file.write(bytes, 0, length);
+ }
+
+ /**
+ * @return data bytes.
+ */
+ public final byte[] getBytes() {
+ return bytes;
+ }
+
+ /**
+ * @param bytes.
+ */
+ public final void setBytes(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ /**
+ * @return String representation.
+ */
+ @Override
+ public final String toString() {
+ StringBuffer buf = new StringBuffer("Synthetic");
+
+ if (length > 0)
+ buf.append(" " + Utility.toHexString(bytes));
+
+ return buf.toString();
+ }
+
+ // /**
+ // * @return deep copy of this attribute
+ // */
+ // public Attribute copy(ConstantPool constant_pool) {
+ // Synthetic c = (Synthetic)clone();
+ //
+ // if(bytes != null)
+ // c.bytes = (byte[])bytes.clone();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
* org.aspectj.apache.bcel.classfile.AttributeReader)">Attribute.addAttributeReader</a>.
*
*
- * @version $Id: Unknown.java,v 1.5 2009/09/10 15:35:05 aclement Exp $
+ * @version $Id: Unknown.java,v 1.6 2009/09/15 19:40:12 aclement Exp $
* @see org.aspectj.apache.bcel.classfile.Attribute
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
/**
* @return deep copy of this attribute
*/
- @Override
- public Attribute copy(ConstantPool constant_pool) {
- Unknown c = (Unknown) clone();
-
- if (bytes != null)
- c.bytes = bytes.clone();
-
- c.cpool = constant_pool;
- return c;
- }
+ // @Override
+ // public Attribute copy(ConstantPool constant_pool) {
+ // Unknown c = (Unknown) clone();
+ //
+ // if (bytes != null)
+ // c.bytes = bytes.clone();
+ //
+ // c.cpool = constant_pool;
+ // return c;
+ // }
}
import org.aspectj.apache.bcel.Constants;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleParameterAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisParamAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeParamAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisParamAnnos;
import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.apache.bcel.util.ByteSequence;
/**
* Utility functions that do not really belong to any class in particular.
*
- * @version $Id: Utility.java,v 1.11 2009/09/14 20:29:10 aclement Exp $
+ * @version $Id: Utility.java,v 1.12 2009/09/15 19:40:13 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*
* modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized
brackets = new StringBuffer(); // Accumulate []'s
// Count opening brackets and look for optional size argument
- for (n = 0; signature.charAt(n) == '['; n++)
+ for (n = 0; signature.charAt(n) == '['; n++) {
brackets.append("[]");
+ }
consumedChars = n;
- // The rest of the string denotes a `<field_type>'
+ // The rest of the string denotes a '<field_type>'
ResultHolder restOfIt = signatureToStringInternal(signature.substring(n), chopit);
- // type = signatureToString(signature.substring(n), chopit);
-
consumedChars += restOfIt.getConsumedChars();
return new ResultHolder(restOfIt.getResult() + brackets.toString(), consumedChars);
}
-
case 'V':
return ResultHolder.VOID;
* @param cp The constant pool gen where we can create the necessary name refs
* @param annotations A list of AnnotationGen objects
*/
- public static Collection<RuntimeAnnotations> getAnnotationAttributes(ConstantPool cp, List<AnnotationGen> annotations) {
+ public static Collection<RuntimeAnnos> getAnnotationAttributes(ConstantPool cp, List<AnnotationGen> annotations) {
if (annotations.size() == 0)
return null;
if (riaData.length > 2)
riaIndex = cp.addUtf8("RuntimeInvisibleAnnotations");
- List<RuntimeAnnotations> newAttributes = new ArrayList<RuntimeAnnotations>();
+ List<RuntimeAnnos> newAttributes = new ArrayList<RuntimeAnnos>();
if (rvaData.length > 2) {
- newAttributes.add(new RuntimeVisibleAnnotations(rvaIndex, rvaData.length, rvaData, cp));
+ newAttributes.add(new RuntimeVisAnnos(rvaIndex, rvaData.length, rvaData, cp));
}
if (riaData.length > 2) {
- newAttributes.add(new RuntimeInvisibleAnnotations(riaIndex, riaData.length, riaData, cp));
+ newAttributes.add(new RuntimeInvisAnnos(riaIndex, riaData.length, riaData, cp));
}
return newAttributes;
if (totalInvisCount > 0)
riaIndex = cp.addUtf8("RuntimeInvisibleParameterAnnotations");
- List<RuntimeParameterAnnotations> newAttributes = new ArrayList<RuntimeParameterAnnotations>();
+ List<RuntimeParamAnnos> newAttributes = new ArrayList<RuntimeParamAnnos>();
if (totalVisCount > 0) {
- newAttributes.add(new RuntimeVisibleParameterAnnotations(rvaIndex, rvaData.length, rvaData, cp));
+ newAttributes.add(new RuntimeVisParamAnnos(rvaIndex, rvaData.length, rvaData, cp));
}
if (totalInvisCount > 0) {
- newAttributes.add(new RuntimeInvisibleParameterAnnotations(riaIndex, riaData.length, riaData, cp));
+ newAttributes.add(new RuntimeInvisParamAnnos(riaIndex, riaData.length, riaData, cp));
}
return newAttributes.toArray(new Attribute[] {});
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public class AnnotationElementValue extends ElementValue {
+
+ private AnnotationGen a;
+
+ public AnnotationElementValue(AnnotationGen a, ConstantPool cpool) {
+ super(ANNOTATION, cpool);
+ this.a = a;
+ }
+
+ public AnnotationElementValue(int type, AnnotationGen annotation, ConstantPool cpool) {
+ super(type, cpool);
+ assert type == ANNOTATION;
+ this.a = annotation;
+ }
+
+ public AnnotationElementValue(AnnotationElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ super(ANNOTATION, cpool);
+ a = new AnnotationGen(value.getAnnotation(), cpool, copyPoolEntries);
+ }
+
+ @Override
+ public void dump(DataOutputStream dos) throws IOException {
+ dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
+ a.dump(dos);
+ }
+
+ @Override
+ public String stringifyValue() {
+ throw new RuntimeException("Not implemented yet");
+ }
+
+ public AnnotationGen getAnnotation() {
+ return a;
+ }
+
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-
-public class AnnotationElementValueGen extends ElementValueGen {
-
- // For annotation element values, this is the annotation
- private AnnotationGen a;
-
- public AnnotationElementValueGen(AnnotationGen a,ConstantPool cpool) {
- super(ANNOTATION,cpool);
- this.a = a;
- }
-
- public AnnotationElementValueGen(int type, AnnotationGen annotation, ConstantPool cpool) {
- super(type,cpool);
- if (type != ANNOTATION)
- throw new RuntimeException("Only element values of type annotation can be built with this ctor");
- this.a = annotation;
- }
-
- public AnnotationElementValueGen(AnnotationElementValueGen value, ConstantPool cpool,boolean copyPoolEntries) {
- super(ANNOTATION,cpool);
- a = new AnnotationGen(value.getAnnotation(),cpool,copyPoolEntries);
- }
-
- public void dump(DataOutputStream dos) throws IOException {
- dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
- a.dump(dos);
- }
-
- public String stringifyValue() {
- throw new RuntimeException("Not implemented yet");
- }
-
- /**
- * Return immutable variant of this AnnotationElementValueGen
- */
- public ElementValueGen getElementValue() {
- return new AnnotationElementValueGen(this.type,a,cpGen);
- }
-
- public AnnotationGen getAnnotation() { return a;}
-
-}
public static final AnnotationGen[] NO_ANNOTATIONS = new AnnotationGen[0];
private int typeIndex;
- private List<ElementNameValuePairGen> pairs = Collections.emptyList();
+ private List<NameValuePair> pairs = Collections.emptyList();
private ConstantPool cpool;
private boolean isRuntimeVisible = false;
pairs = copyValues(a.getValues(), cpool, copyPoolEntries);
}
- private List<ElementNameValuePairGen> copyValues(List<ElementNameValuePairGen> in, ConstantPool cpool, boolean copyPoolEntries) {
- List<ElementNameValuePairGen> out = new ArrayList<ElementNameValuePairGen>();
- for (ElementNameValuePairGen nvp : in) {
- out.add(new ElementNameValuePairGen(nvp, cpool, copyPoolEntries));
+ private List<NameValuePair> copyValues(List<NameValuePair> in, ConstantPool cpool, boolean copyPoolEntries) {
+ List<NameValuePair> out = new ArrayList<NameValuePair>();
+ for (NameValuePair nvp : in) {
+ out.add(new NameValuePair(nvp, cpool, copyPoolEntries));
}
return out;
}
/**
* Retrieve an immutable version of this AnnotationGen
*/
- public AnnotationGen(ObjectType type, List<ElementNameValuePairGen> pairs, boolean runtimeVisible, ConstantPool cpool) {
+ public AnnotationGen(ObjectType type, List<NameValuePair> pairs, boolean runtimeVisible, ConstantPool cpool) {
this.cpool = cpool;
if (type != null) {
this.typeIndex = cpool.addUtf8(type.getSignature()); // Only null for funky *temporary* FakeAnnotation objects
int elemValuePairCount = dis.readUnsignedShort();
for (int i = 0; i < elemValuePairCount; i++) {
int nidx = dis.readUnsignedShort();
- a.addElementNameValuePair(new ElementNameValuePairGen(nidx, ElementValueGen.readElementValue(dis, cpool), cpool));
+ a.addElementNameValuePair(new NameValuePair(nidx, ElementValue.readElementValue(dis, cpool), cpool));
}
a.isRuntimeVisible(b);
return a;
dos.writeShort(typeIndex); // u2 index of type name in cpool
dos.writeShort(pairs.size()); // u2 element_value pair count
for (int i = 0; i < pairs.size(); i++) {
- ElementNameValuePairGen envp = pairs.get(i);
+ NameValuePair envp = pairs.get(i);
envp.dump(dos);
}
}
- public void addElementNameValuePair(ElementNameValuePairGen evp) {
+ public void addElementNameValuePair(NameValuePair evp) {
if (pairs == Collections.EMPTY_LIST) {
- pairs = new ArrayList<ElementNameValuePairGen>();
+ pairs = new ArrayList<NameValuePair>();
}
pairs.add(evp);
}
return Utility.signatureToString(getTypeSignature());
}
- public List<ElementNameValuePairGen> getValues() {
+ public List<NameValuePair> getValues() {
return pairs;
}
* @return true if the annotation has a value with the specified name and (toString'd) value
*/
public boolean hasNameValuePair(String name, String value) {
- for (ElementNameValuePairGen pair : pairs) {
+ for (NameValuePair pair : pairs) {
if (pair.getNameString().equals(name)) {
if (pair.getValue().stringifyValue().equals(value)) {
return true;
* @return true if the annotation has a value with the specified name
*/
public boolean hasNamedValue(String name) {
- for (ElementNameValuePairGen pair : pairs) {
+ for (NameValuePair pair : pairs) {
if (pair.getNameString().equals(name)) {
return true;
}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public class ArrayElementValue extends ElementValue {
+ private static final ElementValue[] NO_VALUES = new ElementValue[0];
+
+ // J5TODO: Should we make this an array or a list? A list would be easier to modify ...
+ private ElementValue[] evalues = NO_VALUES;
+
+ public ElementValue[] getElementValuesArray() {
+ return evalues;
+ }
+
+ public int getElementValuesArraySize() {
+ return evalues.length;
+ }
+
+ public ArrayElementValue(ConstantPool cp) {
+ super(ARRAY, cp);
+ }
+
+ public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool) {
+ super(type, cpool);
+ if (type != ARRAY)
+ throw new RuntimeException("Only element values of type array can be built with this ctor");
+ this.evalues = datums;
+ }
+
+ public ArrayElementValue(ArrayElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ super(ARRAY, cpool);
+ evalues = new ElementValue[value.getElementValuesArraySize()];
+ ElementValue[] in = value.getElementValuesArray();
+ for (int i = 0; i < in.length; i++) {
+ evalues[i] = ElementValue.copy(in[i], cpool, copyPoolEntries);
+ }
+ }
+
+ @Override
+ public void dump(DataOutputStream dos) throws IOException {
+ dos.writeByte(type); // u1 type of value (ARRAY == '[')
+ dos.writeShort(evalues.length);
+ for (int i = 0; i < evalues.length; i++) {
+ evalues[i].dump(dos);
+ }
+ }
+
+ @Override
+ public String stringifyValue() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("[");
+ for (int i = 0; i < evalues.length; i++) {
+ ElementValue element = evalues[i];
+ sb.append(element.stringifyValue());
+ if ((i + 1) < evalues.length)
+ sb.append(",");
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+ public void addElement(ElementValue gen) {
+ ElementValue[] old = evalues;
+ evalues = new ElementValue[evalues.length + 1];
+ System.arraycopy(old, 0, evalues, 0, old.length);
+ evalues[old.length] = gen;
+ }
+
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-
-public class ArrayElementValueGen extends ElementValueGen {
- private static final ElementValueGen[] NO_VALUES = new ElementValueGen[0];
-
- // J5TODO: Should we make this an array or a list? A list would be easier to modify ...
- private ElementValueGen[] evalues = NO_VALUES;
-
- public ElementValueGen[] getElementValuesArray() { return evalues;}
- public int getElementValuesArraySize() { return evalues.length;}
-
- public ArrayElementValueGen(ConstantPool cp) {
- super(ARRAY,cp);
- }
-
- public ArrayElementValueGen(int type, ElementValueGen[] datums, ConstantPool cpool) {
- super(type,cpool);
- if (type != ARRAY)
- throw new RuntimeException("Only element values of type array can be built with this ctor");
- this.evalues = datums;
- }
-
- /**
- * Return immutable variant of this ArrayElementValueGen
- */
- public ElementValueGen getElementValue() {
- ElementValueGen[] immutableData = new ElementValueGen[evalues.length];
- for (int i = 0; i<evalues.length;i++) {
- immutableData[i] = evalues[i];
- }
- return new ArrayElementValueGen(type,immutableData,cpGen);
- }
-
- /**
- * @param value
- * @param cpool
- */
- public ArrayElementValueGen(ArrayElementValueGen value, ConstantPool cpool,boolean copyPoolEntries) {
- super(ARRAY,cpool);
- evalues = new ElementValueGen[value.getElementValuesArraySize()];
- ElementValueGen[] in = value.getElementValuesArray();
- for (int i = 0; i < in.length; i++) {
- evalues[i]=ElementValueGen.copy(in[i],cpool,copyPoolEntries);
- }
- }
-
- public void dump(DataOutputStream dos) throws IOException {
- dos.writeByte(type); // u1 type of value (ARRAY == '[')
- dos.writeShort(evalues.length);
- for (int i =0;i<evalues.length;i++) {
- evalues[i].dump(dos);
- }
- }
-
- public String stringifyValue() {
- StringBuffer sb = new StringBuffer();
- sb.append("[");
- for (int i =0;i<evalues.length;i++) {
- ElementValueGen element = evalues[i];
- sb.append(element.stringifyValue());
- if ((i+1)<evalues.length) sb.append(",");
- }
- sb.append("]");
- return sb.toString();
- }
-
-
- public void addElement(ElementValueGen gen) {
- ElementValueGen[] old = evalues;
- evalues = new ElementValueGen[evalues.length+1];
- System.arraycopy(old,0,evalues,0,old.length);
- evalues[old.length]=gen;
- }
-
-}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ConstantUtf8;
+import org.aspectj.apache.bcel.generic.ObjectType;
+
+public class ClassElementValue extends ElementValue {
+
+ // For primitive types and string type, this points to the value entry in the cpool
+ // For 'class' this points to the class entry in the cpool
+ private int idx;
+
+ protected ClassElementValue(int typeIdx, ConstantPool cpool) {
+ super(ElementValue.CLASS, cpool);
+ this.idx = typeIdx;
+ }
+
+ public ClassElementValue(ObjectType t, ConstantPool cpool) {
+ super(ElementValue.CLASS, cpool);
+ // this.idx = cpool.addClass(t);
+ idx = cpool.addUtf8(t.getSignature());
+ }
+
+ /**
+ * Return immutable variant of this ClassElementValueGen
+ */
+ // public ElementValueGen getElementValue() {
+ // return new ClassElementValueGen(type,idx,cpGen);
+ // }
+ public ClassElementValue(ClassElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ super(CLASS, cpool);
+ if (copyPoolEntries) {
+ // idx = cpool.addClass(value.getClassString());
+ idx = cpool.addUtf8(value.getClassString());
+ } else {
+ idx = value.getIndex();
+
+ }
+ }
+
+ public int getIndex() {
+ return idx;
+ }
+
+ public String getClassString() {
+ ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
+ return cu8.getValue();
+ // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
+ // ConstantUtf8 utf8 = (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
+ // return utf8.getBytes();
+ }
+
+ @Override
+ public String stringifyValue() {
+ return getClassString();
+ }
+
+ @Override
+ public void dump(DataOutputStream dos) throws IOException {
+ dos.writeByte(type); // u1 kind of value
+ dos.writeShort(idx);
+ }
+
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ConstantUtf8;
-import org.aspectj.apache.bcel.generic.ObjectType;
-
-public class ClassElementValueGen extends ElementValueGen {
-
- // For primitive types and string type, this points to the value entry in the cpool
- // For 'class' this points to the class entry in the cpool
- private int idx;
-
- protected ClassElementValueGen(int typeIdx, ConstantPool cpool) {
- super(ElementValueGen.CLASS, cpool);
- this.idx = typeIdx;
- }
-
- public ClassElementValueGen(ObjectType t, ConstantPool cpool) {
- super(ElementValueGen.CLASS, cpool);
- // this.idx = cpool.addClass(t);
- idx = cpool.addUtf8(t.getSignature());
- }
-
- /**
- * Return immutable variant of this ClassElementValueGen
- */
- // public ElementValueGen getElementValue() {
- // return new ClassElementValueGen(type,idx,cpGen);
- // }
- public ClassElementValueGen(ClassElementValueGen value, ConstantPool cpool, boolean copyPoolEntries) {
- super(CLASS, cpool);
- if (copyPoolEntries) {
- // idx = cpool.addClass(value.getClassString());
- idx = cpool.addUtf8(value.getClassString());
- } else {
- idx = value.getIndex();
-
- }
- }
-
- public int getIndex() {
- return idx;
- }
-
- public String getClassString() {
- ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
- return cu8.getValue();
- // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
- // ConstantUtf8 utf8 = (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
- // return utf8.getBytes();
- }
-
- @Override
- public String stringifyValue() {
- return getClassString();
- }
-
- @Override
- public void dump(DataOutputStream dos) throws IOException {
- dos.writeByte(type); // u1 kind of value
- dos.writeShort(idx);
- }
-
-}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-public class ElementNameValuePairGen {
- private int nameIdx;
- private ElementValueGen value;
- private ConstantPool cpool;
-
- public ElementNameValuePairGen(ElementNameValuePairGen pair, ConstantPool cpool, boolean copyPoolEntries) {
- this.cpool = cpool;
- // J5ASSERT:
- // Could assert nvp.getNameString() points to the same thing as cpool.getConstant(nvp.getNameIndex())
- // if (!nvp.getNameString().equals(((ConstantUtf8)cpool.getConstant(nvp.getNameIndex())).getBytes())) {
- // throw new RuntimeException("envp buggered");
- // }
- if (copyPoolEntries) {
- nameIdx = cpool.addUtf8(pair.getNameString());
- } else {
- nameIdx = pair.getNameIndex();
- }
- value = ElementValueGen.copy(pair.getValue(), cpool, copyPoolEntries);
- }
-
- protected ElementNameValuePairGen(int idx, ElementValueGen value, ConstantPool cpool) {
- this.nameIdx = idx;
- this.value = value;
- this.cpool = cpool;
- }
-
- public ElementNameValuePairGen(String name, ElementValueGen value, ConstantPool cpool) {
- this.nameIdx = cpool.addUtf8(name);
- this.value = value;
- this.cpool = cpool;
- }
-
- protected void dump(DataOutputStream dos) throws IOException {
- dos.writeShort(nameIdx); // u2 name of the element
- value.dump(dos);
- }
-
- public int getNameIndex() {
- return nameIdx;
- }
-
- public final String getNameString() {
- return cpool.getConstantUtf8(nameIdx).getValue();
- }
-
- public final ElementValueGen getValue() {
- return value;
- }
-
- @Override
- public String toString() {
- StringBuffer sb = new StringBuffer();
- sb.append(getNameString()).append("=").append(value.stringifyValue());
- return sb.toString();
- }
-}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public abstract class ElementValue {
+
+ 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';
+
+ protected int type;
+ protected ConstantPool cpool;
+
+ protected ElementValue(int type, ConstantPool cpool) {
+ this.type = type;
+ this.cpool = cpool;
+ }
+
+ public int getElementValueType() {
+ return type;
+ }
+
+ public abstract String stringifyValue();
+
+ public abstract void dump(DataOutputStream dos) throws IOException;
+
+ public static ElementValue readElementValue(DataInputStream dis, ConstantPool cpGen) throws IOException {
+ int type = dis.readUnsignedByte();
+ switch (type) {
+ case 'B': // byte
+ return new SimpleElementValue(PRIMITIVE_BYTE, dis.readUnsignedShort(), cpGen);
+ case 'C': // char
+ return new SimpleElementValue(PRIMITIVE_CHAR, dis.readUnsignedShort(), cpGen);
+ case 'D': // double
+ return new SimpleElementValue(PRIMITIVE_DOUBLE, dis.readUnsignedShort(), cpGen);
+ case 'F': // float
+ return new SimpleElementValue(PRIMITIVE_FLOAT, dis.readUnsignedShort(), cpGen);
+ case 'I': // int
+ return new SimpleElementValue(PRIMITIVE_INT, dis.readUnsignedShort(), cpGen);
+ case 'J': // long
+ return new SimpleElementValue(PRIMITIVE_LONG, dis.readUnsignedShort(), cpGen);
+ case 'S': // short
+ return new SimpleElementValue(PRIMITIVE_SHORT, dis.readUnsignedShort(), cpGen);
+ case 'Z': // boolean
+ return new SimpleElementValue(PRIMITIVE_BOOLEAN, dis.readUnsignedShort(), cpGen);
+ case 's': // String
+ return new SimpleElementValue(STRING, dis.readUnsignedShort(), cpGen);
+
+ case 'e': // Enum constant
+ return new EnumElementValue(dis.readUnsignedShort(), dis.readUnsignedShort(), cpGen);
+
+ case 'c': // Class
+ return new ClassElementValue(dis.readUnsignedShort(), cpGen);
+
+ // FIXME should this be true here? or should it be the value for the containing annotation?
+ case '@': // Annotation
+ return new AnnotationElementValue(ANNOTATION, AnnotationGen.read(dis, cpGen, true), cpGen);
+
+ case '[': // Array
+ int numArrayVals = dis.readUnsignedShort();
+ ElementValue[] evalues = new ElementValue[numArrayVals];
+ for (int j = 0; j < numArrayVals; j++) {
+ evalues[j] = ElementValue.readElementValue(dis, cpGen);
+ }
+ return new ArrayElementValue(ARRAY, evalues, cpGen);
+
+ default:
+ throw new RuntimeException("Unexpected element value kind in annotation: " + type);
+ }
+ }
+
+ protected ConstantPool getConstantPool() {
+ return cpool;
+ }
+
+ /**
+ * Creates an (modifiable) ElementValueGen copy of an (immutable) ElementValue - constant pool is assumed correct.
+ */
+ public static ElementValue copy(ElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ switch (value.getElementValueType()) {
+ case 'B': // byte
+ case 'C': // char
+ case 'D': // double
+ case 'F': // float
+ case 'I': // int
+ case 'J': // long
+ case 'S': // short
+ case 'Z': // boolean
+ case 's': // String
+ return new SimpleElementValue((SimpleElementValue) value, cpool, copyPoolEntries);
+
+ case 'e': // Enum constant
+ return new EnumElementValue((EnumElementValue) value, cpool, copyPoolEntries);
+
+ case '@': // Annotation
+ return new AnnotationElementValue((AnnotationElementValue) value, cpool, copyPoolEntries);
+
+ case '[': // Array
+ return new ArrayElementValue((ArrayElementValue) value, cpool, copyPoolEntries);
+
+ case 'c': // Class
+ return new ClassElementValue((ClassElementValue) value, cpool, copyPoolEntries);
+
+ default:
+ throw new RuntimeException("Not implemented yet! (" + value.getElementValueType() + ")");
+ }
+ }
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-public abstract class ElementValueGen {
-
- protected int type;
- protected ConstantPool cpGen;
-
-
- protected ElementValueGen(int type,ConstantPool cpGen) {
- this.type = type;
- this.cpGen = cpGen;
- }
-
-// /**
-// * Subtypes return an immutable variant of the ElementValueGen
-// */
-// public abstract ElementValueGen getElementValue();
-
- public int getElementValueType() {
- return type;
- }
-
- public abstract String stringifyValue();
- public abstract void dump(DataOutputStream dos) throws IOException;
-
- 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 static ElementValueGen readElementValue(DataInputStream dis,ConstantPool cpGen) throws IOException {
- int type= dis.readUnsignedByte();
- switch (type) {
- case 'B': // byte
- return new SimpleElementValueGen(PRIMITIVE_BYTE,dis.readUnsignedShort(),cpGen);
- case 'C': // char
- return new SimpleElementValueGen(PRIMITIVE_CHAR,dis.readUnsignedShort(),cpGen);
- case 'D': // double
- return new SimpleElementValueGen(PRIMITIVE_DOUBLE,dis.readUnsignedShort(),cpGen);
- case 'F': // float
- return new SimpleElementValueGen(PRIMITIVE_FLOAT,dis.readUnsignedShort(),cpGen);
- case 'I': // int
- return new SimpleElementValueGen(PRIMITIVE_INT,dis.readUnsignedShort(),cpGen);
- case 'J': // long
- return new SimpleElementValueGen(PRIMITIVE_LONG,dis.readUnsignedShort(),cpGen);
- case 'S': // short
- return new SimpleElementValueGen(PRIMITIVE_SHORT,dis.readUnsignedShort(),cpGen);
- case 'Z': // boolean
- return new SimpleElementValueGen(PRIMITIVE_BOOLEAN,dis.readUnsignedShort(),cpGen);
- case 's': // String
- return new SimpleElementValueGen(STRING,dis.readUnsignedShort(),cpGen);
-
- case 'e': // Enum constant
- return new EnumElementValueGen(dis.readUnsignedShort(),dis.readUnsignedShort(),cpGen);
-
- case 'c': // Class
- return new ClassElementValueGen(dis.readUnsignedShort(),cpGen);
-
- // FIXME should this be true here? or should it be the value for the containing annotation?
- case '@': // Annotation
- return new AnnotationElementValueGen(ANNOTATION,AnnotationGen.read(dis,cpGen,true),cpGen);
-
- case '[': // Array
- int numArrayVals = dis.readUnsignedShort();
- ElementValueGen[] evalues = new ElementValueGen[numArrayVals];
- for (int j=0;j<numArrayVals;j++) {
- evalues[j] = ElementValueGen.readElementValue(dis,cpGen);
- }
- return new ArrayElementValueGen(ARRAY,evalues,cpGen);
-
- default:
- throw new RuntimeException("Unexpected element value kind in annotation: "+type);
- }
- }
-
- protected ConstantPool getConstantPool() {
- return cpGen;
- }
-
- /**
- * Creates an (modifiable) ElementValueGen copy of an (immutable) ElementValue - constant pool is assumed correct.
- */
- public static ElementValueGen copy(ElementValueGen value,ConstantPool cpool,boolean copyPoolEntries) {
- switch (value.getElementValueType()) {
- case 'B': // byte
- case 'C': // char
- case 'D': // double
- case 'F': // float
- case 'I': // int
- case 'J': // long
- case 'S': // short
- case 'Z': // boolean
- case 's': // String
- return new SimpleElementValueGen((SimpleElementValueGen)value,cpool,copyPoolEntries);
-
- case 'e': // Enum constant
- return new EnumElementValueGen((EnumElementValueGen)value,cpool,copyPoolEntries);
-
- case '@': // Annotation
- return new AnnotationElementValueGen((AnnotationElementValueGen)value,cpool,copyPoolEntries);
-
- case '[': // Array
- return new ArrayElementValueGen((ArrayElementValueGen)value,cpool,copyPoolEntries);
-
- case 'c': // Class
- return new ClassElementValueGen((ClassElementValueGen)value,cpool,copyPoolEntries);
-
- default:
- throw new RuntimeException("Not implemented yet! ("+value.getElementValueType()+")");
- }
- }
-}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ConstantUtf8;
+import org.aspectj.apache.bcel.generic.ObjectType;
+
+public class EnumElementValue extends ElementValue {
+
+ // For enum types, these two indices point to the type and value
+ private int typeIdx;
+ private int valueIdx;
+
+ /**
+ * This ctor assumes the constant pool already contains the right type and value - as indicated by typeIdx and valueIdx. This
+ * ctor is used for deserialization
+ */
+ protected EnumElementValue(int typeIdx, int valueIdx, ConstantPool cpool) {
+ super(ElementValue.ENUM_CONSTANT, cpool);
+ if (type != ENUM_CONSTANT)
+ throw new RuntimeException("Only element values of type enum can be built with this ctor");
+ this.typeIdx = typeIdx;
+ this.valueIdx = valueIdx;
+ }
+
+ // /**
+ // * Return immutable variant of this EnumElementValue
+ // */
+ // public ElementValueGen getElementValue() {
+ // System.err.println("Duplicating value: "+getEnumTypeString()+":"+getEnumValueString());
+ // return new EnumElementValueGen(type,typeIdx,valueIdx,cpGen);
+ // }
+
+ public EnumElementValue(ObjectType t, String value, ConstantPool cpool) {
+ super(ElementValue.ENUM_CONSTANT, cpool);
+ typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t);
+ valueIdx = cpool.addUtf8(value);// was addString(value);
+ }
+
+ public EnumElementValue(EnumElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ super(ENUM_CONSTANT, cpool);
+ if (copyPoolEntries) {
+ typeIdx = cpool.addUtf8(value.getEnumTypeString());// was addClass(value.getEnumTypeString());
+ valueIdx = cpool.addUtf8(value.getEnumValueString()); // was addString(value.getEnumValueString());
+ } else {
+ typeIdx = value.getTypeIndex();
+ valueIdx = value.getValueIndex();
+ }
+ }
+
+ @Override
+ public void dump(DataOutputStream dos) throws IOException {
+ dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
+ dos.writeShort(typeIdx); // u2
+ dos.writeShort(valueIdx); // u2
+ }
+
+ /**
+ * return signature and value, something like Lp/Color;RED
+ */
+ @Override
+ public String stringifyValue() {
+ StringBuffer sb = new StringBuffer();
+ ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(typeIdx, Constants.CONSTANT_Utf8);
+ sb.append(cu8.getValue());
+ cu8 = (ConstantUtf8) cpool.getConstant(valueIdx, Constants.CONSTANT_Utf8);
+ sb.append(cu8.getValue());
+ return sb.toString();
+ }
+
+ // BCELBUG: Should we need to call utility.signatureToString() on the output here?
+ public String getEnumTypeString() {
+ // Constant cc = getConstantPool().getConstant(typeIdx);
+ // ConstantClass cu8 = (ConstantClass)getConstantPool().getConstant(typeIdx);
+ // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
+ return ((ConstantUtf8) getConstantPool().getConstant(typeIdx)).getValue();
+ // return Utility.signatureToString(cu8.getBytes());
+ }
+
+ public String getEnumValueString() {
+ return ((ConstantUtf8) getConstantPool().getConstant(valueIdx)).getValue();
+ // ConstantString cu8 = (ConstantString)getConstantPool().getConstant(valueIdx);
+ // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
+ }
+
+ public int getValueIndex() {
+ return valueIdx;
+ }
+
+ public int getTypeIndex() {
+ return typeIdx;
+ }
+
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ConstantUtf8;
-import org.aspectj.apache.bcel.generic.ObjectType;
-
-public class EnumElementValueGen extends ElementValueGen {
-
- // For enum types, these two indices point to the type and value
- private int typeIdx;
- private int valueIdx;
-
- /**
- * This ctor assumes the constant pool already contains the right type and value - as indicated by typeIdx and valueIdx. This
- * ctor is used for deserialization
- */
- protected EnumElementValueGen(int typeIdx, int valueIdx, ConstantPool cpool) {
- super(ElementValueGen.ENUM_CONSTANT, cpool);
- if (type != ENUM_CONSTANT)
- throw new RuntimeException("Only element values of type enum can be built with this ctor");
- this.typeIdx = typeIdx;
- this.valueIdx = valueIdx;
- }
-
- // /**
- // * Return immutable variant of this EnumElementValue
- // */
- // public ElementValueGen getElementValue() {
- // System.err.println("Duplicating value: "+getEnumTypeString()+":"+getEnumValueString());
- // return new EnumElementValueGen(type,typeIdx,valueIdx,cpGen);
- // }
-
- public EnumElementValueGen(ObjectType t, String value, ConstantPool cpool) {
- super(ElementValueGen.ENUM_CONSTANT, cpool);
- typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t);
- valueIdx = cpool.addUtf8(value);// was addString(value);
- }
-
- public EnumElementValueGen(EnumElementValueGen value, ConstantPool cpool, boolean copyPoolEntries) {
- super(ENUM_CONSTANT, cpool);
- if (copyPoolEntries) {
- typeIdx = cpool.addUtf8(value.getEnumTypeString());// was addClass(value.getEnumTypeString());
- valueIdx = cpool.addUtf8(value.getEnumValueString()); // was addString(value.getEnumValueString());
- } else {
- typeIdx = value.getTypeIndex();
- valueIdx = value.getValueIndex();
- }
- }
-
- @Override
- public void dump(DataOutputStream dos) throws IOException {
- dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
- dos.writeShort(typeIdx); // u2
- dos.writeShort(valueIdx); // u2
- }
-
- /**
- * return signature and value, something like Lp/Color;RED
- */
- @Override
- public String stringifyValue() {
- StringBuffer sb = new StringBuffer();
- ConstantUtf8 cu8 = (ConstantUtf8) cpGen.getConstant(typeIdx, Constants.CONSTANT_Utf8);
- sb.append(cu8.getValue());
- cu8 = (ConstantUtf8) cpGen.getConstant(valueIdx, Constants.CONSTANT_Utf8);
- sb.append(cu8.getValue());
- return sb.toString();
- }
-
- // BCELBUG: Should we need to call utility.signatureToString() on the output here?
- public String getEnumTypeString() {
- // Constant cc = getConstantPool().getConstant(typeIdx);
- // ConstantClass cu8 = (ConstantClass)getConstantPool().getConstant(typeIdx);
- // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getNameIndex())).getBytes();
- return ((ConstantUtf8) getConstantPool().getConstant(typeIdx)).getValue();
- // return Utility.signatureToString(cu8.getBytes());
- }
-
- public String getEnumValueString() {
- return ((ConstantUtf8) getConstantPool().getConstant(valueIdx)).getValue();
- // ConstantString cu8 = (ConstantString)getConstantPool().getConstant(valueIdx);
- // return ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
- }
-
- public int getValueIndex() {
- return valueIdx;
- }
-
- public int getTypeIndex() {
- return typeIdx;
- }
-
-}
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public class NameValuePair {
+ private int nameIdx;
+ private ElementValue value;
+ private ConstantPool cpool;
+
+ public NameValuePair(NameValuePair pair, ConstantPool cpool, boolean copyPoolEntries) {
+ this.cpool = cpool;
+ // J5ASSERT:
+ // Could assert nvp.getNameString() points to the same thing as cpool.getConstant(nvp.getNameIndex())
+ // if (!nvp.getNameString().equals(((ConstantUtf8)cpool.getConstant(nvp.getNameIndex())).getBytes())) {
+ // throw new RuntimeException("envp buggered");
+ // }
+ if (copyPoolEntries) {
+ nameIdx = cpool.addUtf8(pair.getNameString());
+ } else {
+ nameIdx = pair.getNameIndex();
+ }
+ value = ElementValue.copy(pair.getValue(), cpool, copyPoolEntries);
+ }
+
+ protected NameValuePair(int idx, ElementValue value, ConstantPool cpool) {
+ this.nameIdx = idx;
+ this.value = value;
+ this.cpool = cpool;
+ }
+
+ public NameValuePair(String name, ElementValue value, ConstantPool cpool) {
+ this.nameIdx = cpool.addUtf8(name);
+ this.value = value;
+ this.cpool = cpool;
+ }
+
+ protected void dump(DataOutputStream dos) throws IOException {
+ dos.writeShort(nameIdx); // u2 name of the element
+ value.dump(dos);
+ }
+
+ public int getNameIndex() {
+ return nameIdx;
+ }
+
+ public final String getNameString() {
+ return cpool.getConstantUtf8(nameIdx).getValue();
+ }
+
+ public final ElementValue getValue() {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getNameString()).append("=").append(value.stringifyValue());
+ return sb.toString();
+ }
+}
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public abstract class RuntimeAnnos extends Attribute {
+
+ private List<AnnotationGen> annotations;
+ private boolean visible;
+
+ // Keep just a byte stream of the data until someone actually asks for it
+ private boolean inflated = false;
+ private byte[] annotation_data;
+
+ public RuntimeAnnos(byte attrid, boolean visible, int nameIdx, int len, ConstantPool cpool) {
+ super(attrid, nameIdx, len, cpool);
+ this.visible = visible;
+ annotations = new ArrayList<AnnotationGen>();
+ }
+
+ public RuntimeAnnos(byte attrid, boolean visible, int nameIdx, int len, byte[] data, ConstantPool cpool) {
+ super(attrid, nameIdx, len, cpool);
+ this.visible = visible;
+ annotations = new ArrayList<AnnotationGen>();
+ annotation_data = data;
+ }
+
+ public List<AnnotationGen> getAnnotations() {
+ if (!inflated)
+ inflate();
+ return annotations;
+ }
+
+ public boolean areVisible() {
+ return visible;
+ }
+
+ protected void readAnnotations(DataInputStream dis, ConstantPool cpool) throws IOException {
+ annotation_data = new byte[length];
+ dis.read(annotation_data, 0, length);
+ }
+
+ protected void writeAnnotations(DataOutputStream dos) throws IOException {
+ if (!inflated) {
+ dos.write(annotation_data, 0, length);
+ } else {
+ dos.writeShort(annotations.size());
+ for (Iterator<AnnotationGen> i = annotations.iterator(); i.hasNext();) {
+ AnnotationGen ann = i.next();
+ ann.dump(dos);
+ }
+ }
+ }
+
+ private void inflate() {
+ try {
+ DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data));
+ int numberOfAnnotations = dis.readUnsignedShort();
+ for (int i = 0; i < numberOfAnnotations; i++) {
+ annotations.add(AnnotationGen.read(dis, getConstantPool(), visible));
+ }
+ dis.close();
+ inflated = true;
+ } catch (IOException ioe) {
+ throw new RuntimeException("Unabled to inflate annotation data, badly formed? ");
+ }
+ }
+
+ /** FOR TESTING ONLY: Tells you if the annotations have been inflated to an object graph */
+ public boolean isInflated() {
+ return inflated;
+ }
+
+}
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-
-public abstract class RuntimeAnnotations extends Attribute {
-
- private List /*Annotation*/<AnnotationGen> annotations;
- private boolean visible;
-
- // Keep just a byte stream of the data until someone actually asks for it
- private boolean inflated = false;
- private byte[] annotation_data;
-
- public RuntimeAnnotations(byte attrid, boolean visible,
- int nameIdx, int len,
- ConstantPool cpool) {
- super(attrid,nameIdx,len,cpool);
- this.visible = visible;
- annotations = new ArrayList<AnnotationGen>();
- }
-
- public RuntimeAnnotations(byte attrid,boolean visible,int nameIdx,int len,byte[] data,ConstantPool cpool) {
- super(attrid,nameIdx,len,cpool);
- this.visible = visible;
- annotations = new ArrayList<AnnotationGen>();
- annotation_data = data;
- }
-
- public List<AnnotationGen> getAnnotations() {
- if (!inflated) inflate();
- return annotations;
- }
-
- public boolean areVisible() {
- return visible;
- }
-
- protected void readAnnotations(DataInputStream dis,ConstantPool cpool) throws IOException {
- annotation_data = new byte[length];
- dis.read(annotation_data,0,length);
- }
-
- protected void writeAnnotations(DataOutputStream dos) throws IOException {
- if (!inflated) {
- dos.write(annotation_data,0,length);
- } else {
- dos.writeShort(annotations.size());
- for (Iterator<AnnotationGen> i = annotations.iterator(); i.hasNext();) {
- AnnotationGen ann = i.next();
- ann.dump(dos);
- }
- }
- }
-
- private void inflate() {
- try {
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data));
- int numberOfAnnotations = dis.readUnsignedShort();
- for (int i = 0 ;i<numberOfAnnotations;i++) {
- annotations.add(AnnotationGen.read(dis,getConstantPool(),visible));
- }
- dis.close();
- inflated = true;
- } catch (IOException ioe) {
- throw new RuntimeException("Unabled to inflate annotation data, badly formed? ");
- }
- }
-
- /** FOR TESTING ONLY: Tells you if the annotations have been inflated to an object graph */
- public boolean isInflated() {
- return inflated;
- }
-
-}
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ClassVisitor;
+
+public class RuntimeInvisAnnos extends RuntimeAnnos {
+
+ public RuntimeInvisAnnos(int nameIdx, int len, ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, false, nameIdx, len, cpool);
+ }
+
+ public RuntimeInvisAnnos(int nameIdx, int len,
+ DataInputStream dis,ConstantPool cpool) throws IOException {
+ this(nameIdx, len, cpool);
+ readAnnotations(dis,cpool);
+ }
+
+ public RuntimeInvisAnnos(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS,false,nameIndex,len,rvaData,cpool);
+ }
+
+ public void accept(ClassVisitor v) {
+ v.visitRuntimeInvisibleAnnotations(this);
+ }
+
+ public final void dump(DataOutputStream dos) throws IOException {
+ super.dump(dos);
+ writeAnnotations(dos);
+ }
+
+ public Attribute copy(ConstantPool constant_pool) {
+ throw new RuntimeException("Not implemented yet!");
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ClassVisitor;
+
+public class RuntimeInvisParamAnnos extends RuntimeParamAnnos {
+
+ public RuntimeInvisParamAnnos(int nameIdx, int len, ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, false, nameIdx, len, cpool);
+ }
+
+ public RuntimeInvisParamAnnos(int nameIdx, int len,
+ DataInputStream dis,ConstantPool cpool) throws IOException {
+ this(nameIdx, len, cpool);
+ readParameterAnnotations(dis,cpool);
+ }
+
+ public RuntimeInvisParamAnnos(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,false,nameIndex,len,rvaData,cpool);
+ }
+
+ public void accept(ClassVisitor v) {
+ v.visitRuntimeInvisibleParameterAnnotations(this);
+ }
+
+ public Attribute copy(ConstantPool constant_pool) {
+ throw new RuntimeException("Not implemented yet!");
+ }
+}
\ No newline at end of file
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ClassVisitor;
-
-public class RuntimeInvisibleAnnotations extends RuntimeAnnotations {
-
- public RuntimeInvisibleAnnotations(int nameIdx, int len, ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, false, nameIdx, len, cpool);
- }
-
- public RuntimeInvisibleAnnotations(int nameIdx, int len,
- DataInputStream dis,ConstantPool cpool) throws IOException {
- this(nameIdx, len, cpool);
- readAnnotations(dis,cpool);
- }
-
- public RuntimeInvisibleAnnotations(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS,false,nameIndex,len,rvaData,cpool);
- }
-
- public void accept(ClassVisitor v) {
- v.visitRuntimeInvisibleAnnotations(this);
- }
-
- public final void dump(DataOutputStream dos) throws IOException {
- super.dump(dos);
- writeAnnotations(dos);
- }
-
- public Attribute copy(ConstantPool constant_pool) {
- throw new RuntimeException("Not implemented yet!");
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ClassVisitor;
-
-public class RuntimeInvisibleParameterAnnotations extends RuntimeParameterAnnotations {
-
- public RuntimeInvisibleParameterAnnotations(int nameIdx, int len, ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, false, nameIdx, len, cpool);
- }
-
- public RuntimeInvisibleParameterAnnotations(int nameIdx, int len,
- DataInputStream dis,ConstantPool cpool) throws IOException {
- this(nameIdx, len, cpool);
- readParameterAnnotations(dis,cpool);
- }
-
- public RuntimeInvisibleParameterAnnotations(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS,false,nameIndex,len,rvaData,cpool);
- }
-
- public void accept(ClassVisitor v) {
- v.visitRuntimeInvisibleParameterAnnotations(this);
- }
-
- public Attribute copy(ConstantPool constant_pool) {
- throw new RuntimeException("Not implemented yet!");
- }
-}
\ No newline at end of file
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+
+public abstract class RuntimeParamAnnos extends Attribute {
+
+ private List /*Annotation[]*/<AnnotationGen[]> parameterAnnotations;
+ private boolean visible;
+
+
+ // Keep just a byte stream of the data until someone actually asks for it
+ private boolean inflated = false;
+ private byte[] annotation_data;
+
+
+ public RuntimeParamAnnos(byte attrid, boolean visible,
+ int nameIdx, int len, ConstantPool cpool) {
+ super(attrid,nameIdx,len,cpool);
+ this.visible = visible;
+ parameterAnnotations = new ArrayList<AnnotationGen[]>();
+ }
+
+ public RuntimeParamAnnos(byte attrid,boolean visible,int nameIdx,int len,byte[] data,ConstantPool cpool) {
+ super(attrid,nameIdx,len,cpool);
+ this.visible = visible;
+ parameterAnnotations = new ArrayList<AnnotationGen[]>();
+ annotation_data = data;
+ }
+
+ public final void dump(DataOutputStream dos) throws IOException {
+ super.dump(dos);
+ writeAnnotations(dos);
+ }
+
+ public Attribute copy(ConstantPool constant_pool) {
+ throw new RuntimeException("Not implemented yet!");
+ }
+
+ /** Return a list of Annotation[] - each list entry contains the annotations for one parameter */
+ public List /*Annotation[]*/<AnnotationGen[]> getParameterAnnotations() {
+ if (!inflated) inflate();
+ return parameterAnnotations;
+ }
+
+ public AnnotationGen[] getAnnotationsOnParameter(int parameterIndex) {
+ if (!inflated) inflate();
+ // This may happen. In a ctor for a non static inner type the compiler
+ // may have added an extra parameter to the generated ctor (the parameter
+ // contains the instance of the outer class) - in this case
+ // it may appear that there are more parameters than there are entries
+ // in the parameter annotations array
+ if (parameterIndex>=parameterAnnotations.size()) {
+ return AnnotationGen.NO_ANNOTATIONS;
+ }
+ return parameterAnnotations.get(parameterIndex);
+ }
+
+ public boolean areVisible() {
+ return visible;
+ }
+
+ protected void readParameterAnnotations(DataInputStream dis,ConstantPool cpool) throws IOException {
+ annotation_data = new byte[length];
+ dis.read(annotation_data,0,length);
+ }
+
+ private void inflate() {
+ try {
+ DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data));
+ int numParameters = dis.readUnsignedByte();
+ for (int i=0; i<numParameters; i++) {
+ int numAnnotations = dis.readUnsignedShort();
+ AnnotationGen[] annotations = new AnnotationGen[numAnnotations];
+ for (int j=0; j<numAnnotations; j++) {
+ annotations[j] = AnnotationGen.read(dis,getConstantPool(),visible);
+ }
+ parameterAnnotations.add(annotations);
+ }
+ inflated = true;
+ } catch (IOException ioe) {
+ throw new RuntimeException("Unabled to inflate annotation data, badly formed?");
+ }
+ }
+
+
+ protected void writeAnnotations(DataOutputStream dos) throws IOException {
+ if (!inflated) {
+ dos.write(annotation_data,0,length);
+ } else {
+ dos.writeByte(parameterAnnotations.size());
+ for (int i=0; i<parameterAnnotations.size(); i++) {
+ AnnotationGen[] annotations = parameterAnnotations.get(i);
+ dos.writeShort(annotations.length);
+ for (int j=0; j<annotations.length;j++) {
+ annotations[j].dump(dos);
+ }
+ }
+ }
+ }
+
+ /** FOR TESTING ONLY: Tells you if the annotations have been inflated to an object graph */
+ public boolean isInflated() {
+ return inflated;
+ }
+
+ public String toString() {
+ return "Runtime"+(visible?"Visible":"Invisible")+"ParameterAnnotations ["+(inflated?"inflated":"not yet inflated")+"]";
+ }
+
+}
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-
-public abstract class RuntimeParameterAnnotations extends Attribute {
-
- private List /*Annotation[]*/<AnnotationGen[]> parameterAnnotations;
- private boolean visible;
-
-
- // Keep just a byte stream of the data until someone actually asks for it
- private boolean inflated = false;
- private byte[] annotation_data;
-
-
- public RuntimeParameterAnnotations(byte attrid, boolean visible,
- int nameIdx, int len, ConstantPool cpool) {
- super(attrid,nameIdx,len,cpool);
- this.visible = visible;
- parameterAnnotations = new ArrayList<AnnotationGen[]>();
- }
-
- public RuntimeParameterAnnotations(byte attrid,boolean visible,int nameIdx,int len,byte[] data,ConstantPool cpool) {
- super(attrid,nameIdx,len,cpool);
- this.visible = visible;
- parameterAnnotations = new ArrayList<AnnotationGen[]>();
- annotation_data = data;
- }
-
- public final void dump(DataOutputStream dos) throws IOException {
- super.dump(dos);
- writeAnnotations(dos);
- }
-
- public Attribute copy(ConstantPool constant_pool) {
- throw new RuntimeException("Not implemented yet!");
- }
-
- /** Return a list of Annotation[] - each list entry contains the annotations for one parameter */
- public List /*Annotation[]*/<AnnotationGen[]> getParameterAnnotations() {
- if (!inflated) inflate();
- return parameterAnnotations;
- }
-
- public AnnotationGen[] getAnnotationsOnParameter(int parameterIndex) {
- if (!inflated) inflate();
- // This may happen. In a ctor for a non static inner type the compiler
- // may have added an extra parameter to the generated ctor (the parameter
- // contains the instance of the outer class) - in this case
- // it may appear that there are more parameters than there are entries
- // in the parameter annotations array
- if (parameterIndex>=parameterAnnotations.size()) {
- return AnnotationGen.NO_ANNOTATIONS;
- }
- return parameterAnnotations.get(parameterIndex);
- }
-
- public boolean areVisible() {
- return visible;
- }
-
- protected void readParameterAnnotations(DataInputStream dis,ConstantPool cpool) throws IOException {
- annotation_data = new byte[length];
- dis.read(annotation_data,0,length);
- }
-
- private void inflate() {
- try {
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(annotation_data));
- int numParameters = dis.readUnsignedByte();
- for (int i=0; i<numParameters; i++) {
- int numAnnotations = dis.readUnsignedShort();
- AnnotationGen[] annotations = new AnnotationGen[numAnnotations];
- for (int j=0; j<numAnnotations; j++) {
- annotations[j] = AnnotationGen.read(dis,getConstantPool(),visible);
- }
- parameterAnnotations.add(annotations);
- }
- inflated = true;
- } catch (IOException ioe) {
- throw new RuntimeException("Unabled to inflate annotation data, badly formed?");
- }
- }
-
-
- protected void writeAnnotations(DataOutputStream dos) throws IOException {
- if (!inflated) {
- dos.write(annotation_data,0,length);
- } else {
- dos.writeByte(parameterAnnotations.size());
- for (int i=0; i<parameterAnnotations.size(); i++) {
- AnnotationGen[] annotations = parameterAnnotations.get(i);
- dos.writeShort(annotations.length);
- for (int j=0; j<annotations.length;j++) {
- annotations[j].dump(dos);
- }
- }
- }
- }
-
- /** FOR TESTING ONLY: Tells you if the annotations have been inflated to an object graph */
- public boolean isInflated() {
- return inflated;
- }
-
- public String toString() {
- return "Runtime"+(visible?"Visible":"Invisible")+"ParameterAnnotations ["+(inflated?"inflated":"not yet inflated")+"]";
- }
-
-}
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ClassVisitor;
+
+public class RuntimeVisAnnos extends RuntimeAnnos {
+
+ public RuntimeVisAnnos(int nameIdx, int len, ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, true, nameIdx, len, cpool);
+ }
+
+ public RuntimeVisAnnos(int nameIdx, int len,
+ DataInputStream dis,ConstantPool cpool) throws IOException {
+ this(nameIdx, len, cpool);
+ readAnnotations(dis,cpool);
+ }
+
+ public RuntimeVisAnnos(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS,true,nameIndex,len,rvaData,cpool);
+ }
+
+ public void accept(ClassVisitor v) {
+ v.visitRuntimeVisibleAnnotations(this);
+ }
+
+ public final void dump(DataOutputStream dos) throws IOException {
+ super.dump(dos);
+ writeAnnotations(dos);
+ }
+
+ public Attribute copy(ConstantPool constant_pool) {
+ throw new RuntimeException("Not implemented yet!");
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ClassVisitor;
+
+public class RuntimeVisParamAnnos extends RuntimeParamAnnos {
+
+ public RuntimeVisParamAnnos(int nameIdx, int len, ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, true, nameIdx, len, cpool);
+ }
+
+ public RuntimeVisParamAnnos(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
+ super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,true,nameIndex,len,rvaData,cpool);
+ }
+
+ public RuntimeVisParamAnnos(int nameIdx, int len,
+ DataInputStream dis,ConstantPool cpool) throws IOException {
+ this(nameIdx, len, cpool);
+ readParameterAnnotations(dis,cpool);
+ }
+
+ public void accept(ClassVisitor v) {
+ v.visitRuntimeVisibleParameterAnnotations(this);
+ }
+
+ public Attribute copy(ConstantPool constant_pool) {
+ throw new RuntimeException("Not implemented yet!");
+ }
+}
\ No newline at end of file
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ClassVisitor;
-
-public class RuntimeVisibleAnnotations extends RuntimeAnnotations {
-
- public RuntimeVisibleAnnotations(int nameIdx, int len, ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, true, nameIdx, len, cpool);
- }
-
- public RuntimeVisibleAnnotations(int nameIdx, int len,
- DataInputStream dis,ConstantPool cpool) throws IOException {
- this(nameIdx, len, cpool);
- readAnnotations(dis,cpool);
- }
-
- public RuntimeVisibleAnnotations(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS,true,nameIndex,len,rvaData,cpool);
- }
-
- public void accept(ClassVisitor v) {
- v.visitRuntimeVisibleAnnotations(this);
- }
-
- public final void dump(DataOutputStream dos) throws IOException {
- super.dump(dos);
- writeAnnotations(dos);
- }
-
- public Attribute copy(ConstantPool constant_pool) {
- throw new RuntimeException("Not implemented yet!");
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.Attribute;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ClassVisitor;
-
-public class RuntimeVisibleParameterAnnotations extends RuntimeParameterAnnotations {
-
- public RuntimeVisibleParameterAnnotations(int nameIdx, int len, ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, true, nameIdx, len, cpool);
- }
-
- public RuntimeVisibleParameterAnnotations(int nameIndex, int len, byte[] rvaData,ConstantPool cpool) {
- super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,true,nameIndex,len,rvaData,cpool);
- }
-
- public RuntimeVisibleParameterAnnotations(int nameIdx, int len,
- DataInputStream dis,ConstantPool cpool) throws IOException {
- this(nameIdx, len, cpool);
- readParameterAnnotations(dis,cpool);
- }
-
- public void accept(ClassVisitor v) {
- v.visitRuntimeVisibleParameterAnnotations(this);
- }
-
- public Attribute copy(ConstantPool constant_pool) {
- throw new RuntimeException("Not implemented yet!");
- }
-}
\ No newline at end of file
--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * 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 - initial implementation {date}
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.annotation;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.ConstantDouble;
+import org.aspectj.apache.bcel.classfile.ConstantFloat;
+import org.aspectj.apache.bcel.classfile.ConstantInteger;
+import org.aspectj.apache.bcel.classfile.ConstantLong;
+import org.aspectj.apache.bcel.classfile.ConstantPool;
+import org.aspectj.apache.bcel.classfile.ConstantUtf8;
+
+public class SimpleElementValue extends ElementValue {
+
+ // For primitive types and string type, this points to the value entry in the cpGen
+ // For 'class' this points to the class entry in the cpGen
+ private int idx;
+
+ // ctors for each supported type... type could be inferred but for now lets
+ // force it to be passed
+
+ /**
+ * Protected ctor used for deserialization, doesn't *put* an entry in the constant pool, assumes the one at the supplied index
+ * is correct.
+ */
+ protected SimpleElementValue(int type, int idx, ConstantPool cpGen) {
+ super(type, cpGen);
+ this.idx = idx;
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, int value) {
+ super(type, cpGen);
+ idx = cpGen.addInteger(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, long value) {
+ super(type, cpGen);
+ idx = cpGen.addLong(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, double value) {
+ super(type, cpGen);
+ idx = cpGen.addDouble(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, float value) {
+ super(type, cpGen);
+ idx = cpGen.addFloat(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, short value) {
+ super(type, cpGen);
+ idx = cpGen.addInteger(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, byte value) {
+ super(type, cpGen);
+ idx = cpGen.addInteger(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, char value) {
+ super(type, cpGen);
+ idx = cpGen.addInteger(value);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, boolean value) {
+ super(type, cpGen);
+ if (value)
+ idx = cpGen.addInteger(1);
+ else
+ idx = cpGen.addInteger(0);
+ }
+
+ public SimpleElementValue(int type, ConstantPool cpGen, String value) {
+ super(type, cpGen);
+ idx = cpGen.addUtf8(value);
+ }
+
+ public byte getValueByte() {
+ if (type != PRIMITIVE_BYTE)
+ throw new RuntimeException("Dont call getValueByte() on a non BYTE ElementValue");
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(idx, Constants.CONSTANT_Integer);
+ return (byte) c.getIntValue();
+ }
+
+ public char getValueChar() {
+ if (type != PRIMITIVE_CHAR)
+ throw new RuntimeException("Dont call getValueChar() on a non CHAR ElementValue");
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(idx, Constants.CONSTANT_Integer);
+ return (char) c.getIntValue();
+ }
+
+ public long getValueLong() {
+ if (type != PRIMITIVE_LONG)
+ throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue");
+ ConstantLong j = (ConstantLong) cpool.getConstant(idx);
+ return j.getValue();
+ }
+
+ public float getValueFloat() {
+ if (type != PRIMITIVE_FLOAT)
+ throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue");
+ ConstantFloat f = (ConstantFloat) cpool.getConstant(idx);
+ return f.getValue();
+ }
+
+ public double getValueDouble() {
+ if (type != PRIMITIVE_DOUBLE)
+ throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue");
+ ConstantDouble d = (ConstantDouble) cpool.getConstant(idx);
+ return d.getValue();
+ }
+
+ public boolean getValueBoolean() {
+ if (type != PRIMITIVE_BOOLEAN)
+ throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue");
+ ConstantInteger bo = (ConstantInteger) cpool.getConstant(idx);
+ return (bo.getValue() != 0);
+ }
+
+ public short getValueShort() {
+ if (type != PRIMITIVE_SHORT)
+ throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue");
+ ConstantInteger s = (ConstantInteger) cpool.getConstant(idx);
+ return (short) s.getIntValue();
+ }
+
+ /**
+ * The boolean controls whether we copy info from the 'old' constant pool to the 'new'. You need to use this ctor if the
+ * annotation is being copied from one file to another.
+ */
+ public SimpleElementValue(SimpleElementValue value, ConstantPool cpool, boolean copyPoolEntries) {
+ super(value.getElementValueType(), cpool);
+ if (!copyPoolEntries) {
+ // J5ASSERT: Could assert value.stringifyValue() is the same as
+ // cpool.getConstant(SimpleElementValuevalue.getIndex())
+ idx = value.getIndex();
+ } else {
+ switch (value.getElementValueType()) {
+ case STRING:
+ idx = cpool.addUtf8(value.getValueString());
+ break;
+ case PRIMITIVE_INT:
+ idx = cpool.addInteger(value.getValueInt());
+ break;
+ case PRIMITIVE_BYTE:
+ idx = cpool.addInteger(value.getValueByte());
+ break;
+ case PRIMITIVE_CHAR:
+ idx = cpool.addInteger(value.getValueChar());
+ break;
+ case PRIMITIVE_LONG:
+ idx = cpool.addLong(value.getValueLong());
+ break;
+ case PRIMITIVE_FLOAT:
+ idx = cpool.addFloat(value.getValueFloat());
+ break;
+ case PRIMITIVE_DOUBLE:
+ idx = cpool.addDouble(value.getValueDouble());
+ break;
+ case PRIMITIVE_BOOLEAN:
+ if (value.getValueBoolean()) {
+ idx = cpool.addInteger(1);
+ } else {
+ idx = cpool.addInteger(0);
+ }
+ break;
+ case PRIMITIVE_SHORT:
+ idx = cpool.addInteger(value.getValueShort());
+ break;
+ default:
+ throw new RuntimeException("SimpleElementValueGen class does not know how " + "to copy this type " + type);
+ }
+ }
+ }
+
+ public int getIndex() {
+ return idx;
+ }
+
+ public String getValueString() {
+ if (type != STRING)
+ throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
+ ConstantUtf8 c = (ConstantUtf8) cpool.getConstant(idx);
+ return c.getValue();
+ }
+
+ public int getValueInt() {
+ if (type != PRIMITIVE_INT)
+ throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(idx);
+ return c.getValue();
+ }
+
+ // Whatever kind of value it is, return it as a string
+ @Override
+ public String stringifyValue() {
+ switch (type) {
+ case PRIMITIVE_INT:
+ ConstantInteger c = (ConstantInteger) cpool.getConstant(idx);
+ return Integer.toString(c.getValue());
+ case PRIMITIVE_LONG:
+ ConstantLong j = (ConstantLong) cpool.getConstant(idx);
+ return Long.toString(j.getValue());
+ case PRIMITIVE_DOUBLE:
+ ConstantDouble d = (ConstantDouble) cpool.getConstant(idx);
+ return d.getValue().toString();
+ case PRIMITIVE_FLOAT:
+ ConstantFloat f = (ConstantFloat) cpool.getConstant(idx);
+ return Float.toString(f.getValue());
+ case PRIMITIVE_SHORT:
+ ConstantInteger s = (ConstantInteger) cpool.getConstant(idx);
+ return Integer.toString(s.getValue());
+ case PRIMITIVE_BYTE:
+ ConstantInteger b = (ConstantInteger) cpool.getConstant(idx);
+ return Integer.toString(b.getValue());
+ case PRIMITIVE_CHAR:
+ ConstantInteger ch = (ConstantInteger) cpool.getConstant(idx);
+ return new Character((char) ch.getIntValue()).toString();
+ case PRIMITIVE_BOOLEAN:
+ ConstantInteger bo = (ConstantInteger) cpool.getConstant(idx);
+ if (bo.getValue() == 0)
+ return "false";
+ else
+ return "true";
+ case STRING:
+ ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(idx);
+ return cu8.getValue();
+
+ default:
+ throw new RuntimeException("SimpleElementValueGen class does not know how to stringify type " + type);
+ }
+ }
+
+ @Override
+ public void dump(DataOutputStream dos) throws IOException {
+ dos.writeByte(type); // u1 kind of value
+ switch (type) {
+ case PRIMITIVE_INT:
+ case PRIMITIVE_BYTE:
+ case PRIMITIVE_CHAR:
+ case PRIMITIVE_FLOAT:
+ case PRIMITIVE_LONG:
+ case PRIMITIVE_BOOLEAN:
+ case PRIMITIVE_SHORT:
+ case PRIMITIVE_DOUBLE:
+ case STRING:
+ dos.writeShort(idx);
+ break;
+ default:
+ throw new RuntimeException("SimpleElementValueGen doesnt know how to write out type " + type);
+ }
+ }
+
+}
+++ /dev/null
-/* *******************************************************************
- * Copyright (c) 2004 IBM
- * 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 - initial implementation {date}
- * ******************************************************************/
-
-package org.aspectj.apache.bcel.classfile.annotation;
-
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.classfile.ConstantDouble;
-import org.aspectj.apache.bcel.classfile.ConstantFloat;
-import org.aspectj.apache.bcel.classfile.ConstantInteger;
-import org.aspectj.apache.bcel.classfile.ConstantLong;
-import org.aspectj.apache.bcel.classfile.ConstantPool;
-import org.aspectj.apache.bcel.classfile.ConstantUtf8;
-
-public class SimpleElementValueGen extends ElementValueGen {
-
- // For primitive types and string type, this points to the value entry in the cpGen
- // For 'class' this points to the class entry in the cpGen
- private int idx;
-
- // ctors for each supported type... type could be inferred but for now lets
- // force it to be passed
-
- /**
- * Protected ctor used for deserialization, doesn't *put* an entry in the constant pool, assumes the one at the supplied index
- * is correct.
- */
- protected SimpleElementValueGen(int type, int idx, ConstantPool cpGen) {
- super(type, cpGen);
- this.idx = idx;
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, int value) {
- super(type, cpGen);
- idx = cpGen.addInteger(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, long value) {
- super(type, cpGen);
- idx = cpGen.addLong(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, double value) {
- super(type, cpGen);
- idx = cpGen.addDouble(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, float value) {
- super(type, cpGen);
- idx = cpGen.addFloat(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, short value) {
- super(type, cpGen);
- idx = cpGen.addInteger(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, byte value) {
- super(type, cpGen);
- idx = cpGen.addInteger(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, char value) {
- super(type, cpGen);
- idx = cpGen.addInteger(value);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, boolean value) {
- super(type, cpGen);
- if (value)
- idx = cpGen.addInteger(1);
- else
- idx = cpGen.addInteger(0);
- }
-
- public SimpleElementValueGen(int type, ConstantPool cpGen, String value) {
- super(type, cpGen);
- idx = cpGen.addUtf8(value);
- }
-
- public byte getValueByte() {
- if (type != PRIMITIVE_BYTE)
- throw new RuntimeException("Dont call getValueByte() on a non BYTE ElementValue");
- ConstantInteger c = (ConstantInteger) cpGen.getConstant(idx, Constants.CONSTANT_Integer);
- return (byte) c.getIntValue();
- }
-
- public char getValueChar() {
- if (type != PRIMITIVE_CHAR)
- throw new RuntimeException("Dont call getValueChar() on a non CHAR ElementValue");
- ConstantInteger c = (ConstantInteger) cpGen.getConstant(idx, Constants.CONSTANT_Integer);
- return (char) c.getIntValue();
- }
-
- public long getValueLong() {
- if (type != PRIMITIVE_LONG)
- throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue");
- ConstantLong j = (ConstantLong) cpGen.getConstant(idx);
- return j.getValue();
- }
-
- public float getValueFloat() {
- if (type != PRIMITIVE_FLOAT)
- throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue");
- ConstantFloat f = (ConstantFloat) cpGen.getConstant(idx);
- return f.getValue();
- }
-
- public double getValueDouble() {
- if (type != PRIMITIVE_DOUBLE)
- throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue");
- ConstantDouble d = (ConstantDouble) cpGen.getConstant(idx);
- return d.getValue();
- }
-
- public boolean getValueBoolean() {
- if (type != PRIMITIVE_BOOLEAN)
- throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue");
- ConstantInteger bo = (ConstantInteger) cpGen.getConstant(idx);
- return (bo.getValue() != 0);
- }
-
- public short getValueShort() {
- if (type != PRIMITIVE_SHORT)
- throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue");
- ConstantInteger s = (ConstantInteger) cpGen.getConstant(idx);
- return (short) s.getIntValue();
- }
-
- /**
- * The boolean controls whether we copy info from the 'old' constant pool to the 'new'. You need to use this ctor if the
- * annotation is being copied from one file to another.
- */
- public SimpleElementValueGen(SimpleElementValueGen value, ConstantPool cpool, boolean copyPoolEntries) {
- super(value.getElementValueType(), cpool);
- if (!copyPoolEntries) {
- // J5ASSERT: Could assert value.stringifyValue() is the same as
- // cpool.getConstant(SimpleElementValuevalue.getIndex())
- idx = value.getIndex();
- } else {
- switch (value.getElementValueType()) {
- case STRING:
- idx = cpool.addUtf8(value.getValueString());
- break;
- case PRIMITIVE_INT:
- idx = cpool.addInteger(value.getValueInt());
- break;
- case PRIMITIVE_BYTE:
- idx = cpool.addInteger(value.getValueByte());
- break;
- case PRIMITIVE_CHAR:
- idx = cpool.addInteger(value.getValueChar());
- break;
- case PRIMITIVE_LONG:
- idx = cpool.addLong(value.getValueLong());
- break;
- case PRIMITIVE_FLOAT:
- idx = cpool.addFloat(value.getValueFloat());
- break;
- case PRIMITIVE_DOUBLE:
- idx = cpool.addDouble(value.getValueDouble());
- break;
- case PRIMITIVE_BOOLEAN:
- if (value.getValueBoolean()) {
- idx = cpool.addInteger(1);
- } else {
- idx = cpool.addInteger(0);
- }
- break;
- case PRIMITIVE_SHORT:
- idx = cpool.addInteger(value.getValueShort());
- break;
- default:
- throw new RuntimeException("SimpleElementValueGen class does not know how " + "to copy this type " + type);
- }
- }
- }
-
- /**
- * Return immutable variant
- */
- public ElementValueGen getElementValue() {
- return new SimpleElementValueGen(type, idx, cpGen);
- }
-
- public int getIndex() {
- return idx;
- }
-
- public String getValueString() {
- if (type != STRING)
- throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
- ConstantUtf8 c = (ConstantUtf8) cpGen.getConstant(idx);
- return c.getValue();
- }
-
- public int getValueInt() {
- if (type != PRIMITIVE_INT)
- throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
- ConstantInteger c = (ConstantInteger) cpGen.getConstant(idx);
- return c.getValue();
- }
-
- // Whatever kind of value it is, return it as a string
- @Override
- public String stringifyValue() {
- switch (type) {
- case PRIMITIVE_INT:
- ConstantInteger c = (ConstantInteger) cpGen.getConstant(idx);
- return Integer.toString(c.getValue());
- case PRIMITIVE_LONG:
- ConstantLong j = (ConstantLong) cpGen.getConstant(idx);
- return Long.toString(j.getValue());
- case PRIMITIVE_DOUBLE:
- ConstantDouble d = (ConstantDouble) cpGen.getConstant(idx);
- return d.getValue().toString();
- case PRIMITIVE_FLOAT:
- ConstantFloat f = (ConstantFloat) cpGen.getConstant(idx);
- return Float.toString(f.getValue());
- case PRIMITIVE_SHORT:
- ConstantInteger s = (ConstantInteger) cpGen.getConstant(idx);
- return Integer.toString(s.getValue());
- case PRIMITIVE_BYTE:
- ConstantInteger b = (ConstantInteger) cpGen.getConstant(idx);
- return Integer.toString(b.getValue());
- case PRIMITIVE_CHAR:
- ConstantInteger ch = (ConstantInteger) cpGen.getConstant(idx);
- return new Character((char) ch.getIntValue()).toString();
- case PRIMITIVE_BOOLEAN:
- ConstantInteger bo = (ConstantInteger) cpGen.getConstant(idx);
- if (bo.getValue() == 0)
- return "false";
- else
- return "true";
- case STRING:
- ConstantUtf8 cu8 = (ConstantUtf8) cpGen.getConstant(idx);
- return cu8.getValue();
-
- default:
- throw new RuntimeException("SimpleElementValueGen class does not know how to stringify type " + type);
- }
- }
-
- @Override
- public void dump(DataOutputStream dos) throws IOException {
- dos.writeByte(type); // u1 kind of value
- switch (type) {
- case PRIMITIVE_INT:
- case PRIMITIVE_BYTE:
- case PRIMITIVE_CHAR:
- case PRIMITIVE_FLOAT:
- case PRIMITIVE_LONG:
- case PRIMITIVE_BOOLEAN:
- case PRIMITIVE_SHORT:
- case PRIMITIVE_DOUBLE:
- case STRING:
- dos.writeShort(idx);
- break;
- default:
- throw new RuntimeException("SimpleElementValueGen doesnt know how to write out type " + type);
- }
- }
-
-}
import org.aspectj.apache.bcel.classfile.SourceFile;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisAnnos;
/**
* Template class for building up a java class. May be initialized with an existing java class.
*
* @see JavaClass
- * @version $Id: ClassGen.java,v 1.14 2009/09/10 03:59:34 aclement Exp $
+ * @version $Id: ClassGen.java,v 1.15 2009/09/15 19:40:14 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*
* Upgraded, Andy Clement 9th Mar 06 - calculates SUID
// OPTIMIZE Could make unpacking lazy, done on first reference
Attribute[] attributes = clazz.getAttributes();
for (Attribute attr : attributes) {
- if (attr instanceof RuntimeVisibleAnnotations) {
- RuntimeVisibleAnnotations rva = (RuntimeVisibleAnnotations) attr;
+ if (attr instanceof RuntimeVisAnnos) {
+ RuntimeVisAnnos rva = (RuntimeVisAnnos) attr;
List<AnnotationGen> annos = rva.getAnnotations();
for (AnnotationGen a : annos) {
annotationsList.add(new AnnotationGen(a, cpool, false));
}
- } else if (attr instanceof RuntimeInvisibleAnnotations) {
- RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations) attr;
+ } else if (attr instanceof RuntimeInvisAnnos) {
+ RuntimeInvisAnnos ria = (RuntimeInvisAnnos) attr;
List<AnnotationGen> annos = ria.getAnnotations();
for (AnnotationGen anno : annos) {
annotationsList.add(new AnnotationGen(anno, cpool, false));
import org.aspectj.apache.bcel.classfile.Field;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
/**
* Template class for building up a field. The only extraordinary thing one can do is to add a constant value attribute to a field
* (which must of course be compatible with the declared type).
*
- * @version $Id: FieldGen.java,v 1.8 2009/09/14 20:29:10 aclement Exp $
+ * @version $Id: FieldGen.java,v 1.9 2009/09/15 19:40:14 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Field
*/
for (int i = 0; i < attrs.length; i++) {
if (attrs[i] instanceof ConstantValue) {
setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
- } else if (attrs[i] instanceof RuntimeAnnotations) {
- RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) attrs[i];
+ } else if (attrs[i] instanceof RuntimeAnnos) {
+ RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attrs[i];
List<AnnotationGen> l = runtimeAnnotations.getAnnotations();
for (Iterator<AnnotationGen> it = l.iterator(); it.hasNext();) {
AnnotationGen element = it.next();
import org.aspectj.apache.bcel.classfile.Modifiers;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
/**
* Super class for FieldGen and MethodGen objects, since they have some methods in common!
*
- * @version $Id: FieldGenOrMethodGen.java,v 1.7 2009/09/14 20:29:10 aclement Exp $
+ * @version $Id: FieldGenOrMethodGen.java,v 1.8 2009/09/15 19:40:14 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
*/
public abstract class FieldGenOrMethodGen extends Modifiers {
}
protected void addAnnotationsAsAttribute(ConstantPool cp) {
- Collection<RuntimeAnnotations> attrs = Utility.getAnnotationAttributes(cp, annotationList);
+ Collection<RuntimeAnnos> attrs = Utility.getAnnotationAttributes(cp, annotationList);
if (attrs != null) {
for (Attribute attr : attrs) {
addAttribute(attr);
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Utility;
import org.aspectj.apache.bcel.classfile.annotation.AnnotationGen;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
-import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnos;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeParamAnnos;
/**
* Template class for building up a method. This is done by defining exception handlers, adding thrown exceptions, local variables
* While generating code it may be necessary to insert NOP operations. You can use the `removeNOPs' method to get rid off them. The
* resulting method object can be obtained via the `getMethod()' method.
*
- * @version $Id: MethodGen.java,v 1.14 2009/09/14 20:29:10 aclement Exp $
+ * @version $Id: MethodGen.java,v 1.15 2009/09/15 19:40:14 aclement Exp $
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @author <A HREF="http://www.vmeng.com/beard">Patrick C. Beard</A> [setMaxStack()]
* @see InstructionList
String[] names = ((ExceptionTable) a).getExceptionNames();
for (int j = 0; j < names.length; j++)
addException(names[j]);
- } else if (a instanceof RuntimeAnnotations) {
- RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) a;
+ } else if (a instanceof RuntimeAnnos) {
+ RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) a;
List<AnnotationGen> l = runtimeAnnotations.getAnnotations();
annotationList.addAll(l);
// for (Iterator<AnnotationGen> it = l.iterator(); it.hasNext();) {
}
// Find attributes that contain parameter annotation data
List<Attribute> attrs = getAttributes();
- RuntimeParameterAnnotations paramAnnVisAttr = null;
- RuntimeParameterAnnotations paramAnnInvisAttr = null;
+ RuntimeParamAnnos paramAnnVisAttr = null;
+ RuntimeParamAnnos paramAnnInvisAttr = null;
for (Attribute attribute : attrs) {
- if (attribute instanceof RuntimeParameterAnnotations) {
+ if (attribute instanceof RuntimeParamAnnos) {
if (!hasParameterAnnotations) {
param_annotations = new List[parameterTypes.length];
}
hasParameterAnnotations = true;
- RuntimeParameterAnnotations rpa = (RuntimeParameterAnnotations) attribute;
+ RuntimeParamAnnos rpa = (RuntimeParamAnnos) attribute;
if (rpa.areVisible())
paramAnnVisAttr = rpa;
else