The JDT UI plug-in provides a utility class, JavaUI, which allows you to programmatically invoke the JDT user interface.
The following snippet causes a Java editor to show a specific member of a Java compilation unit.
void showMethod(IMember member) {
ICompilationUnit cu = member.getCompilationUnit();
IEditorPart javaEditor = JavaUI.openInEditor(cu);
JavaUI.revealInEditor(javaEditor, member);
}
openInEditor
and revealInEditor
also work for class files and for members contained in class files.