在 Eclipse 中向 java 编辑器添加自定义标记

Add custom markers to java editor in eclipse

我已经尝试将自定义标记添加到 eclipse 编辑器很多很多小时(几天),但我就是无法让它工作。

我可以通过自己扩展来很好地添加问题标记,而且没有任何问题 plugin.xml。除了标记的图标,它可以完成我想要的一切。我想要一个不同的图标。 这是我拥有的:

plugin.xml

<extension
    point="org.eclipse.ui.editors.annotationTypes">
    <type
        markerType="Plugin.MyMarker"
        name="Plugin.MyMarker"/>
</extension>
<extension
    id="MyMarker"
    point="org.eclipse.core.resources.markers">
    <super type="org.eclipse.core.resources.textmarker" />
    <!-- <super type="org.eclipse.core.resources.problemmarker" /> --><!-- if I remove this comment, all works... But I don't want that icon-->
    <persistent value="true"/>
</extension>
<extension
    id="Plugin.markerAnnotationSpecifications"
    point="org.eclipse.ui.editors.markerAnnotationSpecification">
    <specification
        annotationType="Plugin.MyMarker"
        colorPreferenceKey="Plugin.markerColor"
        colorPreferenceValue="100,100,100"
        contributesToHeader="false"
        highlightPreferenceKey="Plugin.markerHighlight"
        highlightPreferenceValue="true"
        includeOnPreferencePage="true"
        icon="icons/icon_mine.gif"
        label="My beautiful label"
        overviewRulerPreferenceKey="Plugin.markerOverview"
        overviewRulerPreferenceValue="true"
        presentationLayer="0"
        symbolicIcon="warning"
        textPreferenceKey="Plugin.tarkerText"
        textPreferenceValue="true"
        textStylePreferenceKey="Plugin.textStyle"
        textStylePreferenceValue="BOX"
        verticalRulerPreferenceKey="Plugin.markerRuler"
        verticalRulerPreferenceValue="true" />

MyPlugin.java

IMarker myMarker = file.createMarker("Plugin.MyMarker");
if(!myMarker.exists()){
    Activator.myLog.log(new Status(Status.ERROR, LOG_PLUGIN_NAME, 15, "There's no marker!", null)); 
}
myMarker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
myMarker.setAttribute(IMarker.MESSAGE, "Txt:\nabc");
myMarker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_HIGH);
myMarker.setAttribute(IMarker.LINE_NUMBER, line);
myMarker.setAttribute(IMarker.CHAR_START, searchStart);
myMarker.setAttribute(IMarker.CHAR_END, searchEnd);

标记图片在这里:icon="icons/icon_mine.gif"

如果我使用上面的代码,注释将出现在菜单中的注释 (General>Editors>TextEditors>Annotations) 选项下,其中包含正确的图像和正确的选项,正如我所期望的那样。

我放在代码中的其他日志消息确认该代码执行得很好,如果我只是更改我在 XML 中评论的那一行(请参阅 XML 评论)。

但是,我仍然看不到任何信息告诉我标记是否实际被应用或错误(或日志或控制台中的任何内容)。就好像我没有设置任何东西,什么也没有发生。
欢迎任何帮助

请检查每个 <extension> 的 ID 必须以与项目包相同的子字符串开头。我看到您使用 Plugin 作为包,包通常以小写字母开头。

请尝试将 ID 的前缀重命名为 plugin.(小写)而不是 Plugin