Example usage for org.aspectj.apache.bcel.classfile LocalVariableTable getLocalVariableTable

List of usage examples for org.aspectj.apache.bcel.classfile LocalVariableTable getLocalVariableTable

Introduction

In this page you can find the example usage for org.aspectj.apache.bcel.classfile LocalVariableTable getLocalVariableTable.

Prototype

public final LocalVariable[] getLocalVariableTable() 

Source Link

Usage

From source file:br.jabuti.util.InstructCtrl.java

License:Open Source License

/** Gets the name of a local variable in a given point of the method.
        //w w w . java  2 s  .c  o  m
 @param lvt The local variable table for the method
 @param var The number of the local variable
 @param pc The poit (position) in the method where the name is wanted. Note
 that the same local variable number may be used with different names
 in several differen placed 
        
 @return The name of the variable. If not defined, returns "???"
 */
public static String getLocalVariableName(LocalVariableTable lvt, int var, int pc) {
    LocalVariable[] lv = lvt.getLocalVariableTable();

    for (int i = 0; i < lv.length; i++) {
        if (var == lv[i].getIndex() && pc >= lv[i].getStartPC()
                && pc <= lv[i].getStartPC() + lv[i].getLength()) {
            return lv[i].getName();
        }
    }
    return null;
}