org.eclipse.jface.text.source.IAnnotationModelExtension2 Java Examples

The following examples show how to use org.eclipse.jface.text.source.IAnnotationModelExtension2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XtextEditor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: OverrideIndicatorRulerAction.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: AbstractAnnotationHover.java    From typescript.java with MIT License 4 votes vote down vote up
@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;
}
 
Example #5
Source File: AbstractAnnotationHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@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;
}
 
Example #6
Source File: AbstractAnnotationHover.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@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;
	}