use of org.eclipse.jface.text.source.IAnnotationModel in project erlide_eclipse by erlang.
the class DefaultErlangFoldingStructureProvider method createAnnotationMap.
private Map<Object, List<Tuple>> createAnnotationMap(final IAnnotationModel model) {
final Map<Object, List<Tuple>> map = new HashMap<>();
final Iterator<?> e = model.getAnnotationIterator();
while (e.hasNext()) {
final Object annotation = e.next();
if (annotation instanceof ErlangProjectionAnnotation) {
final ErlangProjectionAnnotation epa = (ErlangProjectionAnnotation) annotation;
final Position position = model.getPosition(epa);
final List<Tuple> list = map.computeIfAbsent(epa.getElement(), k -> new ArrayList<>(2));
list.add(new Tuple(epa, position));
}
}
final Comparator<Tuple> comparator = (o1, o2) -> o1.position.getOffset() - o2.position.getOffset();
for (final List<Tuple> name : map.values()) {
final List<Tuple> list = name;
list.sort(comparator);
}
return map;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.
the class IssueDataTest method testIssueData.
@Test
public void testIssueData() throws Exception {
IFile dslFile = dslFile(getProjectName(), getFileName(), getFileExtension(), MODEL_WITH_LINKING_ERROR);
XtextEditor xtextEditor = openEditor(dslFile);
IXtextDocument document = xtextEditor.getDocument();
IResource file = xtextEditor.getResource();
List<Issue> issues = getAllValidationIssues(document);
assertEquals(1, issues.size());
Issue issue = issues.get(0);
assertEquals(2, issue.getLineNumber().intValue());
assertEquals(3, issue.getColumn().intValue());
assertEquals(PREFIX.length(), issue.getOffset().intValue());
assertEquals(QuickfixCrossrefTestLanguageValidator.TRIGGER_VALIDATION_ISSUE.length(), issue.getLength().intValue());
String[] expectedIssueData = new String[] { QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_0, QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_1 };
assertTrue(Arrays.equals(expectedIssueData, issue.getData()));
Thread.sleep(1000);
IAnnotationModel annotationModel = xtextEditor.getDocumentProvider().getAnnotationModel(xtextEditor.getEditorInput());
AnnotationIssueProcessor annotationIssueProcessor = new AnnotationIssueProcessor(document, annotationModel, new IssueResolutionProvider.NullImpl());
annotationIssueProcessor.processIssues(issues, new NullProgressMonitor());
Iterator<?> annotationIterator = annotationModel.getAnnotationIterator();
// filter QuickDiffAnnotations
List<Object> allAnnotations = Lists.newArrayList(annotationIterator);
List<XtextAnnotation> annotations = newArrayList(filter(allAnnotations, XtextAnnotation.class));
assertEquals(annotations.toString(), 1, annotations.size());
XtextAnnotation annotation = annotations.get(0);
assertTrue(Arrays.equals(expectedIssueData, annotation.getIssueData()));
IssueUtil issueUtil = new IssueUtil();
Issue issueFromAnnotation = issueUtil.getIssueFromAnnotation(annotation);
assertTrue(Arrays.equals(expectedIssueData, issueFromAnnotation.getData()));
new MarkerCreator().createMarker(issue, file, MarkerTypes.FAST_VALIDATION);
IMarker[] markers = file.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
String errorMessage = new AnnotatedTextToString().withFile(dslFile).withMarkers(markers).toString().trim();
assertEquals(errorMessage, 1, markers.length);
String attribute = (String) markers[0].getAttribute(Issue.DATA_KEY);
assertNotNull(attribute);
assertTrue(Arrays.equals(expectedIssueData, Strings.unpack(attribute)));
Issue issueFromMarker = issueUtil.createIssue(markers[0]);
assertEquals(issue.getColumn(), issueFromMarker.getColumn());
assertEquals(issue.getLineNumber(), issueFromMarker.getLineNumber());
assertEquals(issue.getOffset(), issueFromMarker.getOffset());
assertEquals(issue.getLength(), issueFromMarker.getLength());
assertTrue(Arrays.equals(expectedIssueData, issueFromMarker.getData()));
}
use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.
the class XtextEditorErrorTickUpdater method getSeverity.
protected Severity getSeverity(XtextEditor xtextEditor) {
if (xtextEditor == null || xtextEditor.getInternalSourceViewer() == null)
return null;
IAnnotationModel model = xtextEditor.getInternalSourceViewer().getAnnotationModel();
if (model != null) {
Iterator<Annotation> iterator = model.getAnnotationIterator();
boolean hasWarnings = false;
boolean hasInfos = false;
while (iterator.hasNext()) {
Annotation annotation = iterator.next();
if (!annotation.isMarkedDeleted()) {
Issue issue = issueUtil.getIssueFromAnnotation(annotation);
if (issue != null) {
if (issue.getSeverity() == Severity.ERROR) {
return Severity.ERROR;
} else if (issue.getSeverity() == Severity.WARNING) {
hasWarnings = true;
} else if (issue.getSeverity() == Severity.INFO) {
hasInfos = true;
}
}
}
}
if (hasWarnings)
return Severity.WARNING;
if (hasInfos)
return Severity.INFO;
}
return null;
}
use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.
the class MarkerResolutionGenerator method getResolutions.
@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
try {
if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
return emptyResult;
} catch (CoreException e) {
return emptyResult;
}
if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
return emptyResult;
}
XtextEditor editor = findEditor(marker.getResource());
if (editor != null) {
IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
if (annotationModel != null && !isMarkerStillValid(marker, annotationModel))
return emptyResult;
}
Issue issue = getIssueUtil().createIssue(marker);
if (issue == null)
return emptyResult;
List<IssueResolution> resolutions = getResolutionProvider().getResolutions(issue);
List<IMarkerResolution> result = Lists.newArrayList();
List<IssueResolution> remaining = Lists.newArrayList();
for (IssueResolution resolution : resolutions) {
if (resolution.getModification() instanceof IBatchableModification) {
result.add(adapterFactory.create(marker, resolution));
} else if (resolution.getModification() instanceof ITextualMultiModification) {
result.add(textualMultiModificationAdapterFactory.create(marker, resolution));
} else {
remaining.add(resolution);
}
}
result.addAll(Lists.newArrayList(getAdaptedResolutions(remaining)));
return result.toArray(new IMarkerResolution[result.size()]);
}
use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.
the class XtextQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
ISourceViewer sourceViewer = invocationContext.getSourceViewer();
if (sourceViewer == null)
return new ICompletionProposal[0];
if (invocationContext instanceof QuickAssistInvocationContext) {
if (((QuickAssistInvocationContext) invocationContext).isCancelled()) {
return new ICompletionProposal[0];
}
}
final IDocument document = sourceViewer.getDocument();
if (document == null)
return new ICompletionProposal[0];
final IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
List<ICompletionProposal> result = Lists.newArrayList();
try {
Set<Annotation> applicableAnnotations = getApplicableAnnotations(document, annotationModel, invocationContext.getOffset());
result = createQuickfixes(invocationContext, applicableAnnotations);
selectAndRevealQuickfix(invocationContext, applicableAnnotations, result);
} catch (BadLocationException e) {
errorMessage = e.getMessage();
} catch (OperationCanceledException e) {
return new ICompletionProposal[0];
}
sortQuickfixes(result);
return result.toArray(new ICompletionProposal[result.size()]);
}
Aggregations