【发布时间】:2018-06-06 11:53:17
【问题描述】:
我正在制作一个需要访问在 Eclipse 编辑器中编写的代码的 Eclipse 插件。我已经按照链接中提到的过程进行了操作。 Accessing Eclipse editor code 但它在消息框中显示文件路径而不是代码。 IEditorEditor 类的 getEditorInput() 没有按照链接执行它应该执行的操作。这是我的代码。请帮我找出我做错了什么。
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IEditorPart editor = ((IWorkbenchPage) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()).getActiveEditor();
IEditorInput input = (IEditorInput) editor.getEditorInput(); // accessing code from eclipse editor
String code = input.toString();
MessageDialog.openInformation(
window.getShell(),
"Project",
code);
return null;
}
【问题讨论】:
-
是
StyledText包含正在编辑的文本 - 您错过了getAdapter行 -
@greg-449 没想到它会在那里。对我不小心。非常感谢。
-
@howlger 您提供的其他链接对我无效。
标签: java eclipse-plugin code-editor