Search in sources :

Example 1 with IssueResolutionProviderExtension

use of org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProviderExtension 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;
}
Also used : IssueResolutionProviderExtension(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProviderExtension) Issue(org.eclipse.xtext.validation.Issue) Position(org.eclipse.jface.text.Position) Annotation(org.eclipse.jface.text.source.Annotation) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation)

Aggregations

Position (org.eclipse.jface.text.Position)1 Annotation (org.eclipse.jface.text.source.Annotation)1 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)1 IssueResolutionProviderExtension (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProviderExtension)1 Issue (org.eclipse.xtext.validation.Issue)1