How to get surrounding method in Java source file for a given line number
Posted
by roesslerj
on Stack Overflow
See other posts from Stack Overflow
or by roesslerj
Published on 2009-12-18T13:19:44Z
Indexed on
2010/04/04
17:33 UTC
Read the original article
Hit count: 269
I have a line number of a Java source file and want to get the sourounding method for that line number programatically.
I looked into ANTLR which didn't help me much.
Janino (http://www.janino.net) seems promising, I would scan and parse (and if necessary compile) the code. Then I could use JDI and
ReferenceType.locationsOfLine(int lineNumber)
Still I don't know how to use JDI for doing this and didn't find a tutorial that goes anywhere in this direction.
Maybe there is some other way that I am completely missing.
© Stack Overflow or respective owner