java - 如何在编辑器中给定行号的情况下为特定行设置标记或背景颜色?

标签 java eclipse eclipse-plugin

Hi, I m doing a eclipse plugin project to create an IDE like eclipse for a particular language.

when the program written in my IDE is having errors,it throws the errors to the console view which i have created in my IDE.but when the user clicks on a particular,i should highlight or set a marker for the line having the error.

I know the line number having the error.How shall i set the background color or a marker to indicate the user that this line is having the selected error?

How shall i do this in java?

Can anyone help me in doing this?

最佳答案

您应该使用 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中定义

关于java - 如何在编辑器中给定行号的情况下为特定行设置标记或背景颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10277331/

相关文章:

java - Eclipse:导出要在较旧的 JRE 上执行的可运行 JAR 文件

java - eclipse-microprofiles 配置抛出 No ConfigProviderResolver 实现被发现

java - Eclipse 中意外缺少 { 大括号

android - 有没有一种方法(或插件)可以快速访问例如。来自 Eclipse 中 R.layout.main 的 layout/main.xml?

eclipse - 为什么Eclipse maven无缘无故产生巨大的.cfs文件?

java - Android 模块引用布局错误

java - 未从属性文件获取整数值

javascript - Eclipse jQuery,Javascript 助手插件?

java - Android 中的 "foreign application"是什么?

java - 从另一个类调用非静态 void