commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1663628 - /commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/
Date Tue, 03 Mar 2015 10:56:39 GMT
Author: ebourg
Date: Tue Mar  3 10:56:38 2015
New Revision: 1663628

URL: http://svn.apache.org/r1663628
Log:
Removed the redundant num/length/count fields

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Code.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Field.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Method.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMap.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ClassParser.java Tue
Mar  3 10:56:38 2015
@@ -195,8 +195,7 @@ public final class ClassParser {
      * @throws  ClassFormatException
      */
     private void readAttributes() throws IOException, ClassFormatException {
-        int attributes_count;
-        attributes_count = dataInputStream.readUnsignedShort();
+        int attributes_count = dataInputStream.readUnsignedShort();
         attributes = new Attribute[attributes_count];
         for (int i = 0; i < attributes_count; i++) {
             attributes[i] = Attribute.readAttribute(dataInputStream, constant_pool);
@@ -242,8 +241,7 @@ public final class ClassParser {
      * @throws  ClassFormatException
      */
     private void readFields() throws IOException, ClassFormatException {
-        int fields_count;
-        fields_count = dataInputStream.readUnsignedShort();
+        int fields_count = dataInputStream.readUnsignedShort();
         fields = new Field[fields_count];
         for (int i = 0; i < fields_count; i++) {
             fields[i] = new Field(dataInputStream, constant_pool);
@@ -272,8 +270,7 @@ public final class ClassParser {
      * @throws  ClassFormatException
      */
     private void readInterfaces() throws IOException, ClassFormatException {
-        int interfaces_count;
-        interfaces_count = dataInputStream.readUnsignedShort();
+        int interfaces_count = dataInputStream.readUnsignedShort();
         interfaces = new int[interfaces_count];
         for (int i = 0; i < interfaces_count; i++) {
             interfaces[i] = dataInputStream.readUnsignedShort();
@@ -287,8 +284,7 @@ public final class ClassParser {
      * @throws  ClassFormatException
      */
     private void readMethods() throws IOException, ClassFormatException {
-        int methods_count;
-        methods_count = dataInputStream.readUnsignedShort();
+        int methods_count = dataInputStream.readUnsignedShort();
         methods = new Method[methods_count];
         for (int i = 0; i < methods_count; i++) {
             methods[i] = new Method(dataInputStream, constant_pool);

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Code.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Code.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Code.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Code.java Tue Mar  3
10:56:38 2015
@@ -46,11 +46,8 @@ public final class Code extends Attribut
     private static final long serialVersionUID = -432884354459701506L;
     private int max_stack; // Maximum size of stack used by this method
     private int max_locals; // Number of local variables
-    private int code_length; // Length of code in bytes
     private byte[] code; // Actual byte code
-    private int exception_table_length;
     private CodeException[] exception_table; // Table of handled exceptions
-    private int attributes_count; // Attributes of code: LineNumber
     private Attribute[] attributes; // or LocalVariable
 
 
@@ -75,13 +72,13 @@ public final class Code extends Attribut
         // 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);
-        code_length = file.readInt();
+        int code_length = file.readInt();
         code = new byte[code_length]; // 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.
          */
-        exception_table_length = file.readUnsignedShort();
+        int exception_table_length = file.readUnsignedShort();
         exception_table = new CodeException[exception_table_length];
         for (int i = 0; i < exception_table_length; i++) {
             exception_table[i] = new CodeException(file);
@@ -89,7 +86,7 @@ public final class Code extends Attribut
         /* Read all attributes, currently `LineNumberTable' and
          * `LocalVariableTable'
          */
-        attributes_count = file.readUnsignedShort();
+        int attributes_count = file.readUnsignedShort();
         attributes = new Attribute[attributes_count];
         for (int i = 0; i < attributes_count; i++) {
             attributes[i] = Attribute.readAttribute(file, constant_pool);
@@ -147,15 +144,15 @@ public final class Code extends Attribut
         super.dump(file);
         file.writeShort(max_stack);
         file.writeShort(max_locals);
-        file.writeInt(code_length);
-        file.write(code, 0, code_length);
-        file.writeShort(exception_table_length);
-        for (int i = 0; i < exception_table_length; i++) {
-            exception_table[i].dump(file);
-        }
-        file.writeShort(attributes_count);
-        for (int i = 0; i < attributes_count; i++) {
-            attributes[i].dump(file);
+        file.writeInt(code.length);
+        file.write(code, 0, code.length);
+        file.writeShort(exception_table.length);
+        for (CodeException exception : exception_table) {
+            exception.dump(file);
+        }
+        file.writeShort(attributes.length);
+        for (Attribute attribute : attributes) {
+            attribute.dump(file);
         }
     }
 
@@ -173,9 +170,9 @@ public final class Code extends Attribut
      * @return LineNumberTable of Code, if it has one
      */
     public LineNumberTable getLineNumberTable() {
-        for (int i = 0; i < attributes_count; i++) {
-            if (attributes[i] instanceof LineNumberTable) {
-                return (LineNumberTable) attributes[i];
+        for (Attribute attribute : attributes) {
+            if (attribute instanceof LineNumberTable) {
+                return (LineNumberTable) attribute;
             }
         }
         return null;
@@ -186,9 +183,9 @@ public final class Code extends Attribut
      * @return LocalVariableTable of Code, if it has one
      */
     public LocalVariableTable getLocalVariableTable() {
-        for (int i = 0; i < attributes_count; i++) {
-            if (attributes[i] instanceof LocalVariableTable) {
-                return (LocalVariableTable) attributes[i];
+        for (Attribute attribute : attributes) {
+            if (attribute instanceof LocalVariableTable) {
+                return (LocalVariableTable) attribute;
             }
         }
         return null;
@@ -234,9 +231,9 @@ public final class Code extends Attribut
      */
     private int getInternalLength() {
         return 2 /*max_stack*/+ 2 /*max_locals*/+ 4 /*code length*/
-                + code_length /*byte-code*/
+                + code.length /*byte-code*/
                 + 2 /*exception-table length*/
-                + 8 * exception_table_length /* exception table */
+                + 8 * exception_table.length /* exception table */
                 + 2 /* attributes count */;
     }
 
@@ -247,8 +244,8 @@ public final class Code extends Attribut
      */
     private int calculateLength() {
         int len = 0;
-        for (int i = 0; i < attributes_count; i++) {
-            len += attributes[i].length + 6 /*attribute header size*/;
+        for (Attribute attribute : attributes) {
+            len += attribute.length + 6 /*attribute header size*/;
         }
         return len + getInternalLength();
     }
@@ -259,7 +256,6 @@ public final class Code extends Attribut
      */
     public final void setAttributes( Attribute[] attributes ) {
         this.attributes = attributes;
-        attributes_count = (attributes == null) ? 0 : attributes.length;
         length = calculateLength(); // Adjust length
     }
 
@@ -269,7 +265,6 @@ public final class Code extends Attribut
      */
     public final void setCode( byte[] code ) {
         this.code = code;
-        code_length = (code == null) ? 0 : code.length;
         length = calculateLength(); // Adjust length
     }
 
@@ -279,7 +274,6 @@ public final class Code extends Attribut
      */
     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
     }
 
@@ -306,18 +300,18 @@ public final class Code extends Attribut
     public final String toString( boolean verbose ) {
         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(
+                max_locals).append(", code_length = ").append(code.length).append(")\n").append(
                 Utility.codeToString(code, constant_pool, 0, -1, verbose));
-        if (exception_table_length > 0) {
+        if (exception_table.length > 0) {
             buf.append("\nException handler(s) = \n").append("From\tTo\tHandler\tType\n");
-            for (int i = 0; i < exception_table_length; i++) {
-                buf.append(exception_table[i].toString(constant_pool, verbose)).append("\n");
+            for (CodeException exception : exception_table) {
+                buf.append(exception.toString(constant_pool, verbose)).append("\n");
             }
         }
-        if (attributes_count > 0) {
+        if (attributes.length > 0) {
             buf.append("\nAttribute(s) = \n");
-            for (int i = 0; i < attributes_count; i++) {
-                buf.append(attributes[i].toString()).append("\n");
+            for (Attribute attribute : attributes) {
+                buf.append(attribute.toString()).append("\n");
             }
         }
         return buf.toString();
@@ -346,12 +340,12 @@ public final class Code extends Attribut
             System.arraycopy(code, 0, c.code, 0, code.length);
         }
         c.constant_pool = _constant_pool;
-        c.exception_table = new CodeException[exception_table_length];
-        for (int i = 0; i < exception_table_length; i++) {
+        c.exception_table = new CodeException[exception_table.length];
+        for (int i = 0; i < exception_table.length; i++) {
             c.exception_table[i] = exception_table[i].copy();
         }
-        c.attributes = new Attribute[attributes_count];
-        for (int i = 0; i < attributes_count; i++) {
+        c.attributes = new Attribute[attributes.length];
+        for (int i = 0; i < attributes.length; i++) {
             c.attributes[i] = attributes[i].copy(_constant_pool);
         }
         return c;

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java Tue
Mar  3 10:56:38 2015
@@ -39,7 +39,6 @@ import org.apache.bcel.Constants;
 public class ConstantPool implements Cloneable, Node, Serializable {
 
     private static final long serialVersionUID = -9093478476423540196L;
-    private int constant_pool_count;
     private Constant[] constant_pool;
 
 
@@ -60,7 +59,7 @@ public class ConstantPool implements Clo
      */
     ConstantPool(DataInput input) throws IOException, ClassFormatException {
         byte tag;
-        constant_pool_count = input.readUnsignedShort();
+        int constant_pool_count = input.readUnsignedShort();
         constant_pool = new Constant[constant_pool_count];
         /* constant_pool[0] is unused by the compiler and may be used freely
          * by the implementation.
@@ -212,8 +211,8 @@ public class ConstantPool implements Clo
      * @throws IOException
      */
     public void dump( DataOutputStream file ) throws IOException {
-        file.writeShort(constant_pool_count);
-        for (int i = 1; i < constant_pool_count; i++) {
+        file.writeShort(constant_pool.length);
+        for (int i = 1; i < constant_pool.length; i++) {
             if (constant_pool[i] != null) {
                 constant_pool[i].dump(file);
             }
@@ -314,7 +313,7 @@ public class ConstantPool implements Clo
      * @return Length of constant pool.
      */
     public int getLength() {
-        return constant_pool_count;
+        return constant_pool == null ? 0 : constant_pool.length;
     }
 
 
@@ -331,7 +330,6 @@ public class ConstantPool implements Clo
      */
     public void setConstantPool( Constant[] constant_pool ) {
         this.constant_pool = constant_pool;
-        constant_pool_count = (constant_pool == null) ? 0 : constant_pool.length;
     }
 
 
@@ -341,7 +339,7 @@ public class ConstantPool implements Clo
     @Override
     public String toString() {
         StringBuilder buf = new StringBuilder();
-        for (int i = 1; i < constant_pool_count; i++) {
+        for (int i = 1; i < constant_pool.length; i++) {
             buf.append(i).append(")").append(constant_pool[i]).append("\n");
         }
         return buf.toString();
@@ -355,8 +353,8 @@ public class ConstantPool implements Clo
         ConstantPool c = null;
         try {
             c = (ConstantPool) clone();
-            c.constant_pool = new Constant[constant_pool_count];
-            for (int i = 1; i < constant_pool_count; i++) {
+            c.constant_pool = new Constant[constant_pool.length];
+            for (int i = 1; i < constant_pool.length; i++) {
                 if (constant_pool[i] != null) {
                     c.constant_pool[i] = constant_pool[i].copy();
                 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Field.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Field.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Field.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Field.java Tue Mar 
3 10:56:38 2015
@@ -98,9 +98,9 @@ public final class Field extends FieldOr
      * @return constant value associated with this field (may be null)
      */
     public final ConstantValue getConstantValue() {
-        for (int i = 0; i < attributes_count; i++) {
-            if (attributes[i].getTag() == Constants.ATTR_CONSTANT_VALUE) {
-                return (ConstantValue) attributes[i];
+        for (Attribute attribute : attributes) {
+            if (attribute.getTag() == Constants.ATTR_CONSTANT_VALUE) {
+                return (ConstantValue) attribute;
             }
         }
         return null;
@@ -127,10 +127,9 @@ public final class Field extends FieldOr
         if (cv != null) {
             buf.append(" = ").append(cv);
         }
-        for (int i = 0; i < attributes_count; i++) {
-            Attribute a = attributes[i];
-            if (!(a instanceof ConstantValue)) {
-                buf.append(" [").append(a.toString()).append("]");
+        for (Attribute attribute : attributes) {
+            if (!(attribute instanceof ConstantValue)) {
+                buf.append(" [").append(attribute.toString()).append("]");
             }
         }
         return buf.toString();

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/FieldOrMethod.java Tue
Mar  3 10:56:38 2015
@@ -22,8 +22,6 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import org.apache.bcel.Constants;
-import org.apache.bcel.classfile.Attribute;
-import org.apache.bcel.classfile.Signature;
 
 /** 
  * Abstract super class for fields and methods.
@@ -36,7 +34,6 @@ public abstract class FieldOrMethod exte
     private static final long serialVersionUID = -1833306330869469714L;
     protected int name_index; // Points to field name in constant pool 
     protected int signature_index; // Points to encoded signature
-    protected int attributes_count; // No. of attributes
     protected Attribute[] attributes; // Collection of attributes
     protected AnnotationEntry[] annotationEntries; // annotations defined on the field or
method 
     protected ConstantPool constant_pool;
@@ -79,7 +76,7 @@ public abstract class FieldOrMethod exte
     protected FieldOrMethod(DataInput file, ConstantPool constant_pool) throws IOException,
ClassFormatException {
         this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(),
null,
                 constant_pool);
-        attributes_count = file.readUnsignedShort();
+        int attributes_count = file.readUnsignedShort();
         attributes = new Attribute[attributes_count];
         for (int i = 0; i < attributes_count; i++) {
             attributes[i] = Attribute.readAttribute(file, constant_pool);
@@ -114,9 +111,9 @@ public abstract class FieldOrMethod exte
         file.writeShort(access_flags);
         file.writeShort(name_index);
         file.writeShort(signature_index);
-        file.writeShort(attributes_count);
-        for (int i = 0; i < attributes_count; i++) {
-            attributes[i].dump(file);
+        file.writeShort(attributes.length);
+        for (Attribute attribute : attributes) {
+            attribute.dump(file);
         }
     }
 
@@ -134,7 +131,6 @@ public abstract class FieldOrMethod exte
      */
     public final void setAttributes( Attribute[] attributes ) {
         this.attributes = attributes;
-        attributes_count = (attributes == null) ? 0 : attributes.length;
     }
 
 
@@ -217,9 +213,9 @@ public abstract class FieldOrMethod exte
         } catch(CloneNotSupportedException e) {}
 
         c.constant_pool    = constant_pool;
-        c.attributes       = new Attribute[attributes_count];
+        c.attributes       = new Attribute[attributes.length];
 
-        for(int i=0; i < attributes_count; i++) {
+        for (int i = 0; i < attributes.length; i++) {
             c.attributes[i] = attributes[i].copy(constant_pool);
         }
 
@@ -247,7 +243,7 @@ public abstract class FieldOrMethod exte
         if (!searchedForSignatureAttribute)
         {
             boolean found = false;
-            for (int i = 0; !found && i < attributes_count; i++)
+            for (int i = 0; !found && i < attributes.length; i++)
             {
                 if (attributes[i] instanceof Signature)
                 {

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LineNumberTable.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LineNumberTable.java
Tue Mar  3 10:56:38 2015
@@ -35,7 +35,7 @@ import org.apache.bcel.Constants;
 public final class LineNumberTable extends Attribute {
 
     private static final long serialVersionUID = -6967221519632128904L;
-    private int line_number_table_length;
+
     private LineNumber[] line_number_table; // Table of line/numbers pairs
 
 
@@ -72,7 +72,7 @@ public final class LineNumberTable exten
     LineNumberTable(int name_index, int length, DataInput input, ConstantPool constant_pool)
             throws IOException {
         this(name_index, length, (LineNumber[]) null, constant_pool);
-        line_number_table_length = (input.readUnsignedShort());
+        int line_number_table_length = (input.readUnsignedShort());
         line_number_table = new LineNumber[line_number_table_length];
         for (int i = 0; i < line_number_table_length; i++) {
             line_number_table[i] = new LineNumber(input);
@@ -101,9 +101,9 @@ public final class LineNumberTable exten
     @Override
     public final void dump( DataOutputStream file ) throws IOException {
         super.dump(file);
-        file.writeShort(line_number_table_length);
-        for (int i = 0; i < line_number_table_length; i++) {
-            line_number_table[i].dump(file);
+        file.writeShort(line_number_table.length);
+        for (LineNumber lineNumber : line_number_table) {
+            lineNumber.dump(file);
         }
     }
 
@@ -121,7 +121,6 @@ public final class LineNumberTable exten
      */
     public final void setLineNumberTable( LineNumber[] line_number_table ) {
         this.line_number_table = line_number_table;
-        line_number_table_length = (line_number_table == null) ? 0 : line_number_table.length;
     }
 
 
@@ -133,9 +132,9 @@ public final class LineNumberTable exten
         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++) {
+        for (int i = 0; i < line_number_table.length; i++) {
             line.append(line_number_table[i].toString());
-            if (i < line_number_table_length - 1) {
+            if (i < line_number_table.length - 1) {
                 line.append(", ");
             }
             if (line.length() > 72) {
@@ -156,7 +155,7 @@ public final class LineNumberTable exten
      * @return corresponding line in source code
      */
     public int getSourceLine( int pos ) {
-        int l = 0, r = line_number_table_length - 1;
+        int l = 0, r = line_number_table.length - 1;
         if (r < 0) {
             return -1;
         }
@@ -198,8 +197,8 @@ public final class LineNumberTable exten
     @Override
     public Attribute copy( ConstantPool _constant_pool ) {
         LineNumberTable c = (LineNumberTable) clone();
-        c.line_number_table = new LineNumber[line_number_table_length];
-        for (int i = 0; i < line_number_table_length; i++) {
+        c.line_number_table = new LineNumber[line_number_table.length];
+        for (int i = 0; i < line_number_table.length; i++) {
             c.line_number_table[i] = line_number_table[i].copy();
         }
         c.constant_pool = _constant_pool;
@@ -208,6 +207,6 @@ public final class LineNumberTable exten
 
 
     public final int getTableLength() {
-        return line_number_table_length;
+        return line_number_table == null ? 0 : line_number_table.length;
     }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTable.java
Tue Mar  3 10:56:38 2015
@@ -34,7 +34,6 @@ import org.apache.bcel.Constants;
 public class LocalVariableTable extends Attribute {
 
     private static final long serialVersionUID = 6780929007774637689L;
-    private int local_variable_table_length; // Table of local
     private LocalVariable[] local_variable_table; // variables
 
 
@@ -71,7 +70,7 @@ public class LocalVariableTable extends
     LocalVariableTable(int name_index, int length, DataInput input, ConstantPool constant_pool)
             throws IOException {
         this(name_index, length, (LocalVariable[]) null, constant_pool);
-        local_variable_table_length = (input.readUnsignedShort());
+        int local_variable_table_length = (input.readUnsignedShort());
         local_variable_table = new LocalVariable[local_variable_table_length];
         for (int i = 0; i < local_variable_table_length; i++) {
             local_variable_table[i] = new LocalVariable(input, constant_pool);
@@ -101,9 +100,9 @@ public class LocalVariableTable extends
     @Override
     public final void dump( DataOutputStream file ) throws IOException {
         super.dump(file);
-        file.writeShort(local_variable_table_length);
-        for (int i = 0; i < local_variable_table_length; i++) {
-            local_variable_table[i].dump(file);
+        file.writeShort(local_variable_table.length);
+        for (LocalVariable variable : local_variable_table) {
+            variable.dump(file);
         }
     }
 
@@ -127,9 +126,9 @@ public class LocalVariableTable extends
      */
     @java.lang.Deprecated
     public final LocalVariable getLocalVariable( int index ) {
-        for (int i = 0; i < local_variable_table_length; i++) {
-            if (local_variable_table[i].getIndex() == index) {
-                return local_variable_table[i];
+        for (LocalVariable variable : local_variable_table) {
+            if (variable.getIndex() == index) {
+                return variable;
             }
         }
         return null;
@@ -144,12 +143,12 @@ public class LocalVariableTable extends
      * @return the LocalVariable that matches or null if not found
      */
     public final LocalVariable getLocalVariable( int index, int pc ) {
-        for (int i = 0; i < local_variable_table_length; i++) {
-            if (local_variable_table[i].getIndex() == index) {
-                int start_pc = local_variable_table[i].getStartPC();
-                int end_pc = start_pc + local_variable_table[i].getLength();
+        for (LocalVariable variable : local_variable_table) {
+            if (variable.getIndex() == index) {
+                int start_pc = variable.getStartPC();
+                int end_pc = start_pc + variable.getLength();
                 if ((pc >= start_pc) && (pc <= end_pc)) {
-                    return local_variable_table[i];
+                    return variable;
                 }
             }
         }
@@ -159,9 +158,6 @@ public class LocalVariableTable extends
 
     public final void setLocalVariableTable( LocalVariable[] local_variable_table ) {
         this.local_variable_table = local_variable_table;
-        local_variable_table_length = (local_variable_table == null)
-                ? 0
-                : local_variable_table.length;
     }
 
 
@@ -171,9 +167,9 @@ public class LocalVariableTable extends
     @Override
     public final String toString() {
         StringBuilder buf = new StringBuilder();
-        for (int i = 0; i < local_variable_table_length; i++) {
+        for (int i = 0; i < local_variable_table.length; i++) {
             buf.append(local_variable_table[i].toString());
-            if (i < local_variable_table_length - 1) {
+            if (i < local_variable_table.length - 1) {
                 buf.append('\n');
             }
         }
@@ -187,8 +183,8 @@ public class LocalVariableTable extends
     @Override
     public Attribute copy( ConstantPool _constant_pool ) {
         LocalVariableTable c = (LocalVariableTable) clone();
-        c.local_variable_table = new LocalVariable[local_variable_table_length];
-        for (int i = 0; i < local_variable_table_length; i++) {
+        c.local_variable_table = new LocalVariable[local_variable_table.length];
+        for (int i = 0; i < local_variable_table.length; i++) {
             c.local_variable_table[i] = local_variable_table[i].copy();
         }
         c.constant_pool = _constant_pool;
@@ -197,6 +193,6 @@ public class LocalVariableTable extends
 
 
     public final int getTableLength() {
-        return local_variable_table_length;
+        return local_variable_table == null ? 0 : local_variable_table.length;
     }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/LocalVariableTypeTable.java
Tue Mar  3 10:56:38 2015
@@ -58,7 +58,6 @@ public class LocalVariableTypeTable exte
 
     private static final long serialVersionUID = -1082157891095177114L;
 
-    private int local_variable_type_table_length; // Table of local
     private LocalVariable[] local_variable_type_table;        // variables
 
     public LocalVariableTypeTable(LocalVariableTypeTable c) {
@@ -73,7 +72,7 @@ public class LocalVariableTypeTable exte
     LocalVariableTypeTable(int nameIdx, int len, DataInput input, ConstantPool cpool) throws
IOException {
         this(nameIdx, len, (LocalVariable[]) null, cpool);
 
-        local_variable_type_table_length = (input.readUnsignedShort());
+        int local_variable_type_table_length = (input.readUnsignedShort());
         local_variable_type_table = new LocalVariable[local_variable_type_table_length];
 
         for (int i = 0; i < local_variable_type_table_length; i++) {
@@ -89,9 +88,9 @@ public class LocalVariableTypeTable exte
     @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);
+        file.writeShort(local_variable_type_table.length);
+        for (LocalVariable variable : local_variable_type_table) {
+            variable.dump(file);
         }
     }
 
@@ -100,9 +99,9 @@ public class LocalVariableTypeTable exte
     }
 
     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];
+        for (LocalVariable variable : local_variable_type_table) {
+            if (variable.getIndex() == index) {
+                return variable;
             }
         }
 
@@ -111,8 +110,6 @@ public class LocalVariableTypeTable exte
 
     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;
     }
 
     /**
@@ -122,10 +119,10 @@ public class LocalVariableTypeTable exte
     public final String toString() {
         StringBuilder buf = new StringBuilder();
 
-        for (int i = 0; i < local_variable_type_table_length; i++) {
+        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) {
+            if (i < local_variable_type_table.length - 1) {
                 buf.append('\n');
             }
         }
@@ -140,8 +137,8 @@ public class LocalVariableTypeTable exte
     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 = 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();
         }
 
@@ -150,6 +147,6 @@ public class LocalVariableTypeTable exte
     }
 
     public final int getTableLength() {
-        return local_variable_type_table_length;
+        return local_variable_type_table == null ? 0 : local_variable_type_table.length;
     }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Method.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Method.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Method.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/Method.java Tue Mar
 3 10:56:38 2015
@@ -111,9 +111,9 @@ public final class Method extends FieldO
      * @return Code attribute of method, if any
      */
     public final Code getCode() {
-        for (int i = 0; i < attributes_count; i++) {
-            if (attributes[i] instanceof Code) {
-                return (Code) attributes[i];
+        for (Attribute attribute : attributes) {
+            if (attribute instanceof Code) {
+                return (Code) attribute;
             }
         }
         return null;
@@ -125,9 +125,9 @@ public final class Method extends FieldO
      * exceptions the method may throw not exception handlers!
      */
     public final ExceptionTable getExceptionTable() {
-        for (int i = 0; i < attributes_count; i++) {
-            if (attributes[i] instanceof ExceptionTable) {
-                return (ExceptionTable) attributes[i];
+        for (Attribute attribute : attributes) {
+            if (attribute instanceof ExceptionTable) {
+                return (ExceptionTable) attribute;
             }
         }
         return null;
@@ -178,10 +178,9 @@ public final class Method extends FieldO
         signature = Utility.methodSignatureToString(signature, name, access, true,
                 getLocalVariableTable());
         buf = new StringBuilder(signature);
-        for (int i = 0; i < attributes_count; i++) {
-            Attribute a = attributes[i];
-            if (!((a instanceof Code) || (a instanceof ExceptionTable))) {
-                buf.append(" [").append(a.toString()).append("]");
+        for (Attribute attribute : attributes) {
+            if (!((attribute instanceof Code) || (attribute instanceof ExceptionTable)))
{
+                buf.append(" [").append(attribute.toString()).append("]");
             }
         }
         ExceptionTable e = getExceptionTable();

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
Tue Mar  3 10:56:38 2015
@@ -35,7 +35,6 @@ import org.apache.bcel.Constants;
  */
 public class ParameterAnnotationEntry implements Node, Constants {
 
-    private final int annotation_table_length;
     private final AnnotationEntry[] annotation_table;
 
 
@@ -46,7 +45,7 @@ public class ParameterAnnotationEntry im
      * @throws IOException
      */
     ParameterAnnotationEntry(DataInput input, ConstantPool constant_pool) throws IOException
{
-        annotation_table_length = (input.readUnsignedShort());
+        int annotation_table_length = (input.readUnsignedShort());
         annotation_table = new AnnotationEntry[annotation_table_length];
         for (int i = 0; i < annotation_table_length; i++) {
             // TODO isRuntimeVisible
@@ -66,15 +65,6 @@ public class ParameterAnnotationEntry im
         // v.visitParameterAnnotationEntry(this);
     }
 
-
-    /**
-     * @return the number of annotation entries in this parameter annotation
-     */
-    public final int getNumAnnotations() {
-        return annotation_table_length;
-    }
-
-
     /**
      * returns the array of annotation entries in this annotation
      */
@@ -83,9 +73,9 @@ public class ParameterAnnotationEntry im
     }
 
     public void dump(DataOutputStream dos) throws IOException {
-        dos.writeShort(annotation_table_length);
-        for(int i = 0; i < annotation_table_length; i++) {
-            annotation_table[i].dump(dos);
+        dos.writeShort(annotation_table.length);
+        for (AnnotationEntry entry : annotation_table) {
+            entry.dump(dos);
         }
     }
 

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ParameterAnnotations.java
Tue Mar  3 10:56:38 2015
@@ -31,9 +31,9 @@ import java.io.IOException;
 public abstract class ParameterAnnotations extends Attribute {
 
     private static final long serialVersionUID = 5234607357644462705L;
-    private int num_parameters;
-    private ParameterAnnotationEntry[] parameter_annotation_table; // Table of parameter
annotations
-
+    
+    /** Table of parameter annotations */
+    private ParameterAnnotationEntry[] parameter_annotation_table;
 
     /**
      * @param parameter_annotation_type the subclass type of the parameter annotation
@@ -46,7 +46,7 @@ public abstract class ParameterAnnotatio
             DataInput input, ConstantPool constant_pool) throws IOException {
         this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[])
null,
                 constant_pool);
-        num_parameters = (input.readUnsignedByte());
+        int num_parameters = (input.readUnsignedByte());
         parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
         for (int i = 0; i < num_parameters; i++) {
             parameter_annotation_table[i] = new ParameterAnnotationEntry(input, constant_pool);
@@ -84,12 +84,8 @@ public abstract class ParameterAnnotatio
     /**
      * @param parameter_annotation_table the entries to set in this parameter annotation
      */
-    public final void setParameterAnnotationTable(
-            ParameterAnnotationEntry[] parameter_annotation_table ) {
+    public final void setParameterAnnotationTable(ParameterAnnotationEntry[] parameter_annotation_table
) {
         this.parameter_annotation_table = parameter_annotation_table;
-        num_parameters = (parameter_annotation_table == null)
-                ? 0
-                : parameter_annotation_table.length;
     }
 
 
@@ -108,14 +104,6 @@ public abstract class ParameterAnnotatio
         return parameter_annotation_table;
     }
 
-
-    /**
-     * @return the number of parameter annotation entries in this parameter annotation
-     */
-    public final int getNumParameterAnnotation() {
-        return num_parameters;
-    }
-
     @Override
     public void dump(DataOutputStream dos) throws IOException
     {

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMap.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMap.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMap.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMap.java Tue Mar
 3 10:56:38 2015
@@ -40,7 +40,6 @@ import org.apache.bcel.Constants;
 public final class StackMap extends Attribute {
 
     private static final long serialVersionUID = -6238662431726968495L;
-    private int map_length;
     private StackMapEntry[] map; // Table of stack map entries
 
 
@@ -67,7 +66,7 @@ public final class StackMap extends Attr
      */
     StackMap(int name_index, int length, DataInput input, ConstantPool constant_pool) throws
IOException {
         this(name_index, length, (StackMapEntry[]) null, constant_pool);
-        map_length = input.readUnsignedShort();
+        int map_length = input.readUnsignedShort();
         map = new StackMapEntry[map_length];
         for (int i = 0; i < map_length; i++) {
             map[i] = new StackMapEntry(input, constant_pool);
@@ -84,9 +83,9 @@ public final class StackMap extends Attr
     @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);
+        file.writeShort(map.length);
+        for (StackMapEntry entry : map) {
+            entry.dump(file);
         }
     }
 
@@ -104,7 +103,6 @@ public final class StackMap extends Attr
      */
     public final void setStackMap( StackMapEntry[] map ) {
         this.map = map;
-        map_length = (map == null) ? 0 : map.length;
     }
 
 
@@ -114,9 +112,9 @@ public final class StackMap extends Attr
     @Override
     public final String toString() {
         StringBuilder buf = new StringBuilder("StackMap(");
-        for (int i = 0; i < map_length; i++) {
+        for (int i = 0; i < map.length; i++) {
             buf.append(map[i].toString());
-            if (i < map_length - 1) {
+            if (i < map.length - 1) {
                 buf.append(", ");
             }
         }
@@ -131,8 +129,8 @@ public final class StackMap extends Attr
     @Override
     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 = new StackMapEntry[map.length];
+        for (int i = 0; i < map.length; i++) {
             c.map[i] = map[i].copy();
         }
         c.constant_pool = _constant_pool;
@@ -154,6 +152,6 @@ public final class StackMap extends Attr
 
 
     public final int getMapLength() {
-        return map_length;
+        return map == null ? 0 : map.length;
     }
 }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java?rev=1663628&r1=1663627&r2=1663628&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTable.java Tue
Mar  3 10:56:38 2015
@@ -41,7 +41,6 @@ import org.apache.bcel.Constants;
 public final class StackMapTable extends Attribute {
 
     private static final long serialVersionUID = -5802191977296683162L;
-    private int map_length;
     private StackMapTableEntry[] map; // Table of stack map entries
 
 
@@ -65,10 +64,9 @@ public final class StackMapTable extends
      * @param constant_pool Array of constants
      * @throws IOException
      */
-    StackMapTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
-            throws IOException {
+    StackMapTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
         this(name_index, length, (StackMapTableEntry[]) null, constant_pool);
-        map_length = file.readUnsignedShort();
+        int map_length = file.readUnsignedShort();
         map = new StackMapTableEntry[map_length];
         for (int i = 0; i < map_length; i++) {
             map[i] = new StackMapTableEntry(file, constant_pool);
@@ -85,9 +83,9 @@ public final class StackMapTable extends
     @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);
+        file.writeShort(map.length);
+        for (StackMapTableEntry entry : map) {
+            entry.dump(file);
         }
     }
 
@@ -105,7 +103,6 @@ public final class StackMapTable extends
      */
     public final void setStackMapTable( StackMapTableEntry[] map ) {
         this.map = map;
-        map_length = (map == null) ? 0 : map.length;
     }
 
 
@@ -115,9 +112,9 @@ public final class StackMapTable extends
     @Override
     public final String toString() {
         StringBuilder buf = new StringBuilder("StackMapTable(");
-        for (int i = 0; i < map_length; i++) {
+        for (int i = 0; i < map.length; i++) {
             buf.append(map[i].toString());
-            if (i < map_length - 1) {
+            if (i < map.length - 1) {
                 buf.append(", ");
             }
         }
@@ -132,8 +129,8 @@ public final class StackMapTable extends
     @Override
     public Attribute copy( ConstantPool _constant_pool ) {
         StackMapTable c = (StackMapTable) clone();
-        c.map = new StackMapTableEntry[map_length];
-        for (int i = 0; i < map_length; i++) {
+        c.map = new StackMapTableEntry[map.length];
+        for (int i = 0; i < map.length; i++) {
             c.map[i] = map[i].copy();
         }
         c.constant_pool = _constant_pool;
@@ -155,6 +152,6 @@ public final class StackMapTable extends
 
 
     public final int getMapLength() {
-        return map_length;
+        return map == null ? 0 : map.length;
     }
 }



Mime
View raw message