问题描述
如何在 Eclipse 源代码视图编辑器中实现蓝色标记(标记注解)?
解决方法
标记存在于磁盘上,这是一个注解(一些注解是基于标记创建的)。那就是所谓的范围指示器。特殊之处在于您无需在注释模型中添加和删除它,您只需使用 org.eclipse.jface.text.source#ISourceViewer.setRangeIndication(int,int,boolean)
使其与选择更改保持同步。
public static final String MARKER_ID = "com.test.marker";
@param res=file full path line= line number in file you want to show the marker
public static IMarker createMarker(IResource res,int line) throws CoreException {
IMarker marker = null;
// note: you use the id that is defined in your plugin.xml
if (res != null) {
marker = res.createMarker(MARKER_ID);
marker.setAttribute(IMarker.PRIORITY,IMarker.PRIORITY_HIGH);
marker.setAttribute(IMarker.MESSAGE,marker.setAttribute(IMarker.LINE_NUMBER,line);
marker.setAttribute(IMarker.SEVERITY,IMarker.SEVERITY_ERROR);
}
return marker;
}
插件.xml
使用这个扩展点
<extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerType="com.ashling.comrv.marker"
name="com.test.marker">
</type>