Opening a Java editor

The following snippet shows how JavaUI can be used to open a Java editor and display a specific member of a Java compilation unit.

    void showMethod(IMember member) throws PartInitException, JavaModelException {
        ICompilationUnit cu = member.getCompilationUnit();
        IEditorPart javaEditor = JavaUI.openInEditor(cu);
        JavaUI.revealInEditor(javaEditor, (IJavaElement)member);
    }

The methods openInEditor and revealInEditor also work for class files and for members contained in class files.