use of org.eclipse.jface.text.Position in project xtext-eclipse by eclipse.
the class AnnotationWithQuickFixesHover method getHoverInfoInternal.
// DIFF: this code is entirely different, as the hover subclasses from AbstractProblemHover and
// hooks different methods
@Override
protected Object getHoverInfoInternal(ITextViewer textViewer, final int lineNumber, final int offset) {
AnnotationInfo result = recentAnnotationInfo;
if (result != null)
return result;
List<Annotation> annotations = getAnnotations(lineNumber, offset);
if (annotations != null) {
for (Annotation annotation : annotations) {
Position position = getAnnotationModel().getPosition(annotation);
if (annotation.getText() != null && position != null) {
final QuickAssistInvocationContext invocationContext = new QuickAssistInvocationContext(sourceViewer, position.getOffset(), position.getLength(), true);
CompletionProposalRunnable runnable = new CompletionProposalRunnable(invocationContext);
// Note: the resolutions have to be retrieved from the UI thread, otherwise
// workbench.getActiveWorkbenchWindow() will return null in LanguageSpecificURIEditorOpener and
// cause an exception
Display.getDefault().syncExec(runnable);
if (invocationContext.isMarkedCancelled()) {
return null;
}
result = new AnnotationInfo(annotation, position, sourceViewer, runnable.proposals);
recentAnnotationInfo = result;
return result;
}
}
}
return null;
}
use of org.eclipse.jface.text.Position in project xtext-eclipse by eclipse.
the class DefaultOccurrenceComputer method addOccurrenceAnnotation.
protected void addOccurrenceAnnotation(String type, IDocument document, ITextRegion textRegion, Map<Annotation, Position> annotationMap) {
try {
if (textRegion != null && textRegion.getLength() > 0) {
Annotation annotation = new Annotation(type, false, document.get(textRegion.getOffset(), textRegion.getLength()));
annotationMap.put(annotation, new Position(textRegion.getOffset(), textRegion.getLength()));
}
} catch (BadLocationException e) {
LOG.error("Error creating occurrence annotation", e);
}
}
use of org.eclipse.jface.text.Position in project xtext-eclipse by eclipse.
the class AbstractTemplateProposalProvider method createPosition.
/**
* Positions created for template contexts have to be added to the document so they are updated when the document
* is modified.
*
* @since 2.8
*/
protected Position createPosition(ContentAssistContext context) {
Position position = new Position(context.getReplaceRegion().getOffset(), context.getReplaceRegion().getLength());
IDocument document = context.getDocument();
if (document.containsPositionCategory(XTEXT_TEMPLATE_POS_CATEGORY)) {
try {
document.addPosition(XTEXT_TEMPLATE_POS_CATEGORY, position);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
return position;
}
use of org.eclipse.jface.text.Position in project xtext-eclipse by eclipse.
the class AnnotationIssueProcessor method getAnnotationsToAdd.
protected Map<Annotation, Position> getAnnotationsToAdd(Multimap<Position, Annotation> positionToAnnotations, List<Issue> issues, IProgressMonitor monitor) {
if (monitor.isCanceled()) {
return HashBiMap.create();
}
Map<Annotation, Position> annotationToPosition = Maps.newHashMapWithExpectedSize(issues.size());
for (Issue issue : issues) {
if (monitor.isCanceled()) {
return annotationToPosition;
}
if (isSet(issue.getOffset()) && isSet(issue.getLength()) && issue.getMessage() != null) {
String type = lookup.getAnnotationType(EValidator.MARKER, getMarkerSeverity(issue.getSeverity()));
boolean isQuickfixable = false;
if (issueResolutionProvider instanceof IssueResolutionProviderExtension) {
isQuickfixable = ((IssueResolutionProviderExtension) issueResolutionProvider).hasResolutionFor(issue);
} else {
isQuickfixable = issueResolutionProvider.hasResolutionFor(issue.getCode());
}
Annotation annotation = new XtextAnnotation(type, false, xtextDocument, issue, isQuickfixable);
if (issue.getOffset() < 0 || issue.getLength() < 0) {
LOG.error("Invalid annotation position offset=" + issue.getOffset() + " length = " + issue.getLength());
}
Position position = new Position(Math.max(0, issue.getOffset()), Math.max(0, issue.getLength()));
annotationToPosition.put(annotation, position);
positionToAnnotations.put(position, annotation);
}
}
return annotationToPosition;
}
use of org.eclipse.jface.text.Position in project xtext-eclipse by eclipse.
the class AnnotationIssueProcessor method announceAnnotationChanged.
protected void announceAnnotationChanged(Annotation annotation) {
if (annotationModel instanceof XtextResourceMarkerAnnotationModel)
((XtextResourceMarkerAnnotationModel) annotationModel).fireAnnotationChangedEvent(annotation);
else {
Position position = annotationModel.getPosition(annotation);
if (annotationModel instanceof IAnnotationModelExtension)
((IAnnotationModelExtension) annotationModel).modifyAnnotationPosition(annotation, position);
else {
annotationModel.removeAnnotation(annotation);
annotationModel.addAnnotation(annotation, position);
}
}
}
Aggregations