Method line number [message #64519] |
Sun, 22 June 2003 14:54 |
Eclipse User |
|
|
|
Originally posted by: pebraert.vub.ac.be
Is there really nobody with an answer for this issue?
I have the following:
- a methodName M
- a Path to a java-file J
I want to find the line number in J where M is defined. Can someone tell
me how to do that?
|
|
|
|
Re: Method line number [message #65315 is a reply to message #64655] |
Mon, 23 June 2003 17:50 |
Eclipse User |
|
|
|
Originally posted by: pebraert.vub.ac.be
Yep, indeed, now I got the offset of that method in that file.
So the only missing link is on how to get a line number for a offset and a
file. Somebody knows?
Cheers,
Peter
Frank Sauer wrote:
> use the JavaCore APIs, something like this:
> ICompilationUnit unit = JavaCore.create(path);
> then get the types from it with getAllTypes(), and iterate over the methods
> of those types (getMethods()) until you find the one you want and ask for
> its source range with getSourceRange(). This gives the start and length of
> the
> source for the method. I recall there is a way to find the line number given
> a source
> range, but I can\'t find it right now. Hope this gets you started.
> Frank
|
|
|
Re: Method line number [message #65379 is a reply to message #65315] |
Mon, 23 June 2003 18:15 |
Eclipse User |
|
|
|
Originally posted by: Olivier_Thomann.ca.ibm.comNOSPAM
On Mon, 23 Jun 2003 17:50:20 +0000 (UTC), pebraert@vub.ac.be (Peter
Ebraert) wrote:
>Yep, indeed, now I got the offset of that method in that file.
>So the only missing link is on how to get a line number for a offset and a
>file. Somebody knows?
>Cheers,
>
>Peter
If you have a org.eclipse.jdt.core.dom.CompilationUnit in hand, then
you simply need to use the lineNumber(int) method using the start
position of your source range.
Does it work for you?
--
Olivier
|
|
|
Re: Method line number [message #65550 is a reply to message #65379] |
Mon, 23 June 2003 20:10 |
Eclipse User |
|
|
|
Originally posted by: pebraert.vub.ac.be
Life can be sooo easy ;-)
All working now!
Thanks
Olivier Thomann wrote:
> If you have a org.eclipse.jdt.core.dom.CompilationUnit in hand, then
> you simply need to use the lineNumber(int) method using the start
> position of your source range.
> Does it work for you?
> --
> Olivier
|
|
|
Powered by
FUDForum. Page generated in 0.03659 seconds