Author: tcurdt
Date: Mon Jun 26 03:19:54 2006
New Revision: 417157

URL: http://svn.apache.org/viewvc?rev=417157&view=rev
Log:
GSoC: latest changes from Dmitriy Khayredinov

Added:
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
   (with props)
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
   (with props)
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
   (with props)
Modified:
    jakarta/bcel/trunk/pom.xml
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java
    jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationGen.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementNameValuePairGen.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java
    
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/SimpleElementValueGen.java
    jakarta/bcel/trunk/src/test/java/org/apache/bcel/AnnotationGenTestCase.java

Modified: jakarta/bcel/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/pom.xml?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- jakarta/bcel/trunk/pom.xml (original)
+++ jakarta/bcel/trunk/pom.xml Mon Jun 26 03:19:54 2006
@@ -149,8 +149,8 @@
                                <artifactId>maven-compiler-plugin</artifactId>
                                <configuration>
                                        <debug>true</debug>
-                                       <source>1.4</source>
-                                       <target>1.4</target>
+                                       <source>1.5</source>
+                                       <target>1.5</target>
                                </configuration>
                        </plugin>
                        <plugin>
@@ -180,4 +180,4 @@
                        <version>3.8.1</version>
                </dependency>
        </dependencies>
-</project>
\ No newline at end of file
+</project>

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java 
(original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/AnnotationEntry.java 
Mon Jun 26 03:19:54 2006
@@ -19,6 +19,8 @@
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.bcel.Constants;
 
 /**
@@ -32,8 +34,9 @@
 
     private int type_index;
     private int num_element_value_pairs;
-    private ElementValuePair[] element_value_pairs;
+    private List element_value_pairs;
     private ConstantPool constant_pool;
+    private boolean isRuntimeVisible;
 
 
     /**
@@ -41,14 +44,22 @@
      * @param file Input stream
      * @throws IOException
      */
-    AnnotationEntry(DataInputStream file, ConstantPool constant_pool) throws 
IOException {
-        type_index = (file.readUnsignedShort());
-        num_element_value_pairs = (file.readUnsignedShort());
-        element_value_pairs = new ElementValuePair[num_element_value_pairs];
-        for (int i = 0; i < num_element_value_pairs; i++) {
-            element_value_pairs[i] = new ElementValuePair(file, constant_pool);
-        }
+    public AnnotationEntry(int type_index, ConstantPool constant_pool, boolean 
isRuntimeVisible) {
+        this.type_index = type_index;
+        
         this.constant_pool = constant_pool;
+        this.isRuntimeVisible = isRuntimeVisible;
+    }
+    
+    public static AnnotationEntry read(DataInputStream file, ConstantPool 
constant_pool, boolean isRuntimeVisible) throws IOException 
+    {
+       AnnotationEntry annotationEntry = new 
AnnotationEntry(file.readUnsignedShort(), constant_pool, isRuntimeVisible);
+       annotationEntry.num_element_value_pairs = (file.readUnsignedShort());
+       annotationEntry.element_value_pairs = new ArrayList();
+        for (int i = 0; i < annotationEntry.num_element_value_pairs; i++) {
+               annotationEntry.element_value_pairs.add(new 
ElementValuePair(file.readUnsignedShort(), ElementValue.readElementValue(file, 
constant_pool), constant_pool));
+        }
+        return annotationEntry;
     }
 
 
@@ -72,6 +83,14 @@
         c = (ConstantUtf8) constant_pool.getConstant(type_index, 
CONSTANT_Utf8);
         return c.getBytes();
     }
+    
+    /**
+     * @return the annotation type index
+     */
+    public int getAnnotationTypeIndex()
+    {
+       return type_index;
+    }
 
 
     /**
@@ -86,12 +105,24 @@
      * @return the element value pairs in this annotation entry
      */
     public ElementValuePair[] getElementValuePairs() {
-        return element_value_pairs;
+       // TOFO return List
+        return (ElementValuePair[]) element_value_pairs.toArray();
     }
 
 
        public void dump(DataOutputStream dos)
        {
                // TODO Auto-generated method stub
+       }
+
+
+       public boolean isRuntimeVisible()
+       {
+               return isRuntimeVisible;
+       }
+
+       public void addElementNameValuePair(ElementValuePair 
elementNameValuePair)
+       {
+               element_value_pairs.add(elementNameValuePair);
        }
 }

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java 
(original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Annotations.java 
Mon Jun 26 03:19:54 2006
@@ -30,6 +30,7 @@
 
     private int annotation_table_length;
     private AnnotationEntry[] annotation_table; // Table of annotations
+    private boolean isRuntimeVisible;
 
 
     /**
@@ -39,13 +40,13 @@
      * @param file Input stream
      * @param constant_pool Array of constants
      */
-    Annotations(byte annotation_type, int name_index, int length, 
DataInputStream file,
-            ConstantPool constant_pool) throws IOException {
-        this(annotation_type, name_index, length, (AnnotationEntry[]) null, 
constant_pool);
+    public Annotations(byte annotation_type, int name_index, int length, 
DataInputStream file,
+            ConstantPool constant_pool, boolean isRuntimeVisible) throws 
IOException {
+        this(annotation_type, name_index, length, (AnnotationEntry[]) null, 
constant_pool, isRuntimeVisible);
         annotation_table_length = (file.readUnsignedShort());
         annotation_table = new AnnotationEntry[annotation_table_length];
         for (int i = 0; i < annotation_table_length; i++) {
-            annotation_table[i] = new AnnotationEntry(file, constant_pool);
+            annotation_table[i] = AnnotationEntry.read(file, constant_pool, 
isRuntimeVisible);
         }
     }
 
@@ -58,9 +59,10 @@
      * @param constant_pool Array of constants
      */
     public Annotations(byte annotation_type, int name_index, int length,
-            AnnotationEntry[] annotation_table, ConstantPool constant_pool) {
+            AnnotationEntry[] annotation_table, ConstantPool constant_pool , 
boolean isRuntimeVisible) {
         super(annotation_type, name_index, length, constant_pool);
         setAnnotationTable(annotation_table);
+        this.isRuntimeVisible = isRuntimeVisible;
     }
 
 
@@ -106,5 +108,10 @@
      */
     public final int getNumAnnotations() {
         return annotation_table_length;
+    }
+    
+    public boolean isRuntimeVisible()
+    {
+       return isRuntimeVisible;
     }
 }

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java 
(original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValue.java 
Mon Jun 26 03:19:54 2006
@@ -118,8 +118,9 @@
                case 'c': // Class
                        return new ClassElementValue(CLASS, 
dis.readUnsignedShort(), cpool);
                case '@': // Annotation
-                       return new AnnotationElementValue(ANNOTATION, new 
AnnotationEntry(
-                                       dis, cpool), cpool);
+                       // TODO isRuntimeVisible
+                       return new AnnotationElementValue(ANNOTATION, 
AnnotationEntry.read(
+                                       dis, cpool, false), cpool);
                case '[': // Array
                        int numArrayVals = dis.readUnsignedShort();
                        List arrayVals = new ArrayList();

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ElementValuePair.java
 Mon Jun 26 03:19:54 2006
@@ -16,30 +16,45 @@
  */
 package org.apache.bcel.classfile;
 
-import java.io.DataInputStream;
-import java.io.IOException;
+import org.apache.bcel.Constants;
 
 /**
  * an annotation's element value pair
  * 
  * @version $Id: ElementValuePair
- * @author  <A HREF="mailto:[EMAIL PROTECTED]">D. Brosius</A>
+ * @author <A HREF="mailto:[EMAIL PROTECTED]">D. Brosius</A>
  * @since 5.2
  */
-public class ElementValuePair {
+public class ElementValuePair
+{
+       private ElementValue elementValue;
 
-    private int element_name_index;
-    private ElementValue value;
+       private ConstantPool constantPool;
 
+       private int elementNameIndex;
 
-    /**
-     * Construct object from file stream.
-     * @param file Input stream
-     * @param constant_pool the constant pool
-     * @throws IOException
-     */
-    ElementValuePair(DataInputStream file, ConstantPool constant_pool) throws 
IOException {
-        element_name_index = (file.readUnsignedShort());
-        value = ElementValue.readElementValue(file, constant_pool);
-    }
+       public ElementValuePair(int elementNameIndex, ElementValue elementValue,
+                       ConstantPool constantPool)
+       {
+               this.elementValue = elementValue;
+               this.elementNameIndex = elementNameIndex;
+               this.constantPool = constantPool;
+       }
+
+       public String getNameString()
+       {
+               ConstantUtf8 c = (ConstantUtf8) constantPool.getConstant(
+                               elementNameIndex, Constants.CONSTANT_Utf8);
+               return c.getBytes();
+       }
+
+       public final ElementValue getValue()
+       {
+               return elementValue;
+       }
+
+       public int getNameIndex()
+       {
+               return elementNameIndex;
+       }
 }

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
 Mon Jun 26 03:19:54 2006
@@ -42,7 +42,8 @@
         annotation_table_length = (file.readUnsignedShort());
         annotation_table = new AnnotationEntry[annotation_table_length];
         for (int i = 0; i < annotation_table_length; i++) {
-            annotation_table[i] = new AnnotationEntry(file, constant_pool);
+//              TODO isRuntimeVisible
+            annotation_table[i] = AnnotationEntry.read(file, constant_pool, 
false);
         }
     }
 

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
 Mon Jun 26 03:19:54 2006
@@ -38,7 +38,7 @@
      */
     RuntimeInvisibleAnnotations(int name_index, int length, DataInputStream 
file,
             ConstantPool constant_pool) throws IOException {
-        super(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, 
length, file, constant_pool);
+        super(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, 
length, file, constant_pool, false);
     }
 
 

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
 Mon Jun 26 03:19:54 2006
@@ -36,12 +36,12 @@
      * @param file Input stream
      * @param constant_pool Array of constants
      */
-    RuntimeVisibleAnnotations(int name_index, int length, DataInputStream file,
+    public RuntimeVisibleAnnotations(int name_index, int length, 
DataInputStream file,
             ConstantPool constant_pool) throws IOException {
-        super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length, 
file, constant_pool);
+        super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length, 
file, constant_pool, true);
     }
-
-
+    
+    
     /**
      * @return deep copy of this attribute
      */

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
 Mon Jun 26 03:19:54 2006
@@ -24,7 +24,7 @@
 {
        private int index;
 
-       protected SimpleElementValue(int type, int index, ConstantPool cpool)
+       public SimpleElementValue(int type, int index, ConstantPool cpool)
        {
                super(type, cpool);
                this.index = index;

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java 
(original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/classfile/Utility.java Mon 
Jun 26 03:19:54 2006
@@ -20,6 +20,8 @@
 import java.io.ByteArrayOutputStream;
 import java.io.CharArrayReader;
 import java.io.CharArrayWriter;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
 import java.io.FilterReader;
 import java.io.FilterWriter;
 import java.io.IOException;
@@ -33,6 +35,8 @@
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 import org.apache.bcel.Constants;
+import org.apache.bcel.generic.AnnotationEntryGen;
+import org.apache.bcel.generic.ConstantPoolGen;
 import org.apache.bcel.util.ByteSequence;
 
 /**
@@ -1338,5 +1342,74 @@
             }
         }
         return buf.toString();
+    }
+
+
+    /**
+     * Converts a list of AnnotationGen objects into a set of attributes 
+     * that can be attached to the class file.
+     *
+     * @param cp The constant pool gen where we can create the necessary name 
refs
+     * @param vec A list of AnnotationGen objects
+     */
+    public static Attribute[] getAnnotationAttributes(ConstantPoolGen cp,List 
vec) {
+       
+       if (vec.size()==0) return null;
+       
+       try {
+               int countVisible   = 0;
+               int countInvisible = 0;
+       
+               //  put the annotations in the right output stream
+               for (int i=0; i<vec.size(); i++) {
+                       AnnotationEntryGen a = (AnnotationEntryGen)vec.get(i);
+                       if (a.isRuntimeVisible()) countVisible++;
+                       else                       countInvisible++;
+               }
+       
+               ByteArrayOutputStream rvaBytes = new ByteArrayOutputStream();
+               ByteArrayOutputStream riaBytes = new ByteArrayOutputStream();
+               DataOutputStream rvaDos = new DataOutputStream(rvaBytes);
+               DataOutputStream riaDos = new DataOutputStream(riaBytes);
+       
+               rvaDos.writeShort(countVisible);
+               riaDos.writeShort(countInvisible);
+
+               // put the annotations in the right output stream
+               for (int i=0; i<vec.size(); i++) {
+                       AnnotationEntryGen a = (AnnotationEntryGen)vec.get(i);
+                       if (a.isRuntimeVisible()) a.dump(rvaDos);
+                       else                       a.dump(riaDos);
+               }
+
+      rvaDos.close();
+      riaDos.close();
+      
+      byte[] rvaData = rvaBytes.toByteArray();
+      byte[] riaData = riaBytes.toByteArray();
+      
+      int rvaIndex = -1;
+      int riaIndex = -1;
+      
+      if (rvaData.length>2) rvaIndex = cp.addUtf8("RuntimeVisibleAnnotations");
+      if (riaData.length>2) riaIndex = 
cp.addUtf8("RuntimeInvisibleAnnotations");
+
+       List newAttributes = new ArrayList();
+       if (rvaData.length>2) {
+               
+               newAttributes.add(
+                 new RuntimeVisibleAnnotations(rvaIndex,rvaData.length,new 
DataInputStream(new ByteArrayInputStream(rvaData)),cp.getConstantPool()));
+       }
+       if (riaData.length>2) {
+               newAttributes.add(
+                 new RuntimeInvisibleAnnotations(riaIndex,riaData.length,new 
DataInputStream(new ByteArrayInputStream(riaData)),cp.getConstantPool()));
+       }
+
+       return (Attribute[])newAttributes.toArray(new Attribute[]{});
+       } catch (IOException e) {
+               System.err.println("IOException whilst processing annotations");
+               e.printStackTrace();
+       }
+       return null;
     }
 }

Added: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java?rev=417157&view=auto
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
 (added)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
 Mon Jun 26 03:19:54 2006
@@ -0,0 +1,190 @@
+package org.apache.bcel.generic;
+
+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.apache.bcel.classfile.AnnotationEntry;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.ElementValuePair;
+
+
+public class AnnotationEntryGen
+{
+       private int typeIndex;
+
+       private List /* ElementNameValuePairGen */evs;
+
+       private ConstantPoolGen cpool;
+
+       private boolean isRuntimeVisible = false;
+
+       /**
+        * Here we are taking a fixed annotation of type Annotation and 
building a
+        * modifiable AnnotationGen object. If the pool passed in is for a 
different
+        * class file, then copyPoolEntries should have been passed as true as 
that
+        * will force us to do a deep copy of the annotation and move the cpool
+        * entries across. We need to copy the type and the element name value 
pairs
+        * and the visibility.
+        */
+       public AnnotationEntryGen(AnnotationEntry a, ConstantPoolGen cpool,
+                       boolean copyPoolEntries)
+       {
+               this.cpool = cpool;
+               if (copyPoolEntries)
+               {
+                       typeIndex = cpool.addUtf8(a.getAnnotationType());
+               }
+               else
+               {
+                       typeIndex = a.getAnnotationTypeIndex();
+               }
+               isRuntimeVisible = a.isRuntimeVisible();
+               evs = copyValues(a.getElementValuePairs(), cpool, 
copyPoolEntries);
+       }
+
+       private List copyValues(ElementValuePair[] in, ConstantPoolGen cpool,
+                       boolean copyPoolEntries)
+       {
+               List out = new ArrayList();
+               int l = in.length;
+               for (int i = 0; i < l; i++)
+               {
+                       ElementValuePair nvp = (ElementValuePair) in[i];
+                       out.add(new ElementValuePairGen(nvp, cpool, 
copyPoolEntries));
+               }
+               return out;
+       }
+
+       private AnnotationEntryGen(ConstantPoolGen cpool)
+       {
+               this.cpool = cpool;
+       }
+
+       /**
+        * Retrieve an immutable version of this AnnotationGen
+        */
+       public AnnotationEntry getAnnotation()
+       {
+               AnnotationEntry a = new AnnotationEntry(typeIndex, 
cpool.getConstantPool(),
+                               isRuntimeVisible);
+               for (Iterator iter = evs.iterator(); iter.hasNext();)
+               {
+                       ElementValuePairGen element = (ElementValuePairGen) iter
+                                       .next();
+                       
a.addElementNameValuePair(element.getElementNameValuePair());
+               }
+               return a;
+       }
+
+       public AnnotationEntryGen(ObjectType type,
+                       List /* ElementNameValuePairGen */elements, boolean vis,
+                       ConstantPoolGen cpool)
+       {
+               this.cpool = cpool;
+               this.typeIndex = cpool.addUtf8(type.getSignature());
+               evs = elements;
+               isRuntimeVisible = vis;
+       }
+
+       public static AnnotationEntryGen read(DataInputStream dis,
+                       ConstantPoolGen cpool, boolean b) throws IOException
+       {
+               AnnotationEntryGen a = new AnnotationEntryGen(cpool);
+               a.typeIndex = dis.readUnsignedShort();
+               int elemValuePairCount = dis.readUnsignedShort();
+               for (int i = 0; i < elemValuePairCount; i++)
+               {
+                       int nidx = dis.readUnsignedShort();
+                       a.addElementNameValuePair(new ElementValuePairGen(nidx,
+                                       ElementValueGen.readElementValue(dis, 
cpool), cpool));
+               }
+               a.isRuntimeVisible(b);
+               return a;
+       }
+
+       public void dump(DataOutputStream dos) throws IOException
+       {
+               dos.writeShort(typeIndex); // u2 index of type name in cpool
+               dos.writeShort(evs.size()); // u2 element_value pair count
+               for (int i = 0; i < evs.size(); i++)
+               {
+                       ElementValuePairGen envp = (ElementValuePairGen) 
evs.get(i);
+                       envp.dump(dos);
+               }
+       }
+
+       public void addElementNameValuePair(ElementValuePairGen evp)
+       {
+               if (evs == null)
+                       evs = new ArrayList();
+               evs.add(evp);
+       }
+
+       public int getTypeIndex()
+       {
+               return typeIndex;
+       }
+
+       public final String getTypeSignature()
+       {
+               // ConstantClass c = 
(ConstantClass)cpool.getConstant(typeIndex);
+               ConstantUtf8 utf8 = (ConstantUtf8) cpool
+                               .getConstant(typeIndex/* c.getNameIndex() */);
+               return utf8.getBytes();
+       }
+
+       public final String getTypeName()
+       {
+               return getTypeSignature();// BCELBUG: Should I use this instead?
+                                                                       // 
Utility.signatureToString(getTypeSignature());
+       }
+
+       /**
+        * Returns list of ElementNameValuePair objects
+        */
+       public List getValues()
+       {
+               return evs;
+       }
+
+       public String toString()
+       {
+               StringBuffer s = new StringBuffer();
+               s.append("AnnotationGen:[" + getTypeName() + " #" + evs.size() 
+ " {");
+               for (int i = 0; i < evs.size(); i++)
+               {
+                       s.append(evs.get(i));
+                       if (i + 1 < evs.size())
+                               s.append(",");
+               }
+               s.append("}]");
+               return s.toString();
+       }
+
+       public String toShortString()
+       {
+               StringBuffer s = new StringBuffer();
+               s.append("@" + getTypeName() + "(");
+               for (int i = 0; i < evs.size(); i++)
+               {
+                       s.append(evs.get(i));
+                       if (i + 1 < evs.size())
+                               s.append(",");
+               }
+               s.append(")");
+               return s.toString();
+       }
+
+       private void isRuntimeVisible(boolean b)
+       {
+               isRuntimeVisible = b;
+       }
+
+       public boolean isRuntimeVisible()
+       {
+               return isRuntimeVisible;
+       }
+}

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationEntryGen.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationGen.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationGen.java 
(original)
+++ jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/AnnotationGen.java 
Mon Jun 26 03:19:54 2006
@@ -1,5 +0,0 @@
-package org.apache.bcel.generic;
-
-public class AnnotationGen
-{
-}

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementNameValuePairGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementNameValuePairGen.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementNameValuePairGen.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementNameValuePairGen.java
 Mon Jun 26 03:19:54 2006
@@ -1,5 +0,0 @@
-package org.apache.bcel.generic;
-
-public class ElementNameValuePairGen
-{
-}

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java 
(original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValueGen.java 
Mon Jun 26 03:19:54 2006
@@ -98,8 +98,8 @@
                case 'e': // Enum constant
                        return new EnumElementValueGen(dis.readUnsignedShort(), 
dis
                                        .readUnsignedShort(), cpGen);
-               case 'c': // Class
-                       return new 
ClassElementValueGen(dis.readUnsignedShort(), cpGen);
+                       // case 'c': // Class
+                       // return new 
ClassElementValueGen(dis.readUnsignedShort(), cpGen);
                        //
                        // case '@': // Annotation
                        // return new
@@ -147,15 +147,15 @@
                case 'e': // Enum constant
                        return new EnumElementValueGen((EnumElementValue) 
value, cpool,
                                        copyPoolEntries);
-               case '@': // Annotation
-                       return new AnnotationElementValueGen(
-                                       (AnnotationElementValue) value, cpool, 
copyPoolEntries);
-               case '[': // Array
-                       return new ArrayElementValueGen((ArrayElementValue) 
value, cpool,
-                                       copyPoolEntries);
-               case 'c': // Class
-                       return new ClassElementValueGen((ClassElementValue) 
value, cpool,
-                                       copyPoolEntries);
+                       // case '@': // Annotation
+                       // return new AnnotationElementValueGen(
+                       // (AnnotationElementValue) value, cpool, 
copyPoolEntries);
+                       // case '[': // Array
+                       // return new ArrayElementValueGen((ArrayElementValue) 
value, cpool,
+                       // copyPoolEntries);
+                       // case 'c': // Class
+                       // return new ClassElementValueGen((ClassElementValue) 
value, cpool,
+                       //                                      
copyPoolEntries);
                default:
                        throw new RuntimeException("Not implemented yet! ("
                                        + value.getElementValueType() + ")");

Added: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java?rev=417157&view=auto
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
 (added)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
 Mon Jun 26 03:19:54 2006
@@ -0,0 +1,93 @@
+package org.apache.bcel.generic;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.ElementValue;
+import org.apache.bcel.classfile.ElementValuePair;
+
+public class ElementValuePairGen
+{
+       private int nameIdx;
+
+       private ElementValueGen value;
+
+       private ConstantPoolGen cpool;
+
+       public ElementValuePairGen(ElementValuePair nvp, ConstantPoolGen 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(nvp.getNameString());
+               }
+               else
+               {
+                       nameIdx = nvp.getNameIndex();
+               }
+               value = ElementValueGen.copy(nvp.getValue(), cpool, 
copyPoolEntries);
+       }
+
+       /**
+        * Retrieve an immutable version of this ElementNameValuePairGen
+        */
+       public ElementValuePair getElementNameValuePair()
+       {
+               ElementValue immutableValue = value.getElementValue();
+               return new ElementValuePair(nameIdx, immutableValue, cpool
+                               .getConstantPool());
+       }
+
+       protected ElementValuePairGen(int idx, ElementValueGen value,
+                       ConstantPoolGen cpool)
+       {
+               this.nameIdx = idx;
+               this.value = value;
+               this.cpool = cpool;
+       }
+
+       public ElementValuePairGen(String name, ElementValueGen value,
+                       ConstantPoolGen 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()
+       {
+               // ConstantString cu8 = 
(ConstantString)cpool.getConstant(nameIdx);
+               return ((ConstantUtf8) cpool.getConstant(nameIdx)).getBytes();
+       }
+
+       public final ElementValueGen getValue()
+       {
+               return value;
+       }
+
+       public String toString()
+       {
+               return "ElementValuePair:[" + getNameString() + "="
+                               + value.stringifyValue() + "]";
+       }
+}

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/ElementValuePairGen.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java?rev=417157&view=auto
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
 (added)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
 Mon Jun 26 03:19:54 2006
@@ -0,0 +1,119 @@
+package org.apache.bcel.generic;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.ElementValue;
+import org.apache.bcel.classfile.EnumElementValue;
+
+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,
+                       ConstantPoolGen 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 ElementValue getElementValue()
+       {
+               System.err.println("Duplicating value: " + getEnumTypeString() 
+ ":"
+                               + getEnumValueString());
+               return new EnumElementValue(type, typeIdx, valueIdx, cpGen
+                               .getConstantPool());
+       }
+
+       public EnumElementValueGen(ObjectType t, String value, ConstantPoolGen 
cpool)
+       {
+               super(ElementValueGen.ENUM_CONSTANT, cpool);
+               typeIdx = cpool.addUtf8(t.getSignature());// was addClass(t);
+               valueIdx = cpool.addUtf8(value);// was addString(value);
+       }
+
+       public EnumElementValueGen(EnumElementValue value, ConstantPoolGen 
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();
+               }
+       }
+
+       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
+       }
+
+       public String stringifyValue()
+       {
+               ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(
+                               valueIdx);
+               return cu8.getBytes();
+               // ConstantString cu8 =
+               // (ConstantString)getConstantPool().getConstant(valueIdx);
+               // return
+               // 
((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
+       }
+
+       // 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))
+                               .getBytes();
+               // return Utility.signatureToString(cu8.getBytes());
+       }
+
+       public String getEnumValueString()
+       {
+               return ((ConstantUtf8) getConstantPool().getConstant(valueIdx))
+                               .getBytes();
+               // ConstantString cu8 =
+               // (ConstantString)getConstantPool().getConstant(valueIdx);
+               // return
+               // 
((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
+       }
+
+       public int getValueIndex()
+       {
+               return valueIdx;
+       }
+
+       public int getTypeIndex()
+       {
+               return typeIdx;
+       }
+}

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/EnumElementValueGen.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/SimpleElementValueGen.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/SimpleElementValueGen.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/SimpleElementValueGen.java
 (original)
+++ 
jakarta/bcel/trunk/src/main/java/org/apache/bcel/generic/SimpleElementValueGen.java
 Mon Jun 26 03:19:54 2006
@@ -1,5 +1,245 @@
 package org.apache.bcel.generic;
 
+import java.io.DataOutputStream;
+import java.io.IOException;
+import org.apache.bcel.classfile.ConstantDouble;
+import org.apache.bcel.classfile.ConstantFloat;
+import org.apache.bcel.classfile.ConstantInteger;
+import org.apache.bcel.classfile.ConstantLong;
+import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.ElementValue;
+import org.apache.bcel.classfile.SimpleElementValue;
+
 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, ConstantPoolGen 
cpGen)
+       {
+               super(type, cpGen);
+               this.idx = idx;
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, int value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addInteger(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, long 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addLong(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, double 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addDouble(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, float 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addFloat(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, short 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addInteger(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, byte 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addInteger(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, char 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addInteger(value);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, boolean 
value)
+       {
+               super(type, cpGen);
+               if (value)
+                       idx = cpGen.addInteger(1);
+               else
+                       idx = cpGen.addInteger(0);
+       }
+
+       public SimpleElementValueGen(int type, ConstantPoolGen cpGen, String 
value)
+       {
+               super(type, cpGen);
+               idx = cpGen.addUtf8(value);
+       }
+
+       /**
+        * 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(SimpleElementValue value,
+                       ConstantPoolGen 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 ElementValue getElementValue()
+       {
+               return new SimpleElementValue(type, idx, 
cpGen.getConstantPool());
+       }
+
+       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.getBytes();
+       }
+
+       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.getBytes();
+       }
+
+       // Whatever kind of value it is, return it as a string
+       public String stringifyValue()
+       {
+               switch (type)
+               {
+               case PRIMITIVE_INT:
+                       ConstantInteger c = (ConstantInteger) 
cpGen.getConstant(idx);
+                       return Integer.toString(c.getBytes());
+               case PRIMITIVE_LONG:
+                       ConstantLong j = (ConstantLong) cpGen.getConstant(idx);
+                       return Long.toString(j.getBytes());
+               case PRIMITIVE_DOUBLE:
+                       ConstantDouble d = (ConstantDouble) 
cpGen.getConstant(idx);
+                       return Double.toString(d.getBytes());
+               case PRIMITIVE_FLOAT:
+                       ConstantFloat f = (ConstantFloat) 
cpGen.getConstant(idx);
+                       return Float.toString(f.getBytes());
+               case PRIMITIVE_SHORT:
+                       ConstantInteger s = (ConstantInteger) 
cpGen.getConstant(idx);
+                       return Integer.toString(s.getBytes());
+               case PRIMITIVE_BYTE:
+                       ConstantInteger b = (ConstantInteger) 
cpGen.getConstant(idx);
+                       return Integer.toString(b.getBytes());
+               case PRIMITIVE_CHAR:
+                       ConstantInteger ch = (ConstantInteger) 
cpGen.getConstant(idx);
+                       return Integer.toString(ch.getBytes());
+               case PRIMITIVE_BOOLEAN:
+                       ConstantInteger bo = (ConstantInteger) 
cpGen.getConstant(idx);
+                       if (bo.getBytes() == 0)
+                               return "false";
+                       if (bo.getBytes() != 0)
+                               return "true";
+               case STRING:
+                       ConstantUtf8 cu8 = (ConstantUtf8) 
cpGen.getConstant(idx);
+                       return cu8.getBytes();
+               default:
+                       throw new RuntimeException(
+                                       "SimpleElementValueGen class does not 
know how to stringify type "
+                                                       + type);
+               }
+       }
+
+       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);
+               }
+       }
 }

Modified: 
jakarta/bcel/trunk/src/test/java/org/apache/bcel/AnnotationGenTestCase.java
URL: 
http://svn.apache.org/viewvc/jakarta/bcel/trunk/src/test/java/org/apache/bcel/AnnotationGenTestCase.java?rev=417157&r1=417156&r2=417157&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/test/java/org/apache/bcel/AnnotationGenTestCase.java 
(original)
+++ jakarta/bcel/trunk/src/test/java/org/apache/bcel/AnnotationGenTestCase.java 
Mon Jun 26 03:19:54 2006
@@ -8,15 +8,16 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Vector;
+import org.apache.bcel.classfile.Annotations;
 import org.apache.bcel.classfile.Attribute;
 import org.apache.bcel.classfile.RuntimeInvisibleAnnotations;
 import org.apache.bcel.classfile.RuntimeVisibleAnnotations;
 import org.apache.bcel.classfile.Utility;
-import org.apache.bcel.generic.AnnotationGen;
+import org.apache.bcel.generic.AnnotationEntryGen;
 import org.apache.bcel.generic.ClassGen;
 import org.apache.bcel.generic.ConstantPoolGen;
-import org.apache.bcel.generic.ElementNameValuePairGen;
 import org.apache.bcel.generic.ElementValueGen;
+import org.apache.bcel.generic.ElementValuePairGen;
 import org.apache.bcel.generic.ObjectType;
 import org.apache.bcel.generic.SimpleElementValueGen;
 
@@ -40,7 +41,7 @@
                SimpleElementValueGen evg = new SimpleElementValueGen(
                                ElementValueGen.PRIMITIVE_INT, cp, 4);
                // Give it a name, call it 'id'
-               ElementNameValuePairGen nvGen = new 
ElementNameValuePairGen("id", evg,
+               ElementValuePairGen nvGen = new ElementValuePairGen("id", evg,
                                cp);
                // Check it looks right
                assertTrue(
@@ -51,7 +52,7 @@
                elements.add(nvGen);
                // Build an annotation of type 'SimpleAnnotation' with 'id=4' 
as the
                // only value :)
-               AnnotationGen a = new AnnotationGen(t, elements, true, cp);
+               AnnotationEntryGen a = new AnnotationEntryGen(t, elements, 
true, cp);
                // Check we can save and load it ok
                checkSerialize(a, cp);
        }
@@ -65,7 +66,7 @@
                SimpleElementValueGen evg = new SimpleElementValueGen(
                                ElementValueGen.PRIMITIVE_INT, cp, 4);
                // Give it a name, call it 'id'
-               ElementNameValuePairGen nvGen = new 
ElementNameValuePairGen("id", evg,
+               ElementValuePairGen nvGen = new ElementValuePairGen("id", evg,
                                cp);
                // Check it looks right
                assertTrue(
@@ -76,7 +77,7 @@
                elements.add(nvGen);
                // Build a RV annotation of type 'SimpleAnnotation' with 'id=4' 
as the
                // only value :)
-               AnnotationGen a = new AnnotationGen(t, elements, true, cp);
+               AnnotationEntryGen a = new AnnotationEntryGen(t, elements, 
true, cp);
                Vector v = new Vector();
                v.add(a);
                Attribute[] attributes = Utility.getAnnotationAttributes(cp, v);
@@ -86,14 +87,14 @@
                        Attribute attribute = attributes[i];
                        if (attribute instanceof RuntimeVisibleAnnotations)
                        {
-                               assertTrue(((RuntimeAnnotations) 
attribute).areVisible());
+                               assertTrue(((Annotations) 
attribute).isRuntimeVisible());
                                foundRV = true;
                        }
                }
                assertTrue("Should have seen a RuntimeVisibleAnnotation", 
foundRV);
                // Build a RIV annotation of type 'SimpleAnnotation' with 
'id=4' as the
                // only value :)
-               AnnotationGen a2 = new AnnotationGen(t, elements, false, cp);
+               AnnotationEntryGen a2 = new AnnotationEntryGen(t, elements, 
false, cp);
                Vector v2 = new Vector();
                v2.add(a2);
                Attribute[] attributes2 = Utility.getAnnotationAttributes(cp, 
v2);
@@ -103,14 +104,14 @@
                        Attribute attribute = attributes2[i];
                        if (attribute instanceof RuntimeInvisibleAnnotations)
                        {
-                               assertFalse(((RuntimeAnnotations) 
attribute).areVisible());
+                               assertFalse(((Annotations) 
attribute).isRuntimeVisible());
                                foundRIV = true;
                        }
                }
                assertTrue("Should have seen a RuntimeInvisibleAnnotation", 
foundRIV);
        }
 
-       private void checkSerialize(AnnotationGen a, ConstantPoolGen cpg)
+       private void checkSerialize(AnnotationEntryGen a, ConstantPoolGen cpg)
        {
                try
                {
@@ -124,7 +125,7 @@
                        byte[] bs = baos.toByteArray();
                        ByteArrayInputStream bais = new 
ByteArrayInputStream(bs);
                        DataInputStream dis = new DataInputStream(bais);
-                       AnnotationGen annAfter = AnnotationGen.read(dis, cpg, a
+                       AnnotationEntryGen annAfter = 
AnnotationEntryGen.read(dis, cpg, a
                                        .isRuntimeVisible());
                        dis.close();
                        String afterName = annAfter.getTypeName();
@@ -142,9 +143,9 @@
                        }
                        for (int i = 0; i < a.getValues().size(); i++)
                        {
-                               ElementNameValuePairGen beforeElement = 
(ElementNameValuePairGen) a
+                               ElementValuePairGen beforeElement = 
(ElementValuePairGen) a
                                                .getValues().get(i);
-                               ElementNameValuePairGen afterElement = 
(ElementNameValuePairGen) annAfter
+                               ElementValuePairGen afterElement = 
(ElementValuePairGen) annAfter
                                                .getValues().get(i);
                                if (!beforeElement.getNameString().equals(
                                                afterElement.getNameString()))



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to