Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » How to get selected method?
How to get selected method? [message #260192] Fri, 22 May 2009 09:45 Go to next message
Eclipse UserFriend
Hi,

I am developing a plugin that has a couple of views. These views will
contain information about the method where the caret is currently
positioned in the Java editor.

I would like to be able to discover the method that the caret is currently
positioned in and interrogate its start and end offset (or length) values.
The only solution that I have at the moment is to use ASTParser to parse
the whole source file and then traverse the hierarchy until I find a
method (MethodDeclaration) that the current caret offset is within.
However, this understandably gets quite slow with very large source files.
Is there a simpler way of doing this that is not as processing intensive?

Please let me know if anything is unclear.

Thanks in advance,
Alan
Re: How to get selected method? [message #260211 is a reply to message #260192] Mon, 25 May 2009 06:35 Go to previous message
Eclipse UserFriend
Alan wrote:
> Hi,
>
> I am developing a plugin that has a couple of views. These views will
> contain information about the method where the caret is currently
> positioned in the Java editor.
>
> I would like to be able to discover the method that the caret is
> currently positioned in and interrogate its start and end offset (or
> length) values. The only solution that I have at the moment is to use
> ASTParser to parse the whole source file and then traverse the
> hierarchy until I find a method (MethodDeclaration) that the current
> caret offset is within. However, this understandably gets quite slow
> with very large source files. Is there a simpler way of doing this
> that is not as processing intensive?
Take a look at
org.eclipse.jdt.internal.ui.actions.SelectionConverter.getEl ementAtOffset(*).

Dani
>
> Please let me know if anything is unclear.
>
> Thanks in advance,
> Alan
>
Previous Topic:Content assist in JDT in eclipse 3.5 RC1
Next Topic:Additional save actions
Goto Forum:
  


Current Time: Sun Jun 01 15:57:00 EDT 2025

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

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

Back to the top