use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class AnnotationHover method getMarkerForLine.
/**
* Helper function for {@link #getHoverInfo(ISourceViewer, int)}.
*
* @see #getHoverInfo(ISourceViewer, int)
*
* @param sourceViewer
* The viewer whose annotation we wish to find.
* @param lineNumber
* The line number in which the annotation(s) are.
* @return The list of markers residing in the given line in the given
* editor.
*/
protected List<IMarker> getMarkerForLine(final ISourceViewer sourceViewer, final int lineNumber) {
final List<IMarker> markers = new ArrayList<IMarker>();
final IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
if (annotationModel == null) {
return markers;
}
final Iterator<?> iterator = annotationModel.getAnnotationIterator();
while (iterator.hasNext()) {
final Object o = iterator.next();
if (o instanceof MarkerAnnotation) {
final MarkerAnnotation actuaMarkerl = (MarkerAnnotation) o;
try {
final int actualLine = sourceViewer.getDocument().getLineOfOffset(annotationModel.getPosition(actuaMarkerl).getOffset());
if (actualLine == lineNumber) {
markers.add(actuaMarkerl.getMarker());
}
} catch (BadLocationException e) {
ErrorReporter.logExceptionStackTrace(e);
}
}
}
return markers;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class BaseTextHover method getHoverInfo.
@Override
public String getHoverInfo(final ITextViewer textViewer, final IRegion hoverRegion) {
if (hoverRegion == null || textViewer == null) {
return null;
}
IAnnotationModel annotationModel = getSourceViewer().getAnnotationModel();
if (annotationModel != null) {
Iterator<?> iterator = annotationModel.getAnnotationIterator();
List<String> messages = new ArrayList<String>();
while (iterator.hasNext()) {
Object o = iterator.next();
if (o instanceof MarkerAnnotation) {
MarkerAnnotation actualMarker = (MarkerAnnotation) o;
Position markerPosition = annotationModel.getPosition(actualMarker);
if (markerPosition != null && markerPosition.getOffset() <= hoverRegion.getOffset() && markerPosition.getOffset() + markerPosition.getLength() >= hoverRegion.getOffset()) {
String message = actualMarker.getText();
if (message != null) {
// Marker error text hover (or tooltip in other words) handles error message
// in HTML format, and there can be situation, when the message contains
// < and > characters, which are handled as HTML control tags, so they
// are not visible. So these < and > characters are removed.
// Example: ANTLR sends the following error message during parsing:
// "mismatched input 'control' expecting <EOF>"
message = message.replaceAll("\\<([A-Z]+)\\>", "$1");
} else {
ErrorReporter.INTERNAL_ERROR("BaseTextHover.getHoverInfo(): message == null");
}
messages.add(message);
}
}
}
if (!messages.isEmpty()) {
final StringBuilder builder = new StringBuilder();
builder.append(messages.get(0));
for (int i = 1; i < messages.size() && i <= 3; i++) {
builder.append("<br></br>");
builder.append(messages.get(i));
}
if (messages.size() > 3) {
builder.append("<br></br>...");
}
return builder.toString();
}
}
ErrorReporter.parallelDisplayInStatusLine(getTargetEditor(), null);
DeclarationCollector declarationCollector = OpenDeclarationHelper.findVisibleDeclarations(getTargetEditor(), getReferenceParser(), textViewer.getDocument(), hoverRegion.getOffset(), false);
if (declarationCollector == null) {
return null;
}
List<DeclarationCollectionHelper> collected = declarationCollector.getCollected();
// To handle reference problem in T3Doc
if (T3Doc.isT3DocEnable()) {
String string = T3Doc.getCommentStringBasedOnReference(declarationCollector, collected, getTargetEditor(), hoverRegion, getReferenceParser(), textViewer);
if (string != null) {
return string;
}
}
if (collected.isEmpty()) {
return null;
}
DeclarationCollectionHelper declaration = collected.get(0);
// Check whether the T3Doc is enabled in the preferences window
if (!T3Doc.isT3DocEnable()) {
return declaration.description;
}
if (declaration.node != null) {
if (declaration.node.getT3Doc(declaration.location) == null) {
return "";
}
if (declaration.description != null) {
return declaration.description + "<BR></BR>" + declaration.node.getT3Doc(declaration.location).toString();
}
return declaration.node.getT3Doc(declaration.location).toString();
}
if (declaration.scope != null) {
if (declaration.description != null) {
return declaration.description + declaration.scope.getT3Doc(declaration.location).toString();
}
return declaration.scope.getT3Doc(declaration.location).toString();
}
// return declaration.description;
return "";
}
use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class MarkerHandler method deprecateMarkers.
/**
* Mark the provided markers as deprecated.
* <p>
* Those that are in an open editor, can be manipulated directly,
* the others will receive their value later by the AnnotationImageProvider
*
* @param editor the editor being open/edited triggering the change.
* @param markers the markers to mark deprecated.
*/
public static void deprecateMarkers(final ISemanticTITANEditor editor, final IMarker[] markers) {
if (editor == null || markers == null) {
return;
}
try {
AbstractDecoratedTextEditor textEditor = null;
IFile fileInput = null;
if (editor instanceof AbstractDecoratedTextEditor) {
textEditor = (AbstractDecoratedTextEditor) editor;
if (textEditor.getEditorInput() instanceof FileEditorInput) {
final FileEditorInput input = (FileEditorInput) textEditor.getEditorInput();
fileInput = input.getFile();
}
}
for (IMarker marker : markers) {
if (fileInput != null && textEditor != null && fileInput.equals(marker.getResource())) {
final IEditorInput editorInput = textEditor.getEditorInput();
final IDocumentProvider provider = textEditor.getDocumentProvider();
if (editorInput != null && provider != null) {
final IAnnotationModel model = provider.getAnnotationModel(editorInput);
final Iterator<?> e = model.getAnnotationIterator();
while (e.hasNext()) {
final Annotation annotation = (Annotation) e.next();
if (annotation instanceof MarkerAnnotation && marker.equals(((MarkerAnnotation) annotation).getMarker())) {
annotation.markDeleted(true);
}
}
} else {
if (!marker.getAttribute(AnnotationImageProvider.DEPRECATED, false)) {
marker.setAttribute(AnnotationImageProvider.DEPRECATED, true);
}
}
} else {
if (!marker.getAttribute(AnnotationImageProvider.DEPRECATED, false)) {
marker.setAttribute(AnnotationImageProvider.DEPRECATED, true);
}
}
}
} catch (CoreException e) {
ErrorReporter.logExceptionStackTrace(MARKER_HANDLING_ERROR, e);
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project titan.EclipsePlug-ins by eclipse.
the class TTCNPPEditor method updateInactiveCodeAnnotations.
public void updateInactiveCodeAnnotations(final List<Location> inactiveCodeLocations) {
if ((inactiveCodeLocations == null || inactiveCodeLocations.isEmpty()) && (inactiveCodeAnnotations == null || inactiveCodeAnnotations.length == 0)) {
return;
}
IEditorInput editorInput = getEditorInput();
if (editorInput == null) {
return;
}
IDocumentProvider documentProvider = getDocumentProvider();
if (documentProvider == null) {
return;
}
IAnnotationModel annotationModel = documentProvider.getAnnotationModel(editorInput);
if (annotationModel == null) {
return;
}
Object lockObject = (annotationModel instanceof ISynchronizable) ? ((ISynchronizable) annotationModel).getLockObject() : annotationModel;
synchronized (lockObject) {
Map<Annotation, Position> annotationMap = new HashMap<Annotation, Position>();
if (inactiveCodeLocations != null) {
for (Location loc : inactiveCodeLocations) {
Annotation annotationToAdd = new Annotation(INACTIVE_CODE_ANNOTATION_TYPE, false, "Inactive code");
Position position = new Position(loc.getOffset(), loc.getEndOffset() - loc.getOffset());
annotationMap.put(annotationToAdd, position);
}
}
if (annotationModel instanceof IAnnotationModelExtension) {
((IAnnotationModelExtension) annotationModel).replaceAnnotations(inactiveCodeAnnotations, annotationMap);
} else {
if (inactiveCodeAnnotations != null) {
for (Annotation annotationToRemove : inactiveCodeAnnotations) {
annotationModel.removeAnnotation(annotationToRemove);
}
}
for (Map.Entry<Annotation, Position> entry : annotationMap.entrySet()) {
annotationModel.addAnnotation(entry.getKey(), entry.getValue());
}
}
inactiveCodeAnnotations = annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]);
}
}
use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.
the class DocumentRegionProcessor method endProcessing.
protected void endProcessing() {
super.endProcessing();
ValidatorStrategy validatorStrategy = getValidatorStrategy();
if (validatorStrategy != null) {
validatorStrategy.endProcessing();
}
/* single spell-check for everything to ensure that SpellingProblem offsets are correct */
IReconcilingStrategy spellingStrategy = getSpellcheckStrategy();
IDocument document = getDocument();
if (spellingStrategy != null && document != null) {
spellingStrategy.reconcile(new Region(0, document.getLength()));
}
IReconcilingStrategy semanticHighlightingStrategy = getSemanticHighlightingStrategy();
if (semanticHighlightingStrategy != null && document != null) {
semanticHighlightingStrategy.reconcile(new Region(0, document.getLength()));
}
if ((getTextViewer() instanceof ISourceViewer)) {
ISourceViewer sourceViewer = (ISourceViewer) getTextViewer();
IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
for (int i = 0; i < fReconcileListeners.length; i++) {
fReconcileListeners[i].reconciled(document, annotationModel, false, new NullProgressMonitor());
}
}
}
Aggregations