Author: kohsuke
Date: Wed Dec 28 11:18:18 2005
New Revision: 359606

URL: http://svn.apache.org/viewcvs?rev=359606&view=rev
Log:
modified to use utility methods in Arrays for better readability.

Modified:
    
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/analyser/LocalVariables.java

Modified: 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/analyser/LocalVariables.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/analyser/LocalVariables.java?rev=359606&r1=359605&r2=359606&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/analyser/LocalVariables.java
 (original)
+++ 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/analyser/LocalVariables.java
 Wed Dec 28 11:18:18 2005
@@ -18,6 +18,8 @@
 import org.apache.bcel.generic.Type;
 import org.apache.bcel.verifier.exc.AssertionViolatedException;
 
+import java.util.Arrays;
+
 /**
  * This class implements an array of local variables used for symbolic JVM
  * simulation.
@@ -28,115 +30,106 @@
  * @author <A HREF="http://www.inf.fu-berlin.de/~ehaase"/>Enver Haase</A>
  */
 public class LocalVariables{
-       /** The Type[] containing the local variable slots. */
-       private Type[] locals;
+    /** The Type[] containing the local variable slots. */
+    private Type[] locals;
+
+    /**
+     * Creates a new LocalVariables object.
+     */
+    public LocalVariables(int maxLocals){
+        locals = new Type[maxLocals];
+        Arrays.fill(locals,Type.UNKNOWN);
+    }
 
-       /**
-        * Creates a new LocalVariables object.
-        */
-       public LocalVariables(int maxLocals){
-               locals = new Type[maxLocals];
-               for (int i=0; i<maxLocals; i++){
-                       locals[i] = Type.UNKNOWN;
-               }
-       }
-
-       /**
-        * Returns a deep copy of this object; i.e. the clone
-        * operates on a new local variable array.
-        * However, the Type objects in the array are shared.
-        */
-       protected Object clone(){
-               LocalVariables lvs = new LocalVariables(locals.length);
+    /**
+     * Returns a deep copy of this object; i.e. the clone
+     * operates on a new local variable array.
+     * However, the Type objects in the array are shared.
+     */
+    protected Object clone(){
+        LocalVariables lvs = new LocalVariables(locals.length);
         System.arraycopy(this.locals, 0, lvs.locals, 0, locals.length);
-               return lvs;
-       }
+        return lvs;
+    }
+
+    /**
+     * Returns the type of the local variable slot i.
+     */
+    public Type get(int i){
+        return locals[i];
+    }
+
+    /**
+     * Returns a (correctly typed) clone of this object.
+     * This is equivalent to ((LocalVariables) this.clone()).
+     */
+    public LocalVariables getClone(){
+        return (LocalVariables) this.clone();
+    }
+
+    /**
+     * Returns the number of local variable slots this
+     * LocalVariables instance has.
+     */
+    public int maxLocals(){
+        return locals.length;
+    }
+
+    /**
+     * Sets a new Type for the given local variable slot.
+     */
+    public void set(int i, Type type){
+        if (type == Type.BYTE || type == Type.SHORT || type == Type.BOOLEAN || 
type == Type.CHAR){
+            throw new AssertionViolatedException("LocalVariables do not know 
about '"+type+"'. Use Type.INT instead.");
+        }
+        locals[i] = type;
+    }
+
+    /*
+      * Fulfills the general contract of Object.equals().
+      */
+    public boolean equals(Object o){
+        if (!(o instanceof LocalVariables)) return false;
+        LocalVariables lv = (LocalVariables) o;
+        return Arrays.equals(this.locals, lv.locals);
+    }
+
+    /**
+     * Merges two local variables sets as described in the Java Virtual 
Machine Specification,
+     * Second Edition, section 4.9.2, page 146.
+     */
+    public void merge(LocalVariables that){
+
+        if (this.locals.length != that.locals.length){
+            throw new AssertionViolatedException("Merging LocalVariables of 
different size?!? From different methods or what?!?");
+        }
+
+        for (int i=0; i<locals.length; i++) {
+            this.locals[i] = Frame.merge(this.locals[i], that.locals[i], 
false);
+        }
+    }
 
-       /**
-        * Returns the type of the local variable slot i.
-        */
-       public Type get(int i){
-               return locals[i];
-       }
-
-       /**
-        * Returns a (correctly typed) clone of this object.
-        * This is equivalent to ((LocalVariables) this.clone()).
-        */
-       public LocalVariables getClone(){
-               return (LocalVariables) this.clone();
-       }
-
-       /**
-        * Returns the number of local variable slots this
-        * LocalVariables instance has.
-        */
-       public int maxLocals(){
-               return locals.length;
-       }
-
-       /**
-        * Sets a new Type for the given local variable slot.
-        */
-       public void set(int i, Type type){
-               if (type == Type.BYTE || type == Type.SHORT || type == 
Type.BOOLEAN || type == Type.CHAR){
-                       throw new AssertionViolatedException("LocalVariables do 
not know about '"+type+"'. Use Type.INT instead.");
-               }
-               locals[i] = type;
-       }
-
-       /*
-        * Fulfills the general contract of Object.equals().
-        */
-       public boolean equals(Object o){
-               if (!(o instanceof LocalVariables)) return false;
-               LocalVariables lv = (LocalVariables) o;
-               if (this.locals.length != lv.locals.length) return false;
-               for (int i=0; i<this.locals.length; i++){
-                       if (!this.locals[i].equals(lv.locals[i])){
-                               //log.debug(this.locals[i]+" is not 
"+lv.locals[i]);
-                               return false;
-                       }
-               }
-               return true;
-       }
-       
-       /**
-        * Merges two local variables sets as described in the Java Virtual 
Machine Specification,
-        * Second Edition, section 4.9.2, page 146.
-        */
-       public void merge(LocalVariables that){
-
-               if (this.locals.length != that.locals.length){
-                       throw new AssertionViolatedException("Merging 
LocalVariables of different size?!? From different methods or what?!?");
-               }
-
-               for (int i=0; i<locals.length; i++) {
-                       this.locals[i] = Frame.merge(this.locals[i], 
that.locals[i], false);
-               }
-       }
-       
-
-    /**
-        * Returns a String representation of this object.
-        */
-       public String toString(){
-               String s = "";
-               for (int i=0; i<locals.length; i++){
-                       s += Integer.toString(i)+": "+locals[i]+"\n";
-               }
-               return s;
-       }
-
-       /**
-        * Replaces all occurences of u in this local variables set
-        * with an "initialized" ObjectType.
-        */
-       public void initializeObject(UninitializedObjectType u){
-               for (int i=0; i<locals.length; i++){
-                       if (locals[i] == u){
-                               locals[i] = u.getInitialized();
-                       }
-               }
-       }
+
+    /**
+     * Returns a String representation of this object.
+     */
+    public String toString(){
+        String s = "";
+        for (int i=0; i<locals.length; i++){
+            s += Integer.toString(i)+": "+locals[i]+"\n";
+        }
+        return s;
+    }
+
+    /**
+     * Replaces all occurences of u in this local variables set
+     * with an "initialized" ObjectType.
+     */
+    public void initializeObject(UninitializedObjectType u){
+        for (int i=0; i<locals.length; i++){
+            if (locals[i] == u){
+                locals[i] = u.getInitialized();
+            }
+        }
+    }
 }



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

Reply via email to