]> source.dussan.org Git - aspectj.git/commitdiff
refactoring
authoraclement <aclement>
Tue, 15 Sep 2009 19:40:09 +0000 (19:40 +0000)
committeraclement <aclement>
Tue, 15 Sep 2009 19:40:09 +0000 (19:40 +0000)
52 files changed:
bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Attribute.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/AttributeUtils.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/ClassVisitor.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Code.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantValue.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Deprecated.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/ExceptionTable.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/FieldOrMethod.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/InnerClasses.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumberTable.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTable.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Method.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Signature.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/SourceFile.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/StackMap.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Synthetic.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Unknown.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationGen.java
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementNameValuePairGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/NameValuePair.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisParamAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleParameterAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParamAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParameterAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisParamAnnos.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleParameterAnnotations.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java [new file with mode: 0644]
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValueGen.java [deleted file]
bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java
bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java
bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java
bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java

index 53cf1c33d74f61dbacb8189c9a9cadb48be96f3b..bd5a7251f16a574cd554e113481bdc211a587e53 100644 (file)
@@ -17,7 +17,7 @@ import java.io.DataOutputStream;
 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 
@@ -25,13 +25,13 @@ import org.aspectj.apache.bcel.classfile.annotation.ElementValueGen;
  */
 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;
        }
@@ -42,7 +42,7 @@ public class AnnotationDefault extends Attribute {
                // 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);
index 3f730f2174c2104542bd9544d9a9ab5a104e7e69..aefa0ed44cb6ecc111050c7bc3fa05accca534c9 100644 (file)
@@ -60,17 +60,17 @@ import java.io.IOException;
 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
@@ -143,13 +143,13 @@ public abstract class Attribute implements Cloneable, Node, Serializable {
                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:
@@ -181,28 +181,29 @@ public abstract class Attribute implements Cloneable, Node, Serializable {
                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() {
index c2f7ed1c05dd9d190f3f517b704ed77b6fc20e13..45d1597a78bc05e8fe457fb8919cc8ae8d68895a 100644 (file)
@@ -36,17 +36,6 @@ public class AttributeUtils {
                }
        }
 
-       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) {
index 9513e02f904525f68f3f90298aa0a9d6e4262aa4..0957bfba825a406e35732088f6be4f8924e3b6b2 100644 (file)
@@ -1,9 +1,9 @@
 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
@@ -65,7 +65,7 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleParameterAnnot
  * 
  * 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 {
@@ -135,13 +135,13 @@ 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);
 
index 237b80029d147173f5340016233d73720eaa65a8..fb96fbe5fa6b279b985ac9d9bce101c1294f1118 100644 (file)
@@ -54,325 +54,324 @@ package org.aspectj.apache.bcel.classfile;
  * <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();
+       }
 }
index c07ddcc6222e96277a470b83283cef2bd20813a0..67cc0851e1b5a6cac305219c6a78faebe677b35a 100644 (file)
@@ -64,7 +64,7 @@ import org.aspectj.apache.bcel.Constants;
  * 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
  */
@@ -176,14 +176,14 @@ public final class ConstantValue extends 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;
+       // }
 }
index f3cc4e32c35215bb1c3446664f3760ec8cdcc98d..21bbbcb46d62c2cecb2fe8b268a5c8653c73e44a 100644 (file)
@@ -54,116 +54,118 @@ package org.aspectj.apache.bcel.classfile;
  * <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;
+       // }
 }
index a7a084cefa6bfa4934e4d85d0dc45cf68be899ca..ad7d43f2e541df84900c6824af363770871be50f 100644 (file)
@@ -54,149 +54,146 @@ package org.aspectj.apache.bcel.classfile;
  * <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;
+       // }
 }
index 1babd200ac2ce7886e7ae88b245e2e4627d77a0b..a152b616f56a6b421d2fd73149b3318a8e458d89 100644 (file)
@@ -61,12 +61,12 @@ import java.util.List;
 
 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 {
@@ -170,8 +170,8 @@ 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());
                                }
                        }
