Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Method line number
Method line number [message #64519] Sun, 22 June 2003 14:54 Go to next message
Eclipse UserFriend
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 #64655 is a reply to message #64519] Sun, 22 June 2003 17:27 Go to previous messageGo to next message
Frank Sauer is currently offline Frank SauerFriend
Messages: 36
Registered: July 2009
Member
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


"Peter Ebraert" <pebraert@vub.ac.be> wrote in message
news:bd4fvt$pcs$1@rogue.oti.com...
> 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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
Previous Topic:Multiple entries in the "Open Type" dialog...
Next Topic:Stepping into JAVA API classes
Goto Forum:
  


Current Time: Thu Jan 02 19:46:01 GMT 2025

Powered by FUDForum. Page generated in 0.03659 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top