svn commit: r153168 - jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java

[email protected]
Newsgroups gmane.comp.jakarta.bcel.devel
Message-ID <[email protected]>
Author: dbrosius
Date: Wed Feb  9 22:13:01 2005
New Revision: 153168

URL: http://svn.apache.org/viewcvs?view=rev&rev=153168
Log:
Apply Patch 32077: add a getLocalVariable that takes the current pc, and deprecate the old one that is inprecise.

Modified:
    jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java

Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java?view=diff&r1=153167&r2=153168
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/LocalVariableTable.java Wed Feb  9 22:13:01 2005
@@ -108,7 +108,15 @@
     return local_variable_table;
   }    
 
-  /** @return first matching variable using index
+  /** 
+   * @return first matching variable using index
+   * 
+   * @param index the variable slot
+   * 
+   * @returns the first LocalVariable that matches the slot or null if not found
+   * 
+   * @deprecated since 5.2 because multiple variables can share the
+   *             same slot, use getLocalVariable(int index, int pc) instead.
    */
   public final LocalVariable getLocalVariable(int index) {
     for(int i=0; i < local_variable_table_length; i++)
@@ -118,6 +126,26 @@
     return null;
   }
 
+  /** 
+   * @return matching variable using index when variable is used at supplied pc
+   * 
+   * @param index the variable slot
+   * @param pc the current pc that this variable is alive
+   * 
+   * @returns 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();
+        if ((pc >= start_pc) && (pc < end_pc))
+	      return local_variable_table[i];
+	  }
+
+    return null;
+  }
+  
   public final void setLocalVariableTable(LocalVariable[] local_variable_table)
   {
     this.local_variable_table = local_variable_table;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.