[英]getting current project path from IJavaEditorTextHover
i am developing an eclipse plugin and i need the path to the project of the user. 我正在开发一个eclipse插件,我需要该用户项目的路径。 I wnat to obtain it on my class which implements
org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover
我在实现
org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover
类上获得它
I have tried doing: 我试着做:
IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
String activeProjectName = "";
if (editorPart != null)
{
IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ;
IFile file = input.getFile();
IProject activeProject = file.getProject();
activeProjectName = activeProject .getName();
}
IProject project = workspace.getRoot().getProject(activeProjectName);
But when i do that on my my class which implements org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover, i keep getting nullpointerExcetion on 但是当我在实现org.eclipse.jdt.ui.text.java.hover.IJavaEditorTextHover的类上执行此操作时,我一直在获取nullpointerExcetion
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
I have tried this method before, but on a class that extends AbstractHandler and it worked. 我之前尝试过这种方法,但是在扩展AbstractHandler的类上起作用了。 Why can´ti get IProject from IJavaEditorTextHover?
为什么可以从IJavaEditorTextHover获取IProject?
IJavaEditorTextHover
has a setEditor(IEditorPart editor)
method so you can use that rather than trying to find the active editor. IJavaEditorTextHover
具有setEditor(IEditorPart editor)
方法,因此您可以使用该方法,而不是尝试查找活动的编辑器。
Your current code may be looking for an active workbench or page or editor before there actually is one. 您当前的代码可能正在寻找一个有效的工作台,页面或编辑器,然后才真正找到一个工作台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.