index 493012bf941582962bcc8a90051d1f7bb84bbee9..0078156edacbff4bffab2ece7dce8a510ac60d32 100644 (file)
@@ -54,128 +54,128 @@ package org.aspectj.apache.bcel.classfile;
  * <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;
+       // }
 }
index 27d2c241a44fadefa7ce3b828ce46f958b03d36b..25c415295540e610b5e83318faef102232dee975 100644 (file)
@@ -69,7 +69,7 @@ import java.util.StringTokenizer;
 
 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;
 
@@ -80,7 +80,7 @@ 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>
  */
@@ -289,8 +289,8 @@ public class JavaClass extends Modifiers implements Cloneable, 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());
                                }
                        }
index e0ba7ebae34c58aac2cdf22809463cac9e5f98ce..10d72fd3edd7e1149058b9156666cfba11df159a 100644 (file)
@@ -65,7 +65,7 @@ import org.aspectj.apache.bcel.Constants;
  * 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
  */
@@ -258,18 +258,17 @@ public final class LineNumberTable extends Attribute {
        /**
         * @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;
index 138269700f2b988731266aab0d54cb3371ce1d34..717bb596581ad3b18f581c53573e529d801d1e6a 100644 (file)
@@ -64,7 +64,7 @@ import org.aspectj.apache.bcel.Constants;
 /**
  * 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.
@@ -120,6 +120,7 @@ public class LocalVariableTable extends Attribute {
         * 
         * @param v Visitor object
         */
+       @Override
        public void accept(ClassVisitor v) {
                unpack();
                v.visitLocalVariableTable(this);
@@ -131,6 +132,7 @@ public class LocalVariableTable extends Attribute {
         * @param file Output file stream
         * @throws IOException
         */
+       @Override
        public final void dump(DataOutputStream file) throws IOException {
                super.dump(file);
                if (isInPackedState) {
@@ -173,6 +175,7 @@ public class LocalVariableTable extends Attribute {
        /**
         * @return String representation.
         */
+       @Override
        public final String toString() {
                StringBuffer buf = new StringBuffer("");
                unpack();
@@ -189,18 +192,17 @@ public class LocalVariableTable extends Attribute {
        /**
         * @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;
index ea1f3badf2ad77fea7ca37ba61f53eb688fb3a6a..ecd7e43834532f3a1caecfd5a3654b964621f4f7 100644 (file)
  * ******************************************************************/
 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...
 
@@ -45,91 +47,90 @@ import  java.io.*;
 //  }
 // 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;
+       }
 }
index cec26bd342eb5f43aef1bcc74f465493d936bc47..d354b7fe1942038658b99f8c425380d3a1c1dd35 100644 (file)
@@ -60,15 +60,15 @@ import java.util.List;
 
 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 {
@@ -206,18 +206,18 @@ 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;
                        }
                }
 
index b1991afef263b283cb6b6ba0596e811ceeb87c8d..b7488e9a4d73ee888e1624d5bb4fbc665656e08f 100644 (file)
@@ -68,7 +68,7 @@ import org.aspectj.apache.bcel.Constants;
  * 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
  */
@@ -299,12 +299,12 @@ public final class Signature extends 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();
+       // }
 
 }
index 6832f86cd87b566aff1e76db4f87582c6e6ef887..9fd840fc0789526b9b95ca16c87f9a79d8659f60 100644 (file)
@@ -65,7 +65,7 @@ import org.aspectj.apache.bcel.Constants;
  * 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
  */
@@ -160,10 +160,10 @@ public final class SourceFile extends 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();
+       // }
 }
index 0ddf0e88f585eca30f90907be4cd1d5259d2c893..80f943bbf2709c34866a49479640b91a90e6c1ac 100644 (file)
@@ -54,132 +54,137 @@ package org.aspectj.apache.bcel.classfile;
  * <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;
+       }
 }
index e3eebe36b22de2587f21164c3778e6ba984ac287..57fe97468e37f7bac7d0d42a02868807f706c892 100644 (file)
@@ -54,131 +54,132 @@ package org.aspectj.apache.bcel.classfile;
  * <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;
+       // }
 }
