4

I have created a Eclipse plug in to printout the object in selection on press of a short cut key. I have been able to do this ,but i also would like to add the current method and current class name in the log. I am not sure how to proceede further. I tried to search for breadcrumb API but i was not able to reference the package from my project. I am quite new to plugin developement could someone guide me as to how to achive my goal. Thanks in advance.

Ravisha
  • 3,261
  • 9
  • 39
  • 66

1 Answers1

6

It really hard to get that stuff from Breadcrumb, you would have to use reflection to get it.

Here is the code to get current method from editor.

ITextEditor editor = (ITextEditor) PlatformUI.getWorkbench()
        .getActiveWorkbenchWindow().getActivePage().getActiveEditor();

ITextSelection selection = (ITextSelection) editor
        .getSelectionProvider().getSelection();

IEditorInput editorInput = editor.getEditorInput();
IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
if (elem instanceof ICompilationUnit) {
    ICompilationUnit unit = (ICompilationUnit) elem;
    IJavaElement selected = unit.getElementAt(selection.getOffset());

    System.out.println("selected=" + selected);
    System.out.println("selected.class=" + selected.getClass());
}
IAdapter
  • 62,595
  • 73
  • 179
  • 242
  • 1
    Hi Thanks a lot for the answer. It helped me a lot. I would appreciate if you could share some links where in i can learn more of these. – Ravisha Oct 19 '10 at 03:49