tags:

views:

173

answers:

2

I am writing Eclipse plugins for Java, and have the following problem:

Given an IEditorPart, I need to check if it is a java editor.

I could do (IEditor instanceof JavaEditor), but JavaEditor is an org.eclipse.jdt.internal.ui.javaeditor.JavaEditor, which falls under the JDT's "internal" classes.

Is there a smarter and safer way to do this? I'm not sure why there is no non-internal interface for this.

+3  A: 
VonC
Seems reliable, but I have to say that's a really bizarre mechanism... String comparisons? I wish the JDT exposed more materials.
Uri
Yes, as far as know, every uid mechanism for plugins are based on String
VonC
A: 

One strategy might be to use JavaUI.getEditorInputJavaElement(IEditorPart):

// given IEditorPart editor
IJavaElement elt = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (elt != null) {
    // editor is a Java editor
}

The method returns null if the editor input is not in fact a Java element.

maxg