类org.eclipse.jface.text.source.IAnnotationModelExtension2源码实例Demo

下面列出了怎么用org.eclipse.jface.text.source.IAnnotationModelExtension2的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-eclipse   文件: XtextEditor.java
@SuppressWarnings("rawtypes")
private Annotation getAnnotation(final int offset, final int length) {
	final IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
	if (model == null || length < 0)
		return null;

	Iterator iterator;
	if (model instanceof IAnnotationModelExtension2) {
		iterator = ((IAnnotationModelExtension2) model).getAnnotationIterator(offset, length, true, true);
	} else {
		iterator = model.getAnnotationIterator();
	}

	while (iterator.hasNext()) {
		final Annotation a = (Annotation) iterator.next();
		final Position p = model.getPosition(a);
		if (p != null && p.overlapsWith(offset, length))
			return a;
	}
	return null;
}
 
private OverrideIndicatorAnnotation findOverrideIndicatorAnnotation() {
	IDocument document = getDocument();
	IVerticalRuler verticalRuler = getVerticalRuler();
	int lineOfLastMouseButtonActivity = verticalRuler.getLineOfLastMouseButtonActivity();
	IAnnotationModelExtension2 annotationModel = (IAnnotationModelExtension2) verticalRuler.getModel();
	if (annotationModel != null) {
		Iterator<?> iterator = ImmutableSet.<Object>of().iterator();
		try {
			IRegion line = document.getLineInformation(lineOfLastMouseButtonActivity);
			iterator = annotationModel.getAnnotationIterator(line.getOffset(), line.getLength() + 1, true, true);
		} catch (BadLocationException e) {
		}
		while (iterator.hasNext()) {
			Annotation annotation = (Annotation) iterator.next();
			if (annotation instanceof OverrideIndicatorAnnotation) {
				return (OverrideIndicatorAnnotation) annotation;
			}
		}
	}
	return null;
}
 
/**
 * Returns the annotation overlapping with the given range or <code>null</code>.
 *
 * @param offset the region offset
 * @param length the region length
 * @return the found annotation or <code>null</code>
 * @since 3.0
 */
private Annotation getAnnotation(int offset, int length) {
	IAnnotationModel model= getDocumentProvider().getAnnotationModel(getEditorInput());
	if (model == null)
		return null;

	Iterator<Annotation> parent;
	if (model instanceof IAnnotationModelExtension2)
		parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(offset, length, true, true);
	else
		parent= model.getAnnotationIterator();

	Iterator<Annotation> e= new JavaAnnotationIterator(parent, false);
	while (e.hasNext()) {
		Annotation a= e.next();
		Position p= model.getPosition(a);
		if (p != null && p.overlapsWith(offset, length))
			return a;
	}
	return null;
}
 
源代码4 项目: typescript.java   文件: AbstractAnnotationHover.java
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	IPath path;
	IAnnotationModel model;
	if (textViewer instanceof ISourceViewer) {
		path = null;
		model = ((ISourceViewer) textViewer).getAnnotationModel();
	} else {
		// Get annotation model from file buffer manager
		path = getEditorInputPath();
		model = getAnnotationModel(path);
	}
	if (model == null)
		return null;

	try {
		Iterator<Annotation> parent;
		if (model instanceof IAnnotationModelExtension2)
			parent = ((IAnnotationModelExtension2) model).getAnnotationIterator(hoverRegion.getOffset(),
					hoverRegion.getLength() > 0 ? hoverRegion.getLength() : 1, true, true);
		else
			parent = model.getAnnotationIterator();
		Iterator<Annotation> e = new TypeScriptAnnotationIterator(parent, fAllAnnotations);

		int layer = -1;
		Annotation annotation = null;
		Position position = null;
		while (e.hasNext()) {
			Annotation a = e.next();

			AnnotationPreference preference = getAnnotationPreference(a);
			if (preference == null || !(preference.getTextPreferenceKey() != null
			/*
			 * && fStore.getBoolean(preference.getTextPreferenceKey()) ||
			 * (preference.getHighlightPreferenceKey() != null &&
			 * fStore.getBoolean(preference.getHighlightPreferenceKey()))
			 */))
				continue;

			Position p = model.getPosition(a);

			int l = fAnnotationAccess.getLayer(a);

			if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
				String msg = a.getText();
				if (msg != null && msg.trim().length() > 0) {
					layer = l;
					annotation = a;
					position = p;
				}
			}
		}
		if (layer > -1)
			return createAnnotationInfo(annotation, position, textViewer);

	} finally {
		try {
			if (path != null) {
				ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
				manager.disconnect(path, LocationKind.NORMALIZE, null);
			}
		} catch (CoreException ex) {
			TypeScriptUIPlugin.log(ex.getStatus());
		}
	}

	return null;
}
 
