本文整理汇总了Java中org.eclipse.jface.text.source.ISourceViewer.getAnnotationModel方法的典型用法代码示例。如果您正苦于以下问题:Java ISourceViewer.getAnnotationModel方法的具体用法?Java ISourceViewer.getAnnotationModel怎么用?Java ISourceViewer.getAnnotationModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.source.ISourceViewer
的用法示例。
在下文中一共展示了ISourceViewer.getAnnotationModel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHoverInfo
import org.eclipse.jface.text.source.ISourceViewer; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
IAnnotationModel model = sourceViewer.getAnnotationModel();
Iterator iterator = model.getAnnotationIterator();
while (iterator.hasNext()) {
Annotation annotation = (Annotation) iterator.next();
Position position = model.getPosition(annotation);
try {
int lineOfAnnotation = sourceViewer.getDocument().
getLineOfOffset(position.getOffset());
if (lineNumber == lineOfAnnotation) {
return annotation.getText();
}
} catch (BadLocationException e) {
// TODO: handle exception
}
}
return null;
}
示例2: ensureAnnotationModelInstalled
import org.eclipse.jface.text.source.ISourceViewer; //导入方法依赖的package包/类
private void ensureAnnotationModelInstalled() {
LinkedPositionAnnotations lpa = fCurrentTarget.fAnnotationModel;
if (lpa != null) {
ITextViewer viewer = fCurrentTarget.getViewer();
if (viewer instanceof ISourceViewer) {
ISourceViewer sv = (ISourceViewer) viewer;
IAnnotationModel model = sv.getAnnotationModel();
if (model instanceof IAnnotationModelExtension) {
IAnnotationModelExtension ext = (IAnnotationModelExtension) model;
IAnnotationModel ourModel = ext.getAnnotationModel(getUniqueKey());
if (ourModel == null) {
ext.addAnnotationModel(getUniqueKey(), lpa);
}
}
}
}
}
示例3: getMarkerPosition
import org.eclipse.jface.text.source.ISourceViewer; //导入方法依赖的package包/类
/**
* Returns the actual position of <i>marker</i> or null if the marker was
* deleted. Code inspired by
* @param marker
* @param sourceViewer
* @return
*/
private static int[] getMarkerPosition(IMarker marker, ISourceViewer sourceViewer) {
int[] p = new int[2];
p[0] = marker.getAttribute(IMarker.CHAR_START, -1);
p[1] = marker.getAttribute(IMarker.CHAR_END, -1);
// look up the current range of the marker when the document has been edited
IAnnotationModel model= sourceViewer.getAnnotationModel();
if (model instanceof AbstractMarkerAnnotationModel) {
AbstractMarkerAnnotationModel markerModel= (AbstractMarkerAnnotationModel) model;
Position pos= markerModel.getMarkerPosition(marker);
if (pos != null && !pos.isDeleted()) {
// use position instead of marker values
p[0] = pos.getOffset();
p[1] = pos.getOffset() + pos.getLength();
}
if (pos != null && pos.isDeleted()) {
// do nothing if position has been deleted
return null;
}
}
return p;
}
示例4: uninstallAnnotationModel
import org.eclipse.jface.text.source.ISourceViewer; //导入方法依赖的package包/类
private void uninstallAnnotationModel(LinkedModeUITarget target) {
ITextViewer viewer = target.getViewer();
if (viewer instanceof ISourceViewer) {
ISourceViewer sv = (ISourceViewer) viewer;
IAnnotationModel model = sv.getAnnotationModel();
if (model instanceof IAnnotationModelExtension) {
IAnnotationModelExtension ext = (IAnnotationModelExtension) model;
ext.removeAnnotationModel(getUniqueKey());
}
}
}
示例5: getHoverInfo
import org.eclipse.jface.text.source.ISourceViewer; //导入方法依赖的package包/类
/**
* Find a problem marker from the given line and return its error message.
*
* @param sourceViewer the source viewer
* @param lineNumber line number in the file, starting from zero
* @return the message of the marker of null, if no marker at the specified line
*/
public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
IDocument document= sourceViewer.getDocument();
IAnnotationModel model= sourceViewer.getAnnotationModel();
if (model == null)
return null;
List<String> lineMarkers = null;
Iterator<Annotation> e= model.getAnnotationIterator();
while (e.hasNext()) {
Annotation o= e.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation a= (MarkerAnnotation) o;
if (isRulerLine(model.getPosition(a), document, lineNumber)) {
if (lineMarkers == null)
lineMarkers = new LinkedList<String>();
lineMarkers.add(a.getMarker().getAttribute(IMarker.MESSAGE, null));
}
}
}
if (lineMarkers != null)
return getMessage(lineMarkers);
return null;
}