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



我一直在尝试向 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

最新更新