@Override
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
	IPath path;
	IAnnotationModel model;
	if (textViewer instanceof ISourceViewer) {
		path= null;
		model= ((ISourceViewer)textViewer).getAnnotationModel();
	} else {
		// Get annotation model from file buffer manager
		path= getEditorInputPath();
		model= getAnnotationModel(path);
	}
	if (model == null)
		return null;

	try {
		Iterator<Annotation> parent;
		if (model instanceof IAnnotationModelExtension2)
			parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true);
		else
			parent= model.getAnnotationIterator();
		Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations);

		int layer= -1;
		Annotation annotation= null;
		Position position= null;
		while (e.hasNext()) {
			Annotation a= e.next();

			AnnotationPreference preference= getAnnotationPreference(a);
			if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey()))))
				continue;

			Position p= model.getPosition(a);

			int l= fAnnotationAccess.getLayer(a);

			if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
				String msg= a.getText();
				if (msg != null && msg.trim().length() > 0) {
					layer= l;
					annotation= a;
					position= p;
				}
			}
		}
		if (layer > -1)
			return createAnnotationInfo(annotation, position, textViewer);

	} finally {
		try {
			if (path != null) {
				ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
				manager.disconnect(path, LocationKind.NORMALIZE, null);
			}
		} catch (CoreException ex) {
			JavaPlugin.log(ex.getStatus());
		}
	}

	return null;
}
 
源代码6 项目: goclipse   文件: AbstractAnnotationHover.java
@Override
	public Object getHoverInfo(ISourceBuffer sourceBuffer, IRegion hoverRegion, ITextViewer textViewer) {
		
		if (!(textViewer instanceof ISourceViewer)) {
			return null;
		}
		
		ISourceViewer sourceViewer = (ISourceViewer) textViewer;
//		IPath path = null;
		IAnnotationModel model = sourceViewer.getAnnotationModel();
//		if (editor.getSourceViewer_() instanceof ISourceViewer) {
//			path= null;
//			model= editor.getSourceViewer_().getAnnotationModel();
//		} else {
//			// Get annotation model from file buffer manager
//			path= getEditorInputPath();
//			model= getAnnotationModel(path);
//		}
		if (model == null)
			return null;

//		try {
			Iterator<Annotation> parent;
			if (model instanceof IAnnotationModelExtension2)
				parent= ((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(), hoverRegion.getLength(), true, true);
			else
				parent= model.getAnnotationIterator();
			Iterator<Annotation> e= new JavaAnnotationIterator(parent, fAllAnnotations);

			int layer= -1;
			Annotation annotation= null;
			Position position= null;
			while (e.hasNext()) {
				Annotation a= e.next();

				AnnotationPreference preference= getAnnotationPreference(a);
				if (preference == null || !(preference.getTextPreferenceKey() != null && fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey()))))
					continue;

				Position p= model.getPosition(a);

				int l= fAnnotationAccess.getLayer(a);

				if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
					String msg= a.getText();
					if (msg != null && msg.trim().length() > 0) {
						layer= l;
						annotation= a;
						position= p;
					}
				}
			}
			if (layer > -1)
				return createAnnotationInfo(annotation, position, textViewer);

//		} finally {
//			try {
//				if (path != null) {
//					ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
//					manager.disconnect(path, LocationKind.NORMALIZE, null);
//				}
//			} catch (CoreException ex) {
//				LangUIPlugin.logStatus(ex);
//			}
//		}

		return null;
	}
 
 类所在包
 同包方法