Hi,
I am working on getting the source code line numbers
from class files using BCEL.
ConstantPool constants = java_class.getConstantPool(); ConstantPoolGen cp = new ConstantPoolGen(constants);
MethodGen methodGen = new MethodGen(method, java_class.getClassName(), cp); Instruction [] instructions = methodGen.getInstructionList().getInstructions(); LineNumberGen[] aLineNumberGen = methodGen.getLineNumbers();
I intend to use getSourceLine() API of LineNumberGen class. But the array aLineNumberGen is returned of 0 length. Is there any setting of the compiler that will save the line numbers in the class files, because of which it is not working right now.
The compiler has to generate debugging-info. This can be ensured using the -g option. I think you can also use -g:lines, haven't checked myself if that is enough though.
fyi, just if you are interested - i used another approach to get the linenumbers out of a class file:
LineNumberTable lnt = method.getLineNumberTable(); Code code = method.getCode(); InstructionList il = new InstructionList(code.getCode()); InstructionHandle ih = il.getStart();
int sourceLine = lnt.getSourceLine(ih.getPosition());
then you can iterate over the instruction handles using ih.getNext();
greetings, Martin
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
