commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1664574 - in /commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile: ExceptionTable.java InnerClasses.java StackMapEntry.java StackMapTableEntry.java
Date Fri, 06 Mar 2015 09:51:41 GMT
Author: ebourg
Date: Fri Mar  6 09:51:40 2015
New Revision: 1664574

URL: http://svn.apache.org/r1664574
Log:
Removed the redundant number_of_* fields

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/InnerClasses.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
    commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ExceptionTable.java?rev=1664574&r1=1664573&r2=1664574&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ExceptionTable.java
Fri Mar  6 09:51:40 2015
@@ -13,8 +13,8 @@
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
- *
  */
+
 package org.apache.bcel.classfile;
 
 import java.io.DataInput;
@@ -37,7 +37,7 @@ import org.apache.bcel.Constants;
 public final class ExceptionTable extends Attribute {
 
     private static final long serialVersionUID = 2045358830660883220L;
-    private int number_of_exceptions; // Table of indices into
+
     private int[] exception_index_table; // constant pool
 
 
@@ -71,10 +71,9 @@ public final class ExceptionTable extend
      * @param constant_pool Array of constants
      * @throws IOException
      */
-    ExceptionTable(int name_index, int length, DataInput input, ConstantPool constant_pool)
-            throws IOException {
+    ExceptionTable(int name_index, int length, DataInput input, ConstantPool constant_pool)
throws IOException {
         this(name_index, length, (int[]) null, constant_pool);
-        number_of_exceptions = input.readUnsignedShort();
+        int number_of_exceptions = input.readUnsignedShort();
         exception_index_table = new int[number_of_exceptions];
         for (int i = 0; i < number_of_exceptions; i++) {
             exception_index_table[i] = input.readUnsignedShort();
@@ -104,9 +103,9 @@ public final class ExceptionTable extend
     @Override
     public final void dump( DataOutputStream file ) throws IOException {
         super.dump(file);
-        file.writeShort(number_of_exceptions);
-        for (int i = 0; i < number_of_exceptions; i++) {
-            file.writeShort(exception_index_table[i]);
+        file.writeShort(exception_index_table.length);
+        for (int index : exception_index_table) {
+            file.writeShort(index);
         }
     }
 
@@ -123,7 +122,7 @@ public final class ExceptionTable extend
      * @return Length of exception table.
      */
     public final int getNumberOfExceptions() {
-        return number_of_exceptions;
+        return exception_index_table == null ? 0 : exception_index_table.length;
     }
 
 
@@ -131,9 +130,9 @@ public final class ExceptionTable extend
      * @return class names of thrown exceptions
      */
     public final String[] getExceptionNames() {
-        String[] names = new String[number_of_exceptions];
-        for (int i = 0; i < number_of_exceptions; i++) {
-            names[i] = constant_pool.getConstantString(exception_index_table[i],
+        String[] names = new String[exception_index_table.length];
+        for (int i = 0; i < exception_index_table.length; i++) {
+            names[i] = constant_pool.getConstantString(exception_index_table[i], 
                     Constants.CONSTANT_Class).replace('/', '.');
         }
         return names;
@@ -145,8 +144,7 @@ public final class ExceptionTable extend
      * Also redefines number_of_exceptions according to table length.
      */
     public final void setExceptionIndexTable( int[] exception_index_table ) {
-        this.exception_index_table = exception_index_table;
-        number_of_exceptions = (exception_index_table == null) ? 0 : exception_index_table.length;
+        this.exception_index_table = exception_index_table != null ? exception_index_table
: new int[0];
     }
 
 
@@ -157,11 +155,10 @@ public final class ExceptionTable extend
     public final String toString() {
         StringBuilder buf = new StringBuilder();
         String str;
-        for (int i = 0; i < number_of_exceptions; i++) {
-            str = constant_pool.getConstantString(exception_index_table[i],
-                    Constants.CONSTANT_Class);
+        for (int i = 0; i < exception_index_table.length; i++) {
+            str = constant_pool.getConstantString(exception_index_table[i], Constants.CONSTANT_Class);
             buf.append(Utility.compactClassName(str, false));
-            if (i < number_of_exceptions - 1) {
+            if (i < exception_index_table.length - 1) {
                 buf.append(", ");
             }
         }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/InnerClasses.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/InnerClasses.java?rev=1664574&r1=1664573&r2=1664574&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/InnerClasses.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/InnerClasses.java Fri
Mar  6 09:51:40 2015
@@ -36,7 +36,6 @@ public final class InnerClasses extends
 
     private static final long serialVersionUID = 4570147726361753700L;
     private InnerClass[] inner_classes;
-    private int number_of_classes;
 
 
     /**
@@ -73,7 +72,7 @@ public final class InnerClasses extends
     InnerClasses(int name_index, int length, DataInput input, ConstantPool constant_pool)
             throws IOException {
         this(name_index, length, (InnerClass[]) null, constant_pool);
-        number_of_classes = input.readUnsignedShort();
+        int number_of_classes = input.readUnsignedShort();
         inner_classes = new InnerClass[number_of_classes];
         for (int i = 0; i < number_of_classes; i++) {
             inner_classes[i] = new InnerClass(input);
@@ -103,9 +102,9 @@ public final class InnerClasses extends
     @Override
     public final void dump( DataOutputStream file ) throws IOException {
         super.dump(file);
-        file.writeShort(number_of_classes);
-        for (int i = 0; i < number_of_classes; i++) {
-            inner_classes[i].dump(file);
+        file.writeShort(inner_classes.length);
+        for (InnerClass inner_class : inner_classes) {
+            inner_class.dump(file);
         }
     }
 
@@ -122,8 +121,7 @@ public final class InnerClasses extends
      * @param inner_classes the array of inner classes
      */
     public final void setInnerClasses( InnerClass[] inner_classes ) {
-        this.inner_classes = inner_classes;
-        number_of_classes = (inner_classes == null) ? 0 : inner_classes.length;
+        this.inner_classes = inner_classes != null ? inner_classes : new InnerClass[0];
     }
 
 
@@ -133,8 +131,8 @@ public final class InnerClasses extends
     @Override
     public final String toString() {
         StringBuilder buf = new StringBuilder();
-        for (int i = 0; i < number_of_classes; i++) {
-            buf.append(inner_classes[i].toString(constant_pool)).append("\n");
+        for (InnerClass inner_class : inner_classes) {
+            buf.append(inner_class.toString(constant_pool)).append("\n");
         }
         return buf.toString();
     }
@@ -146,8 +144,8 @@ public final class InnerClasses extends
     @Override
     public Attribute copy( ConstantPool _constant_pool ) {
         InnerClasses c = (InnerClasses) clone();
-        c.inner_classes = new InnerClass[number_of_classes];
-        for (int i = 0; i < number_of_classes; i++) {
+        c.inner_classes = new InnerClass[inner_classes.length];
+        for (int i = 0; i < inner_classes.length; i++) {
             c.inner_classes[i] = inner_classes[i].copy();
         }
         c.constant_pool = _constant_pool;

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapEntry.java?rev=1664574&r1=1664573&r2=1664574&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapEntry.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapEntry.java Fri
Mar  6 09:51:40 2015
@@ -13,8 +13,8 @@
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
- *
  */
+
 package org.apache.bcel.classfile;
 
 import java.io.DataInput;
@@ -37,9 +37,7 @@ public final class StackMapEntry impleme
     private static final long serialVersionUID = 1L;
 
     private int byte_code_offset;
-    private int number_of_locals;
     private StackMapType[] types_of_locals;
-    private int number_of_stack_items;
     private StackMapType[] types_of_stack_items;
     private ConstantPool constant_pool;
 
@@ -51,12 +49,16 @@ public final class StackMapEntry impleme
      * @throws IOException
      */
     StackMapEntry(DataInput input, ConstantPool constant_pool) throws IOException {
-        this(input.readShort(), input.readShort(), null, -1, null, constant_pool);
+        this.constant_pool = constant_pool;
+        this.byte_code_offset = input.readShort();
+
+        int number_of_locals = input.readShort();
         types_of_locals = new StackMapType[number_of_locals];
         for (int i = 0; i < number_of_locals; i++) {
             types_of_locals[i] = new StackMapType(input, constant_pool);
         }
-        number_of_stack_items = input.readShort();
+
+        int number_of_stack_items = input.readShort();
         types_of_stack_items = new StackMapType[number_of_stack_items];
         for (int i = 0; i < number_of_stack_items; i++) {
             types_of_stack_items[i] = new StackMapType(input, constant_pool);
@@ -68,10 +70,8 @@ public final class StackMapEntry impleme
             StackMapType[] types_of_locals, int number_of_stack_items,
             StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
         this.byte_code_offset = byte_code_offset;
-        this.number_of_locals = number_of_locals;
-        this.types_of_locals = types_of_locals;
-        this.number_of_stack_items = number_of_stack_items;
-        this.types_of_stack_items = types_of_stack_items;
+        setTypesOfLocals(types_of_locals);
+        setTypesOfStackItems(types_of_stack_items);
         this.constant_pool = constant_pool;
     }
 
@@ -84,13 +84,13 @@ public final class StackMapEntry impleme
      */
     public final void dump( DataOutputStream file ) throws IOException {
         file.writeShort(byte_code_offset);
-        file.writeShort(number_of_locals);
-        for (int i = 0; i < number_of_locals; i++) {
-            types_of_locals[i].dump(file);
-        }
-        file.writeShort(number_of_stack_items);
-        for (int i = 0; i < number_of_stack_items; i++) {
-            types_of_stack_items[i].dump(file);
+        file.writeShort(types_of_locals.length);
+        for (StackMapType type : types_of_locals) {
+            type.dump(file);
+        }
+        file.writeShort(types_of_stack_items.length);
+        for (StackMapType type : types_of_stack_items) {
+            type.dump(file);
         }
     }
 
@@ -102,21 +102,21 @@ public final class StackMapEntry impleme
     public final String toString() {
         StringBuilder buf = new StringBuilder(64);
         buf.append("(offset=").append(byte_code_offset);
-        if (number_of_locals > 0) {
+        if (types_of_locals.length > 0) {
             buf.append(", locals={");
-            for (int i = 0; i < number_of_locals; i++) {
+            for (int i = 0; i < types_of_locals.length; i++) {
                 buf.append(types_of_locals[i]);
-                if (i < number_of_locals - 1) {
+                if (i < types_of_locals.length - 1) {
                     buf.append(", ");
                 }
             }
             buf.append("}");
         }
-        if (number_of_stack_items > 0) {
+        if (types_of_stack_items.length > 0) {
             buf.append(", stack items={");
-            for (int i = 0; i < number_of_stack_items; i++) {
+            for (int i = 0; i < types_of_stack_items.length; i++) {
                 buf.append(types_of_stack_items[i]);
-                if (i < number_of_stack_items - 1) {
+                if (i < types_of_stack_items.length - 1) {
                     buf.append(", ");
                 }
             }
@@ -137,18 +137,18 @@ public final class StackMapEntry impleme
     }
 
 
+    @java.lang.Deprecated
     public void setNumberOfLocals( int n ) {
-        number_of_locals = n;
     }
 
 
     public int getNumberOfLocals() {
-        return number_of_locals;
+        return types_of_locals == null ? 0 : types_of_locals.length;
     }
 
 
-    public void setTypesOfLocals( StackMapType[] t ) {
-        types_of_locals = t;
+    public void setTypesOfLocals( StackMapType[] types ) {
+        types_of_locals = types != null ? types : new StackMapType[0];
     }
 
 
@@ -157,18 +157,18 @@ public final class StackMapEntry impleme
     }
 
 
+    @java.lang.Deprecated
     public void setNumberOfStackItems( int n ) {
-        number_of_stack_items = n;
     }
 
 
     public int getNumberOfStackItems() {
-        return number_of_stack_items;
+        return types_of_stack_items == null ? 0 : types_of_stack_items.length;
     }
 
 
-    public void setTypesOfStackItems( StackMapType[] t ) {
-        types_of_stack_items = t;
+    public void setTypesOfStackItems( StackMapType[] types ) {
+        types_of_stack_items = types != null ? types : new StackMapType[0];
     }
 
 

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java?rev=1664574&r1=1664573&r2=1664574&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java
(original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/StackMapTableEntry.java
Fri Mar  6 09:51:40 2015
@@ -13,8 +13,8 @@
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
- *
  */
+
 package org.apache.bcel.classfile;
 
 import java.io.DataInput;
@@ -41,31 +41,28 @@ public final class StackMapTableEntry im
 
     private final int frame_type;
     private int byte_code_offset_delta;
-    private int number_of_locals;
     private StackMapType[] types_of_locals;
-    private int number_of_stack_items;
     private StackMapType[] types_of_stack_items;
     private ConstantPool constant_pool;
 
 
     /**
      * Construct object from file stream.
+     * * 
      * @param file Input stream
      * @throws IOException
      */
     StackMapTableEntry(DataInput file, ConstantPool constant_pool) throws IOException {
-        this(file.readByte() & 0xFF, -1, -1, null, -1, null, constant_pool);
+        this(file.readByte() & 0xFF, -1, null, null, constant_pool);
 
         if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX)
{
             byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
         } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type
<= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
             byte_code_offset_delta = frame_type - Constants.SAME_LOCALS_1_STACK_ITEM_FRAME;
-            number_of_stack_items = 1;
             types_of_stack_items = new StackMapType[1];
             types_of_stack_items[0] = new StackMapType(file, constant_pool);
         } else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
             byte_code_offset_delta = file.readShort();
-            number_of_stack_items = 1;
             types_of_stack_items = new StackMapType[1];
             types_of_stack_items[0] = new StackMapType(file, constant_pool);
         } else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX)
{
@@ -74,19 +71,19 @@ public final class StackMapTableEntry im
             byte_code_offset_delta = file.readShort();
         } else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX)
{
             byte_code_offset_delta = file.readShort();
-            number_of_locals = frame_type - 251;
+            int number_of_locals = frame_type - 251;
             types_of_locals = new StackMapType[number_of_locals];
             for (int i = 0; i < number_of_locals; i++) {
                 types_of_locals[i] = new StackMapType(file, constant_pool);
             }            
         } else if (frame_type == Constants.FULL_FRAME) {        
             byte_code_offset_delta = file.readShort();
-            number_of_locals = file.readShort();
+            int number_of_locals = file.readShort();
             types_of_locals = new StackMapType[number_of_locals];
             for (int i = 0; i < number_of_locals; i++) {
                 types_of_locals[i] = new StackMapType(file, constant_pool);
             }
-            number_of_stack_items = file.readShort();
+            int number_of_stack_items = file.readShort();
             types_of_stack_items = new StackMapType[number_of_stack_items];
             for (int i = 0; i < number_of_stack_items; i++) {
                 types_of_stack_items[i] = new StackMapType(file, constant_pool);
@@ -98,15 +95,13 @@ public final class StackMapTableEntry im
     }
 
 
-    public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals,
-            StackMapType[] types_of_locals, int number_of_stack_items,
+    public StackMapTableEntry(int tag, int byte_code_offset_delta,
+            StackMapType[] types_of_locals,
             StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
         this.frame_type = tag;
         this.byte_code_offset_delta = byte_code_offset_delta;
-        this.number_of_locals = number_of_locals;
-        this.types_of_locals = types_of_locals;
-        this.number_of_stack_items = number_of_stack_items;
-        this.types_of_stack_items = types_of_stack_items;
+        setTypesOfLocals(types_of_locals);
+        setTypesOfStackItems(types_of_stack_items);
         this.constant_pool = constant_pool;
     }
 
@@ -132,18 +127,18 @@ public final class StackMapTableEntry im
             file.writeShort(byte_code_offset_delta);
         } else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX)
{
             file.writeShort(byte_code_offset_delta);
-            for (int i = 0; i < number_of_locals; i++) {
-                types_of_locals[i].dump(file);
+            for (StackMapType type : types_of_locals) {
+                type.dump(file);
             }            
         } else if (frame_type == Constants.FULL_FRAME) {        
             file.writeShort(byte_code_offset_delta);
-            file.writeShort(number_of_locals);
-            for (int i = 0; i < number_of_locals; i++) {
-                types_of_locals[i].dump(file);
-            }
-            file.writeShort(number_of_stack_items);
-            for (int i = 0; i < number_of_stack_items; i++) {
-                types_of_stack_items[i].dump(file);
+            file.writeShort(types_of_locals.length);
+            for (StackMapType type : types_of_locals) {
+                type.dump(file);
+            }
+            file.writeShort(types_of_stack_items.length);
+            for (StackMapType type : types_of_stack_items) {
+                type.dump(file);
             }
         } else {
             /* Can't happen */
@@ -177,21 +172,21 @@ public final class StackMapTableEntry im
             buf.append("UNKNOWN");
         }
         buf.append(", offset delta=").append(byte_code_offset_delta);
-        if (number_of_locals > 0) {
+        if (types_of_locals.length > 0) {
             buf.append(", locals={");
-            for (int i = 0; i < number_of_locals; i++) {
+            for (int i = 0; i < types_of_locals.length; i++) {
                 buf.append(types_of_locals[i]);
-                if (i < number_of_locals - 1) {
+                if (i < types_of_locals.length - 1) {
                     buf.append(", ");
                 }
             }
             buf.append("}");
         }
-        if (number_of_stack_items > 0) {
+        if (types_of_stack_items.length > 0) {
             buf.append(", stack items={");
-            for (int i = 0; i < number_of_stack_items; i++) {
+            for (int i = 0; i < types_of_stack_items.length; i++) {
                 buf.append(types_of_stack_items[i]);
-                if (i < number_of_stack_items - 1) {
+                if (i < types_of_stack_items.length - 1) {
                     buf.append(", ");
                 }
             }
@@ -211,19 +206,14 @@ public final class StackMapTableEntry im
         return byte_code_offset_delta;
     }
 
-
-    public void setNumberOfLocals( int n ) {
-        number_of_locals = n;
-    }
-
-
+    
     public int getNumberOfLocals() {
-        return number_of_locals;
+        return types_of_locals.length;
     }
 
 
-    public void setTypesOfLocals( StackMapType[] t ) {
-        types_of_locals = t;
+    public void setTypesOfLocals( StackMapType[] types ) {
+        types_of_locals = types != null ? types : new StackMapType[0];
     }
 
 
@@ -232,18 +222,13 @@ public final class StackMapTableEntry im
     }
 
 
-    public void setNumberOfStackItems( int n ) {
-        number_of_stack_items = n;
-    }
-
-
     public int getNumberOfStackItems() {
-        return number_of_stack_items;
+        return types_of_stack_items.length;
     }
 
 
-    public void setTypesOfStackItems( StackMapType[] t ) {
-        types_of_stack_items = t;
+    public void setTypesOfStackItems( StackMapType[] types ) {
+        types_of_stack_items = types != null ? types : new StackMapType[0];
     }
 
 



Mime
View raw message