|
Re: Converting from CompilationUnitEditor to a Java Model element [message #545063 is a reply to message #544874] |
Tue, 06 July 2010 14:37 |
Dani Megert Messages: 3802 Registered: July 2009 |
Senior Member |
|
|
Ciera wrote:
> I'm trying to listen for caret updates on Java source files. I need to
> retrieve something in the Java AST when this occurs.
In order to also get caret movement you should use a post selection
changed listener. To get the CU use this:
org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot(IEditorInpu t)
to get the AST:
org.eclipse.jdt.ui.SharedASTProvider.getAST(ITypeRoot, WAIT_FLAG,
IProgressMonitor)
Dani
>
> Right now, I have the following:
>
> public void selectionChanged(IWorkbenchPart part, ISelection selection) {
> if (selection instanceof ITextSelection && part instanceof
> AbstractDecoratedTextEditor) {
> AbstractDecoratedTextEditor editor =
> (AbstractDecoratedTextEditor)part;
> //do stuff and refresh my view
> }
> }
>
>
> That part is actually a CompilationUnitEditor, but I noticed
> CompilationUnitEditor is in an internal package rather than an
> external one. However, the only way I see to get to the Java Model is
> through that class by calling getViewPartInput().
>
> I found two other posts on this topic, but no answers on either:
>
> http://www.eclipse.org/forums/index.php?t=msg&th=58457&a mp;#msg_185047
>
> http://www.eclipse.org/forums/index.php?t=msg&goto=24855 3&
>
> What is the suggested mechanism for going from an IWorkbenchPart and
> ISelection to, say, an ASTNode of the first complete statement on that
> line?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03975 seconds