Eclipse Plugin: Enter Class and Member Name

I created an Eclipse plug-in to print an object when I click on the shortcut key. I was able to do this, but I would also like to add the current current method and the name of the current class to the log. I am not sure how to proceed. I tried to find an API for packaging, but I could not reference the package from my project. I am completely new to plugin development and someone can help me achieve my goal. Thanks in advance.

+4
source share
1 answer

It is very difficult to get this material from Breadcrumb, you will need to use reflection to get it.

Here is the code to get the current method from the 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()); } 
+6
source

All Articles