【发布时间】:2016-05-28 13:09:19
【问题描述】:
我目前正在为我自己的语言开发一个编辑器。我使用以下代码将错误标记添加到我的源视图:
private void displayError(Interval interval, String message) {
int startIndex = interval.a;
int stopIndex = interval.b + 1;
Annotation annotation =
new Annotation("org.eclipse.ui.workbench.texteditor.error", false, message);
annotations.add(annotation);
annotationModel.addAnnotation(annotation, new Position(startIndex, stopIndex - startIndex));
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IMarker marker;
try { //create Marker to display Syntax Errors in Problems View
marker = workspace.getRoot().createMarker(MARKERID);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.CHAR_START, startIndex);
marker.setAttribute(IMarker.CHAR_END, stopIndex);
marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
//marker.setAttribute(IMarker.LOCATION, workspace.getRoot().getLocationURI().toString());
MarkerUtilities.setCharStart(marker, startIndex);
MarkerUtilities.setCharEnd(marker, stopIndex);
int lineNumber = 0;
if(!content.isEmpty() && content.length()>=stopIndex){ //Convert StartIndex to Line Number
String[] lines = content.substring(0, stopIndex).split("\r\n|\r|\n");
lineNumber = lines.length;
}
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
marker.setAttribute(IMarker.TEXT, message);
marker.setAttribute(IDE.EDITOR_ID_ATTR, "de.se_rwth.langeditor");
MarkerAnnotation ma = new MarkerAnnotation("org.eclipse.ui.workbench.texteditor.error", marker);
annotationModel.addAnnotation(ma, new Position(startIndex, stopIndex - startIndex));
annotations.add(ma);
} catch (CoreException e) {
e.printStackTrace();
}
}
标记正确显示在问题视图中。 Bt 如果我双击问题标记,它不会跳转到代码中的正确位置。此外,如果我右键单击问题标记,“转到”选项将被禁用。我的 Editor 类扩展了 TextEditor,也实现了 IGotoMarker 接口。 gotoMarker 方法是我这样实现的:
public void gotoMarker(IMarker marker) {
IDE.gotoMarker(this, marker);
}
getAdapter 方法如下所示:
public Object getAdapter(Class adapter) {
if (IContentOutlinePage.class.equals(adapter)) {
return contentOutlinePage;
}
return super.getAdapter(adapter);
}
如果有人可以帮助我,那就太好了!
【问题讨论】:
标签: java eclipse eclipse-plugin