Parser Help: Find the method name from source code

Hello,

Given a line number from the Java source code, I need to find the name of the method that the line belongs to.

I have tried using Eclipse's AST Parser for this cause, but it does not work with line numbers.

Can someone help me to solve me this problem or point me in the right direction?

Thanks for your help.

Fayezin

[364 byte] By [nitrousFiza] at [2007-11-27 7:34:06]
# 1

Does the parser give you line numbers for stuff that it has already parsed? (As opposed to starting at the given line and working backwards, which is what you want.)

If so, perhaps you could pre-parse the file, and create a table mapping methods to line number ranges, and then invert the table.

paulcwa at 2007-7-12 19:14:31 > top of Java-index,Java Essentials,Java Programming...
# 2
A different approach is to use something like BCEL. This parses class files. It allows you access to the methods in the class file and (if the file hasn't had the line numbers stripped) access to the associated line numbers.matfud
matfuda at 2007-7-12 19:14:31 > top of Java-index,Java Essentials,Java Programming...