Java Code Examples for org.apache.bcel.classfile.Method#getLocalVariableTable()
The following examples show how to use
org.apache.bcel.classfile.Method#getLocalVariableTable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalVariableAnnotation.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, int local, int position1, int position2) { LocalVariableTable localVariableTable = method.getLocalVariableTable(); String localName = UNKNOWN_NAME; if (localVariableTable != null) { LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1); if (lv1 == null) { lv1 = localVariableTable.getLocalVariable(local, position2); position1 = position2; } if (lv1 != null) { localName = lv1.getName(); } } LineNumberTable lineNumbers = method.getLineNumberTable(); if (lineNumbers == null) { return new LocalVariableAnnotation(localName, local, position1); } int line = lineNumbers.getSourceLine(position1); return new LocalVariableAnnotation(localName, local, position1, line); }
Example 2
Source File: PLSETestCase.java From commons-bcel with Apache License 2.0 | 6 votes |
/** * BCEL-295: */ public void testB295() throws Exception { final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.PLSETestClass2"); final ClassGen cg = new ClassGen(clazz); final ConstantPoolGen pool = cg.getConstantPool(); final Method m = cg.getMethodAt(1); // 'main' final LocalVariableTable lvt = m.getLocalVariableTable(); final LocalVariable lv = lvt.getLocalVariable(2, 4); // 'i' //System.out.println(lv); final MethodGen mg = new MethodGen(m, cg.getClassName(), pool); final LocalVariableTable new_lvt = mg.getLocalVariableTable(mg.getConstantPool()); final LocalVariable new_lv = new_lvt.getLocalVariable(2, 4); // 'i' //System.out.println(new_lv); assertEquals("live range length", lv.getLength(), new_lv.getLength()); }
Example 3
Source File: SuperfluousInstanceOf.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void visit(Method obj) { state = SEEN_NOTHING; varTable = obj.getLocalVariableTable(); if (varTable != null) { super.visit(obj); } }
Example 4
Source File: OpcodeStack.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private void pushByLocalObjectLoad(DismantleBytecode dbc, int register) { Method m = dbc.getMethod(); LocalVariableTable lvt = m.getLocalVariableTable(); if (lvt != null) { LocalVariable lv = LVTHelper.getLocalVariableAtPC(lvt, register, dbc.getPC()); if (lv != null) { String signature = lv.getSignature(); pushByLocalLoad(signature, register); return; } } pushByLocalLoad("Ljava/lang/Object;", register); }
Example 5
Source File: UnreadVariableCheck.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void visitMethod(Method aMethod) { // check references from previous method checkReferences(); mCurrentMethod = aMethod; // update reference recording mLocalVariableTable = aMethod.getLocalVariableTable(); mLocalVariableBitSet.clear(); }
Example 6
Source File: UnreadVariableCheck.java From contribution with GNU Lesser General Public License v2.1 | 5 votes |
public void visitMethod(Method aMethod) { // check references from previous method checkReferences(); mCurrentMethod = aMethod; // update reference recording mLocalVariableTable = aMethod.getLocalVariableTable(); mLocalVariableBitSet.clear(); }
Example 7
Source File: PLSETestCase.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * BCEL-79: */ public void testB79() throws ClassNotFoundException { final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.PLSETestClass"); final ClassGen gen = new ClassGen(clazz); final ConstantPoolGen pool = gen.getConstantPool(); final Method m = gen.getMethodAt(2); final LocalVariableTable lvt = m.getLocalVariableTable(); //System.out.println(lvt); //System.out.println(lvt.getTableLength()); final MethodGen mg = new MethodGen(m, gen.getClassName(), pool); final LocalVariableTable new_lvt = mg.getLocalVariableTable(mg.getConstantPool()); //System.out.println(new_lvt); assertEquals("number of locals", lvt.getTableLength(), new_lvt.getTableLength()); }