我已经通过其的IFile例如Eclipse IDE中对XML文件的引用。 我知道要添加对我的看法,打开该文件在XML编辑器的动作,然后定位到特定的行号。 任何人有如何去任何想法?
Answer 1:
假设你知道文件的网址:
IWorkbenchPage page = activeWorkbenchPage();
if (page == null) {
throw new RuntimeException();
}
IFile file;
IFile[] files = ResourcesPlugin.getWorkspace().getRoot()
.findFilesForLocationURI(url.toURI());
file = files[0];
IMarker marker;
marker = file.createMarker(IMarker.TEXT);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.LINE_NUMBER, lineNumber);
marker.setAttributes(map);
IDE.openEditor(page, marker);
marker.delete();
当然,你需要捕捉/抛出几个例外的为好,但我忽略此这里简单。
文章来源: Want to open a eclipse xml file in code and navigate to a specific line number with reference to its IFile