Marker in Eclipse editor not showing message
I'm building a custom text editor plugin for a domain specific language in Eclipse.
I can detect errors in the format of the editor contents and want to use eclipse's marker's to point out the errors to the user.
I have the following code in the plugin:
public static void createMarkerForResource(int linenumber, String message) throws CoreException {
IResource resource = getFile();
createMarkerForResource(resource, linenumber, message);
}
public static void createMarkerForResource(IResource resource, int linenumber, String message)
throws CoreException {
HashMap<String, Object> map = new HashMap<String, Object>();
MarkerUtilities.setLineNumber(map, linenumber);
MarkerUtilities.setMessage(map, message);
MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
IMarker[] markers = resource.findMarkers(null, true, IResource.DEPTH_INFINITE);
for (IMarker marker : markers){
System.out.println("Marker contents"+MarkerUtilities.getMessage(marker));
}
}
I run this code with the command:
createMarkerForResource(2, "hello");
This successfully gives me an image on the correct line
and if I hover over it, I get a 'you can click this thing' cursor. But I can't get the message to turn up.
The message has definitely been placed, because the:
for (IMarker marker : markers){
System.out.println("Marker contents"+MarkerUtilities.getMessage(marker));
}
code produces the "Marker contentshello" output as expected. What am I doing wrong?
EDIT:
The message is appearing in the problem view:
The answer of Njol is correct and works for me (Eclipse Neon.1).
But two additional recommendations:
Example:
import org.eclipse.jface.text.source.SourceViewerConfiguration;
...
public class MySourceViewerConfiguration extends SourceViewerConfiguration {
...
private IAnnotationHover annotationHoover;
...
public MySourceViewerConfiguration(){
this.annotationHoover=new MyAnnotationHoover();
}
...
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return annotationHoover;
}
}
And here the annotation hoover class
private class MyAnnotationHoover extends DefaultAnnotationHover{
@Override
protected boolean isIncluded(Annotation annotation) {
if (annotation instanceof MarkerAnnotation){
return true;
}
/* we do not support other annotations than markers*/
return false;
}
}
您需要使用适当的IAnnotationHover
,它可以在您的SourceViewerConfiguration
像这样定义:
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
return new DefaultAnnotationHover(false);
}
链接地址: http://www.djcxy.com/p/63366.html
下一篇: Eclipse编辑器中的标记不显示消息