java - Eclipse插件开发: How to jump to Marker in the Source View from Problems View?

标签 java eclipse eclipse-plugin

我目前正在为我自己的语言开发一个编辑器。我使用以下代码将错误标记添加到我的源 View :

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

  }

标记正确显示在问题 View 中。 Bt 如果我双击问题标记,它不会跳转到代码中的正确位置。此外,如果我右键单击问题标记,“转到”选项将被禁用。我的编辑器类扩展了 TextEditor,也实现了 IGotoMarker 接口(interface)。 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);
  }

如果有人能帮助我,那就太好了!

最佳答案

您正在工作区根资源上创建标记:

marker = workspace.getRoot().createMarker(MARKERID);

这是错误的,您必须在您正在编辑的实际 IFile 上创建标记。

关于java - Eclipse插件开发: How to jump to Marker in the Source View from Problems View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37499393/

相关文章:

java - 如何将java代码转换成应用程序格式?

java - 在哪里为基于 Eclipse 的应用程序设置主题?

python - 当我在 Eclipse 中运行一个简单的 django 脚本时出现奇怪的 python 错误,而不是在控制台中发生

java - 以[。]开头或结尾的object字段使elasticsearch bulk index中的对象分辨率不明确

java - 为什么 java.util.Properties 实现 Map<Object,Object> 而不是 Map<String,String>

java - 在eclipse中提取方法似乎不起作用

java - 启用 Jasper Studio Web 服务插件

java - 使用 Stringbuilder 与整数数组的算法性能

java - 如何创建 Activity 的 Android 快捷方式?

java - Ant 编译但不运行或创建 jar