Sync with Commons BCEL (moved from Jakarta)
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Oct 2011 18:37:14 +0000 (18:37 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 10 Oct 2011 18:37:14 +0000 (18:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1181123 13f79535-47bb-0310-9956-ffa450edef68

33 files changed:
java/org/apache/tomcat/util/bcel/classfile/AnnotationElementValue.java
java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java
java/org/apache/tomcat/util/bcel/classfile/Annotations.java
java/org/apache/tomcat/util/bcel/classfile/ArrayElementValue.java
java/org/apache/tomcat/util/bcel/classfile/AttributeReader.java
java/org/apache/tomcat/util/bcel/classfile/Code.java
java/org/apache/tomcat/util/bcel/classfile/ConstantFieldref.java
java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java
java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java
java/org/apache/tomcat/util/bcel/classfile/ConstantInterfaceMethodref.java
java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java
java/org/apache/tomcat/util/bcel/classfile/ConstantMethodref.java
java/org/apache/tomcat/util/bcel/classfile/ConstantObject.java
java/org/apache/tomcat/util/bcel/classfile/ConstantPool.java
java/org/apache/tomcat/util/bcel/classfile/ConstantString.java
java/org/apache/tomcat/util/bcel/classfile/ElementValue.java
java/org/apache/tomcat/util/bcel/classfile/EnumElementValue.java
java/org/apache/tomcat/util/bcel/classfile/ExceptionTable.java
java/org/apache/tomcat/util/bcel/classfile/Field.java
java/org/apache/tomcat/util/bcel/classfile/InnerClasses.java
java/org/apache/tomcat/util/bcel/classfile/JavaClass.java
java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java
java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java
java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java
java/org/apache/tomcat/util/bcel/classfile/Method.java
java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
java/org/apache/tomcat/util/bcel/classfile/StackMap.java
java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java
java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java
java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java
java/org/apache/tomcat/util/bcel/classfile/Synthetic.java
java/org/apache/tomcat/util/bcel/classfile/Utility.java
java/org/apache/tomcat/util/bcel/util/BCELComparator.java

index 0965ea0..d9888c0 100644 (file)
@@ -45,9 +45,7 @@ public class AnnotationElementValue extends ElementValue
     @Override
     public String stringifyValue()
     {
-        StringBuffer sb = new StringBuffer();
-        sb.append(annotationEntry.toString());
-        return sb.toString();
+        return annotationEntry.toString();
     }
 
     @Override
index b633bc2..9ec1a85 100644 (file)
@@ -37,8 +37,8 @@ public class AnnotationEntry implements Constants, Serializable {
 
     private static final long serialVersionUID = 1L;
     
-    private int type_index;
-    private ConstantPool constant_pool;
+    private final int type_index;
+    private final ConstantPool constant_pool;
 
     private List<ElementValuePair> element_value_pairs;
     
@@ -47,6 +47,7 @@ public class AnnotationEntry implements Constants, Serializable {
      * 
      * @param file
      * @param constant_pool
+     * @return the entry
      * @throws IOException
      */
     public static AnnotationEntry read(DataInputStream file, ConstantPool constant_pool) throws IOException {
@@ -78,19 +79,17 @@ public class AnnotationEntry implements Constants, Serializable {
      * @return the element value pairs in this annotation entry
      */
     public ElementValuePair[] getElementValuePairs() {
-        // TOFO return List
+        // TODO return List
         return element_value_pairs.toArray(new ElementValuePair[element_value_pairs.size()]);
     }
 
-
-    public void dump(DataOutputStream dos) throws IOException
-    {
-        dos.writeShort(type_index);    // u2 index of type name in cpool
-        dos.writeShort(element_value_pairs.size()); // u2 element_value pair count
-        for (int i = 0 ; i<element_value_pairs.size();i++) {
-            ElementValuePair envp = element_value_pairs.get(i);
+    public void dump(DataOutputStream dos) throws IOException {
+        dos.writeShort(type_index); // u2 index of type name in cpool
+        dos.writeShort(element_value_pairs.size()); // u2 element_value pair
+        // count
+        for (int i = 0; i < element_value_pairs.size(); i++) {
+            final ElementValuePair envp = element_value_pairs.get(i);
             envp.dump(dos);
         }
     }
-
 }
index 7a38f6a..7558c57 100644 (file)
@@ -82,7 +82,8 @@ public abstract class Annotations extends Attribute {
             return;
         }
         dos.writeShort(annotation_table.length);
-        for (int i = 0; i < annotation_table.length; i++)
+        for (int i = 0; i < annotation_table.length; i++) {
             annotation_table[i].dump(dos);
+        }
     }
 }
index c4c5639..0c3804d 100644 (file)
@@ -28,7 +28,7 @@ public class ArrayElementValue extends ElementValue
     @Override
     public String toString()
     {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append("{");
         for (int i = 0; i < evalues.length; i++)
         {
@@ -63,7 +63,7 @@ public class ArrayElementValue extends ElementValue
     @Override
     public String stringifyValue()
     {
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         sb.append("[");
         for (int i = 0; i < evalues.length; i++)
         {
@@ -79,6 +79,4 @@ public class ArrayElementValue extends ElementValue
     {
         return evalues;
     }
-
-    
 }
index e596ebb..527ca32 100644 (file)
@@ -52,6 +52,6 @@ public interface AttributeReader {
      it to construct an attribute.  In the case of errors, a null can be
      returned which will cause the parsing of the class file to fail.
      */
-    public Attribute createAttribute( int name_index, int length, java.io.DataInputStream file,
+    Attribute createAttribute( int name_index, int length, java.io.DataInputStream file,
             ConstantPool constant_pool );
 }
index 80b7a31..e4cd5dc 100644 (file)
@@ -193,6 +193,7 @@ public final class Code extends Attribute {
     public final void setCode( byte[] code ) {
         this.code = code;
         code_length = (code == null) ? 0 : code.length;
+        length = calculateLength(); // Adjust length
     }
 
 
@@ -202,6 +203,7 @@ public final class Code extends Attribute {
     public final void setExceptionTable( CodeException[] exception_table ) {
         this.exception_table = exception_table;
         exception_table_length = (exception_table == null) ? 0 : exception_table.length;
+        length = calculateLength(); // Adjust length
     }
 
 
@@ -209,8 +211,7 @@ public final class Code extends Attribute {
      * @return String representation of code chunk.
      */
     public final String toString( boolean verbose ) {
-        StringBuffer buf;
-        buf = new StringBuffer(100);
+        StringBuilder buf = new StringBuilder(100);
         buf.append("Code(max_stack = ").append(max_stack).append(", max_locals = ").append(
                 max_locals).append(", code_length = ").append(code_length).append(")\n").append(
                 Utility.codeToString(code, constant_pool, 0, -1, verbose));
index 58e03de..fb946a9 100644 (file)
@@ -42,6 +42,4 @@ public final class ConstantFieldref extends ConstantCP {
     ConstantFieldref(DataInputStream file) throws IOException {
         super(Constants.CONSTANT_Fieldref, file);
     }
-
-
 }
index 23650af..66614d3 100644 (file)
@@ -86,6 +86,4 @@ public final class ConstantFloat extends Constant implements ConstantObject {
     public final String toString() {
         return super.toString() + "(bytes = " + bytes + ")";
     }
-
-
 }
index 64a403e..7cc87d0 100644 (file)
@@ -86,6 +86,4 @@ public final class ConstantInteger extends Constant implements ConstantObject {
     public final String toString() {
         return super.toString() + "(bytes = " + bytes + ")";
     }
-
-
 }
index b9acf71..5dbe87d 100644 (file)
@@ -42,6 +42,4 @@ public final class ConstantInterfaceMethodref extends ConstantCP {
     ConstantInterfaceMethodref(DataInputStream file) throws IOException {
         super(Constants.CONSTANT_InterfaceMethodref, file);
     }
-
-
 }
index 1161852..1ba3bab 100644 (file)
@@ -86,6 +86,4 @@ public final class ConstantLong extends Constant implements ConstantObject {
     public final String toString() {
         return super.toString() + "(bytes = " + bytes + ")";
     }
-
-
 }
index 58419ac..a83c41b 100644 (file)
@@ -42,6 +42,4 @@ public final class ConstantMethodref extends ConstantCP {
     ConstantMethodref(DataInputStream file) throws IOException {
         super(Constants.CONSTANT_Methodref, file);
     }
-
-
 }
index 673b299..00d4bd8 100644 (file)
@@ -131,7 +131,7 @@ public class ConstantPool implements Cloneable, Serializable {
 
     private static final String escape( String str ) {
         int len = str.length();
-        StringBuffer buf = new StringBuffer(len + 5);
+        StringBuilder buf = new StringBuilder(len + 5);
         char[] ch = str.toCharArray();
         for (int i = 0; i < len; i++) {
             switch (ch[i]) {
@@ -265,7 +265,7 @@ public class ConstantPool implements Cloneable, Serializable {
      */
     @Override
     public String toString() {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         for (int i = 1; i < constant_pool_count; i++) {
             buf.append(i).append(")").append(constant_pool[i]).append("\n");
         }
index 2b861fa..0ffdb5a 100644 (file)
@@ -86,6 +86,4 @@ public final class ConstantString extends Constant implements ConstantObject {
     public final String toString() {
         return super.toString() + "(string_index = " + string_index + ")";
     }
-
-
 }
index cdd4d7e..3934fdc 100644 (file)
@@ -130,6 +130,4 @@ public abstract class ElementValue
                     "Unexpected element value kind in annotation: " + type);
         }
     }
-
-    
 }
index 3837e2a..d91561c 100644 (file)
@@ -55,5 +55,4 @@ public class EnumElementValue extends ElementValue
                 Constants.CONSTANT_Utf8);
         return cu8.getBytes();
     }
-
 }
index c401ae7..5f04ae5 100644 (file)
@@ -105,7 +105,7 @@ public final class ExceptionTable extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         String str;
         for (int i = 0; i < number_of_exceptions; i++) {
             str = constant_pool.getConstantString(exception_index_table[i],
index 788466b..3a43625 100644 (file)
@@ -89,7 +89,7 @@ public final class Field extends FieldOrMethod {
         access = access.equals("") ? "" : (access + " ");
         signature = Utility.signatureToString(getSignature());
         name = getName();
-        StringBuffer buf = new StringBuffer(64);
+        StringBuilder buf = new StringBuilder(64);
         buf.append(access).append(signature).append(" ").append(name);
         ConstantValue cv = getConstantValue();
         if (cv != null) {
index 87b5e05..f69f815 100644 (file)
@@ -103,7 +103,7 @@ public final class InnerClasses extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         for (int i = 0; i < number_of_classes; i++) {
             buf.append(inner_classes[i].toString(constant_pool)).append("\n");
         }
index 818af8f..70cb11d 100644 (file)
@@ -186,7 +186,7 @@ public class JavaClass extends AccessFlags
     public String toString() {
         String access = Utility.accessToString(access_flags, true);
         access = access.equals("") ? "" : (access + " ");
-        StringBuffer buf = new StringBuffer(128);
+        StringBuilder buf = new StringBuilder(128);
         buf.append(access).append(Utility.classOrInterface(access_flags)).append(" ").append(
                 class_name).append(" extends ").append(
                 Utility.compactClassName(superclass_name, false)).append('\n');
@@ -237,7 +237,7 @@ public class JavaClass extends AccessFlags
 
     private static final String indent( Object obj ) {
         StringTokenizer tok = new StringTokenizer(obj.toString(), "\n");
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         while (tok.hasMoreTokens()) {
             buf.append("\t").append(tok.nextToken()).append("\n");
         }
index ca28667..5feaa97 100644 (file)
@@ -102,8 +102,8 @@ public final class LineNumberTable extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer();
-        StringBuffer line = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
+        StringBuilder line = new StringBuilder();
         String newLine = System.getProperty("line.separator", "\n");
         for (int i = 0; i < line_number_table_length; i++) {
             line.append(line_number_table[i].toString());
@@ -134,6 +134,4 @@ public final class LineNumberTable extends Attribute {
         c.constant_pool = _constant_pool;
         return c;
     }
-
-
 }
index 67243df..3127ff0 100644 (file)
@@ -119,7 +119,7 @@ public class LocalVariableTable extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         for (int i = 0; i < local_variable_table_length; i++) {
             buf.append(local_variable_table[i].toString());
             if (i < local_variable_table_length - 1) {
@@ -143,6 +143,4 @@ public class LocalVariableTable extends Attribute {
         c.constant_pool = _constant_pool;
         return c;
     }
-
-
 }
index 445be64..afa2133 100644 (file)
@@ -93,7 +93,7 @@ private int             local_variable_type_table_length; // Table of local
    */ 
   @Override
   public final String toString() {
-    StringBuffer buf = new StringBuffer("");
+      StringBuilder buf = new StringBuilder();
 
     for(int i=0; i < local_variable_type_table_length; i++) {
       buf.append(local_variable_type_table[i].toString());
index 058ba74..eb32267 100644 (file)
@@ -122,7 +122,7 @@ public final class Method extends FieldOrMethod {
     public final String toString() {
         ConstantUtf8 c;
         String name, signature, access; // Short cuts to constant pool
-        StringBuffer buf;
+        StringBuilder buf;
         access = Utility.accessToString(access_flags);
         // Get name and signature from constant pool
         c = (ConstantUtf8) constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8);
@@ -131,7 +131,7 @@ public final class Method extends FieldOrMethod {
         name = c.getBytes();
         signature = Utility.methodSignatureToString(signature, name, access, true,
                 getLocalVariableTable());
-        buf = new StringBuffer(signature);
+        buf = new StringBuilder(signature);
         for (int i = 0; i < attributes_count; i++) {
             Attribute a = attributes[i];
             if (!((a instanceof Code) || (a instanceof ExceptionTable))) {
index 2947bf4..bb5cadb 100644 (file)
@@ -77,5 +77,4 @@ public abstract class ParameterAnnotations extends Attribute {
                 ? 0
                 : parameter_annotation_table.length;
     }
-    
 }
index 1971490..68918cd 100644 (file)
@@ -106,7 +106,7 @@ public final class StackMap extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer("StackMap(");
+        StringBuilder buf = new StringBuilder("StackMap(");
         for (int i = 0; i < map_length; i++) {
             buf.append(map[i].toString());
             if (i < map_length - 1) {
index fcdf120..2608470 100644 (file)
@@ -97,7 +97,7 @@ public final class StackMapEntry implements Cloneable, Serializable {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer(64);
+        StringBuilder buf = new StringBuilder(64);
         buf.append("(offset=").append(byte_code_offset);
         if (number_of_locals > 0) {
             buf.append(", locals={");
index 35a7325..9389433 100644 (file)
@@ -106,7 +106,7 @@ public final class StackMapTable extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer("StackMapTable(");
+        StringBuilder buf = new StringBuilder("StackMapTable(");
         for (int i = 0; i < map_length; i++) {
             buf.append(map[i].toString());
             if (i < map_length - 1) {
index 314afd3..4f710a7 100644 (file)
@@ -154,7 +154,7 @@ public final class StackMapTableEntry implements Cloneable, Serializable {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer(64);
+        StringBuilder buf = new StringBuilder(64);
         buf.append("(");
         if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
             buf.append("SAME");
@@ -209,6 +209,4 @@ public final class StackMapTableEntry implements Cloneable, Serializable {
         }
         return null;
     }
-
-
 }
index 89b4d26..71066ac 100644 (file)
@@ -95,7 +95,7 @@ public final class Synthetic extends Attribute {
      */
     @Override
     public final String toString() {
-        StringBuffer buf = new StringBuffer("Synthetic");
+        StringBuilder buf = new StringBuilder("Synthetic");
         if (length > 0) {
             buf.append(" ").append(Utility.toHexString(bytes));
         }
index 5525763..f83b04a 100644 (file)
@@ -36,14 +36,14 @@ public abstract class Utility {
 
 
     private static void wrap( ThreadLocal<Integer> tl, int value ) {
-        tl.set(new Integer(value));
+        tl.set(Integer.valueOf(value));
     }
 
     private static ThreadLocal<Integer> consumed_chars =
             new ThreadLocal<Integer>() {
         @Override
         protected Integer initialValue() {
-            return new Integer(0);
+            return Integer.valueOf(0);
         }
     };/* How many chars have been consumed
      * during parsing in signatureToString().
@@ -85,7 +85,7 @@ public abstract class Utility {
      * @return String representation of flags
      */
     public static final String accessToString( int access_flags, boolean for_class ) {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         int p = 0;
         for (int i = 0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags
             p = pow2(i);
@@ -131,7 +131,7 @@ public abstract class Utility {
      */
     public static final String codeToString( byte[] code, ConstantPool constant_pool, int index,
             int length, boolean verbose ) {
-        StringBuffer buf = new StringBuffer(code.length * 20); // Should be sufficient
+        StringBuilder buf = new StringBuilder(code.length * 20); // Should be sufficient
         ByteSequence stream = new ByteSequence(code);
         try {
             for (int i = 0; i < index; i++) {
@@ -171,7 +171,7 @@ public abstract class Utility {
         int index, vindex, constant;
         int[] match, jump_table;
         int no_pad_bytes = 0, offset;
-        StringBuffer buf = new StringBuffer(Constants.OPCODE_NAMES[opcode]);
+        StringBuilder buf = new StringBuilder(Constants.OPCODE_NAMES[opcode]);
         /* Special case: Skip (0-3) padding bytes, i.e., the
          * following bytes are 4-byte-aligned
          */
@@ -489,7 +489,7 @@ public abstract class Utility {
      */
     public static final String methodSignatureToString( String signature, String name,
             String access, boolean chopit, LocalVariableTable vars ) throws ClassFormatException {
-        StringBuffer buf = new StringBuffer("(");
+        StringBuilder buf = new StringBuilder("(");
         String type;
         int index;
         int var_index = (access.indexOf("static") >= 0) ? 0 : 1;
@@ -646,10 +646,10 @@ public abstract class Utility {
                     return "boolean";
                 case '[': { // Array declaration
                     int n;
-                    StringBuffer brackets;
+                    StringBuilder brackets;
                     String type;
                     int consumed_chars; // Shadows global var
-                    brackets = new StringBuffer(); // Accumulate []'s
+                    brackets = new StringBuilder(); // Accumulate []'s
                     // Count opening brackets and look for optional size argument
                     for (n = 0; signature.charAt(n) == '['; n++) {
                         brackets.append("[]");
@@ -689,7 +689,7 @@ public abstract class Utility {
      * @return bytes as hexadecimal string, e.g. 00 FA 12 ...
      */
     public static final String toHexString( byte[] bytes ) {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         for (int i = 0; i < bytes.length; i++) {
             short b = byteToShort(bytes[i]);
             String hex = Integer.toString(b, 0x10);
@@ -753,7 +753,7 @@ public abstract class Utility {
      */
     public static final String convertString( String label ) {
         char[] ch = label.toCharArray();
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         for (int i = 0; i < ch.length; i++) {
             switch (ch[i]) {
                 case '\n':
@@ -778,6 +778,4 @@ public abstract class Utility {
         }
         return buf.toString();
     }
-
-
 }
index 14204d5..2d68865 100644 (file)
@@ -33,7 +33,7 @@ public interface BCELComparator {
      * @param THAT
      * @return true if and only if THIS equals THAT
      */
-    public boolean equals( Object THIS, Object THAT );
+    boolean equals( Object THIS, Object THAT );
 
 
     /**
@@ -42,5 +42,5 @@ public interface BCELComparator {
      * @param THIS
      * @return hashcode for THIS.hashCode()
      */
-    public int hashCode( Object THIS );
+    int hashCode( Object THIS );
 }