index c4f86441b95f29ff190eface04c6a3358fbd7fe4..416d105b1e39b9c084cffe79ffd4448140669512 100644 (file)
@@ -68,7 +68,7 @@ import org.aspectj.apache.bcel.Constants;
  * 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>
  */
@@ -202,14 +202,14 @@ public final class Unknown extends Attribute {
        /**
         * @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;
+       // }
 }
index df6b7f37652272eb84dc5677325d69ebcaf9e269..efcbf9fb5f7a51a2bc13c5d1e4d2a310a92fc1ad 100644 (file)
@@ -63,19 +63,19 @@ import java.util.List;
 
 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
@@ -396,18 +396,16 @@ public abstract class Utility {
 
                                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;
 
@@ -545,7 +543,7 @@ public abstract class Utility {
         * @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;
@@ -593,12 +591,12 @@ public abstract class Utility {
                        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;
@@ -682,14 +680,14 @@ public abstract class Utility {
                        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[] {});
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValue.java
new file mode 100644 (file)
index 0000000..1b2d402
--- /dev/null
@@ -0,0 +1,55 @@
+/* *******************************************************************
+ * 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;
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/AnnotationElementValueGen.java
deleted file mode 100644 (file)
index e1b9f47..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/* *******************************************************************
- * 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;}
-   
-}
index e5d2566b747f4fd6e6370bfaed258f6b0502f2ce..af442522d69d00f847d765caafda2de1fc89a447 100644 (file)
@@ -28,7 +28,7 @@ public class AnnotationGen {
        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;
 
@@ -43,10 +43,10 @@ public class AnnotationGen {
                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;
        }
@@ -58,7 +58,7 @@ public class AnnotationGen {
        /**
         * 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
@@ -73,7 +73,7 @@ public class AnnotationGen {
                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;
@@ -83,14 +83,14 @@ public class AnnotationGen {
                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);
        }
@@ -108,7 +108,7 @@ public class AnnotationGen {
                return Utility.signatureToString(getTypeSignature());
        }
 
-       public List<ElementNameValuePairGen> getValues() {
+       public List<NameValuePair> getValues() {
                return pairs;
        }
 
@@ -149,7 +149,7 @@ public class AnnotationGen {
         * @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;
@@ -163,7 +163,7 @@ public class AnnotationGen {
         * @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;
                        }
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValue.java
new file mode 100644 (file)
index 0000000..3dd19af
--- /dev/null
@@ -0,0 +1,84 @@
+/* *******************************************************************
+ * 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;
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ArrayElementValueGen.java
deleted file mode 100644 (file)
index 1059922..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/* *******************************************************************
- * 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;
-       }
-   
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValue.java
new file mode 100644 (file)
index 0000000..a4e18b6
--- /dev/null
@@ -0,0 +1,79 @@
+/* *******************************************************************
+ * 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);
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ClassElementValueGen.java
deleted file mode 100644 (file)
index 82c1559..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/* *******************************************************************
- * 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);
-       }
-
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementNameValuePairGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementNameValuePairGen.java
deleted file mode 100644 (file)
index c186fb2..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/* *******************************************************************
- * 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();
-       }
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValue.java
new file mode 100644 (file)
index 0000000..511afe2
--- /dev/null
@@ -0,0 +1,135 @@
+/* *******************************************************************
+ * 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() + ")");
+               }
+       }
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/ElementValueGen.java
deleted file mode 100644 (file)
index e575ff3..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/* *******************************************************************
- * 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()+")");
-               }
-       }
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java
new file mode 100644 (file)
index 0000000..b7adc17
--- /dev/null
@@ -0,0 +1,109 @@
+/* *******************************************************************
+ * 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;
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValueGen.java
deleted file mode 100644 (file)
index c0198d2..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/* *******************************************************************
- * 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;
-       }
-
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/NameValuePair.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/NameValuePair.java
new file mode 100644 (file)
index 0000000..99b4211
--- /dev/null
@@ -0,0 +1,75 @@
+/* *******************************************************************
+ * 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();
+       }
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnos.java
new file mode 100644 (file)
index 0000000..a6b6534
--- /dev/null
@@ -0,0 +1,82 @@
+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;
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeAnnotations.java
deleted file mode 100644 (file)
index 0530dca..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-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;
-       }
-       
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisAnnos.java
new file mode 100644 (file)
index 0000000..a2ab520
--- /dev/null
@@ -0,0 +1,40 @@
+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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisParamAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisParamAnnos.java
new file mode 100644 (file)
index 0000000..b5d7bb1
--- /dev/null
@@ -0,0 +1,34 @@
+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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleAnnotations.java
deleted file mode 100644 (file)
index cb372b2..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleParameterAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeInvisibleParameterAnnotations.java
deleted file mode 100644 (file)
index 4fb4bb7..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParamAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParamAnnos.java
new file mode 100644 (file)
index 0000000..4bd8644
--- /dev/null
@@ -0,0 +1,118 @@
+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")+"]";
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParameterAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeParameterAnnotations.java
deleted file mode 100644 (file)
index 7d57cb9..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-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")+"]";
-       }
-
-}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisAnnos.java
new file mode 100644 (file)
index 0000000..aa3f49e
--- /dev/null
@@ -0,0 +1,40 @@
+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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisParamAnnos.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisParamAnnos.java
new file mode 100644 (file)
index 0000000..ccd1aa7
--- /dev/null
@@ -0,0 +1,34 @@
+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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleAnnotations.java
deleted file mode 100644 (file)
index 5d6e427..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleParameterAnnotations.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/RuntimeVisibleParameterAnnotations.java
deleted file mode 100644 (file)
index b0eeea8..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-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
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java
new file mode 100644 (file)
index 0000000..b8b354c
--- /dev/null
@@ -0,0 +1,268 @@
+/* *******************************************************************
+ * 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);
+               }
+       }
+
+}
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValueGen.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValueGen.java
deleted file mode 100644 (file)
index b1276ba..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/* *******************************************************************
- * 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);
-               }
-       }
-
-}
index bafc633594639180ad3d9ac367778715f1ee8916..f12bd4491a9e33721335e68d493ffdf8118adf35 100644 (file)
@@ -75,14 +75,14 @@ import org.aspectj.apache.bcel.classfile.Modifiers;
 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
@@ -148,14 +148,14 @@ public class ClassGen extends Modifiers implements Cloneable {
                // 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));
index 2208446330899551add0e64291a232f9db596413..fdda9109a4b6b8c73db765d0f95fdd6c9428c0f3 100644 (file)
@@ -66,13 +66,13 @@ import org.aspectj.apache.bcel.classfile.ConstantValue;
 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
  */
@@ -109,8 +109,8 @@ public class FieldGen extends FieldGenOrMethodGen {
                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();
index 74ede06ec9f602cf1d79ae7dd5ba3f2801886612..ff8b6f42cb8aaf31501097daa2af5cd081def7c9 100644 (file)
@@ -63,12 +63,12 @@ import org.aspectj.apache.bcel.classfile.ConstantPool;
 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 {
@@ -145,7 +145,7 @@ 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);
index b85bf0165e55bfe86dad3fb0a6d874d078649d8d..15c9000e917a97220cdc7044db3166eea10afe0e 100644 (file)
@@ -73,8 +73,8 @@ import org.aspectj.apache.bcel.classfile.LocalVariableTable;
 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
@@ -84,7 +84,7 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations;
  * 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
@@ -329,8 +329,8 @@ public class MethodGen extends FieldGenOrMethodGen {
                                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();) {
@@ -1040,11 +1040,11 @@ public class MethodGen extends FieldGenOrMethodGen {
                }
                // 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];
@@ -1054,7 +1054,7 @@ public class MethodGen extends FieldGenOrMethodGen {
                                }
 
                                hasParameterAnnotations = true;
-                               RuntimeParameterAnnotations rpa = (RuntimeParameterAnnotations) attribute;
+                               RuntimeParamAnnos rpa = (RuntimeParamAnnos) attribute;
                                if (rpa.areVisible())
                                        paramAnnVisAttr = rpa;
                                else