【问题标题】:How to setup a marker or a background color to a particular line in the editor given its line number?给定行号,如何在编辑器中为特定行设置标记或背景颜色?
【发布时间】:2012-04-23 08:42:13
【问题描述】:
你好,我正在做一个 Eclipse 插件项目来创建一个类似 Eclipse 的 IDE
对于特定的语言。
当我的 IDE 中编写的程序出现错误时,它会抛出
我在 IDE 中创建的控制台视图出现错误。但是当
用户点击一个特定的,我应该突出显示或设置一个标记
有错误的行。
我知道有错误的行号。我应该如何设置背景
颜色或标记以指示用户此行具有
选择错误?
我应该如何在 java 中做到这一点?
谁能帮我做这件事?
【问题讨论】:
标签:
java
eclipse
eclipse-plugin
【解决方案1】:
您应该使用MarkerUtilities.createMarker(IResource, Map, String) 与这样的东西:
Map<String, Object> map = new HashMap<String, Object>();
map.put(IMarker.MESSAGE, "My message");
map.put(IMarker.LINE_NUMBER, Integer.valueOf(myLine));
map.put(IMarker.CHAR_START, Integer.valueOf(myStartRegion));
map.put(IMarker.CHAR_END, Integer.valueOf(myEndRegion));
map.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_INFO));
map.put(IMarker.PRIORITY, Integer.valueOf(IMarker.PRIORITY_NORMAL));
org.eclipse.ui.texteditor.MarkerUtilities.createMarker(myFile, map, MARKER_ID);
您的MARKER_ID 与您的 plugin.xml 中的“markerType”描述相匹配
查看扩展点
org.eclipse.ui.editors.annotationTypes
org.eclipse.ui.editors.markerAnnotationSpecification
org.eclipse.core.resources.markers
您可以在this plugin.xml 中找到错误标记的示例。寻找对标记的引用。标记的设计在plugin.xml中定义