简体   繁体   English

在Eclipse中将自定义标记添加到Java编辑器

[英]Add custom markers to java editor in eclipse

I've been trying to add custom markers to eclipse editor for many many hours (days) and I just can't get it to work. 我一直在尝试将自定义标记添加到eclipse编辑器中很多小时(几天),但是我无法使其正常工作。

I can add problem markers well and without any issues by extending them on my own plugin.xml . 通过在我自己的plugin.xml上扩展问题标记,可以很好地添加问题标记,而不会出现任何问题。 It does everything I want EXCEPT the icon for the marker. 除了标记的图标,它可以完成我想要的所有操作。 I want a different icon. 我想要一个不同的图标。 Here's What I have: 这是我所拥有的:

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

The marker image is here: icon="icons/icon_mine.gif" 标记图片在这里: icon="icons/icon_mine.gif"

If I use the code as it is above, the annotation appears in the menu under the annotations ( General>Editors>TextEditors>Annotations )option with the correct image and the correct options as I would expect it to be. 如果我使用上面的代码,则注释会出现在菜单中的注释( General>Editors>TextEditors>Annotations )选项下,并带有正确的图像和我期望的正确选项。

Other log messages that I placed in the code confirm that that code executes well same as the results if I just change that line I commented in the XML (see the XML comment). 如果我只是更改在XML中注释的行(请参阅XML注释),则我在代码中放置的其他日志消息将确认该代码与结果的执行效果相同。

But still, I can't see anything telling me if the marker is actually being applied or an error (or anything in the log or the console, on that matter). 但是,仍然看不到任何东西告诉我标记是实际上是在应用还是错误(或在日志或控制台中的任何内容)。 It is as if I didn't setup anything and nothing is happening. 好像我什么都没设置,什么也没发生。
Any help is welcome 欢迎任何帮助

Please do check that the ids of each <extension> must start with the same substring as as the package of the project. 请检查每个<extension>的ID是否以与项目包相同的子字符串开头。 I see you using Plugin as the package and packages usually start with low case letters. 我看到您使用Plugin作为软件包,并且软件包通常以小写字母开头。

Please try renaming the prefixes of the ids to plugin. 请尝试将ID的前缀重命名为plugin. (low case) instead of Plugin . (小写),而不是Plugin

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM