我创建了一个Eclipse插件,可以在按下快捷键时打印出所选对象。我已经能够做到这一点,但我还想在日志中添加当前方法和当前类名。我不确定如何进一步操作。我尝试搜索面包屑API,但无法从我的项目中引用该包。我对插件开发还很新,请有人指导我如何实现我的目标。提前感谢。
我创建了一个Eclipse插件,可以在按下快捷键时打印出所选对象。我已经能够做到这一点,但我还想在日志中添加当前方法和当前类名。我不确定如何进一步操作。我尝试搜索面包屑API,但无法从我的项目中引用该包。我对插件开发还很新,请有人指导我如何实现我的目标。提前感谢。
要从Breadcrumb获取那些信息实在是很困难的,您必须使用反射来获取它。
以下是从编辑器获取当前方法的代码。
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());
}