You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Laran Evans <la...@laranevans.com> on 2009/04/08 21:33:09 UTC

How can I get the line number for a particular line of a Code object?

I'm just analyzing code, not re-engineering.

What I want to do is get the corresponding line number in source code
for a given instruction. Here's my basic code.

Code code = method.getCode();
String instructions = Utility.codeToString(code.getCode(),
constantPool, 0, -1, false);
BufferedReader reader = new BufferedReader(new StringReader(instructions));
String line = null;
while(null != (line = reader.readLine())) {
  // How can I get the source code line number that corresponds to
this line in the instructions?
}

Another thing I want to do is analyze constructor invocations within code.

In the same code above inside the while loop I can recognize lines
that start with "new ", which tells me that a constructor is being
called. But, every time I see an object being "newed" it's always the
"<init>" method being invoked. Can I inspect the code in that method
as well?

I hope this all makes sense. I appreciate any help I can get.

Thanks.

- Laran Evans

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