jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scho...@t-online.de (Martin Schöffler)
Subject Re: Source Line Numbers from Class files
Date Tue, 27 Jan 2004 09:45:50 GMT
Nikhil C. Khedkar wrote:
> 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();


To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org

View raw message