Eclipse 插件:获取封闭类和成员名称

发布于 2024-09-28 04:11:48 字数 147 浏览 4 评论 0原文

我创建了一个 Eclipse 插件,可以在按下快捷键时打印输出选择的对象。 我已经能够做到这一点,但我还想在日志中添加当前方法和当前类名称。我不知道如何进一步进行。我尝试搜索面包屑 API,但无法从我的项目中引用该包。我对插件开发很陌生,有人可以指导我如何实现我的目标。提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自我难过 2024-10-05 04:11:48

从面包屑中获取这些东西真的很难,你必须使用反射来获取它。

这是从编辑器获取当前方法的代码。

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());
}

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());
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文