1 package freemarker.eclipse.editors; 2 3 4 import java.util.Iterator ; 5 6 import org.eclipse.core.resources.IMarker; 7 import org.eclipse.jface.text.source.IAnnotationHover; 8 import org.eclipse.jface.text.source.IAnnotationModel; 9 import org.eclipse.jface.text.source.ISourceViewer; 10 import org.eclipse.ui.texteditor.MarkerAnnotation; 11 12 13 14 18 public class AnnotationHover implements IAnnotationHover { 19 20 public String getHoverInfo(ISourceViewer aViewer, int aLine) { 21 String info = null; 22 IMarker marker = getMarkerForLine(aViewer, aLine); 23 if (marker != null) { 24 String message = marker.getAttribute(IMarker.MESSAGE, (String )null); 25 if (message != null && message.trim().length() > 0) { 26 info = message.trim(); 27 } 28 } 29 return info; 30 } 31 32 protected IMarker getMarkerForLine(ISourceViewer aViewer, int aLine) { 33 IMarker marker = null; 34 IAnnotationModel model = aViewer.getAnnotationModel(); 35 if (model != null) { 36 Iterator e = model.getAnnotationIterator(); 37 if(e.hasNext()) { 38 Object o = e.next(); 39 if (o instanceof MarkerAnnotation) { 40 MarkerAnnotation a = (MarkerAnnotation)o; 41 marker = a.getMarker(); 42 } 43 } 44 } 45 return marker; 46 } 47 48 } 49 | Popular Tags |