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/