use of org.eclipse.xtext.ui.editor.validation.XtextAnnotation in project xtext-eclipse by eclipse.
the class IssueDataTest method testIssueData.
@Test
public void testIssueData() throws Exception {
XtextEditor xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR);
IXtextDocument document = xtextEditor.getDocument();
IResource file = xtextEditor.getResource();
List<Issue> issues = getIssues(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);
assertEquals(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.xtext.ui.editor.validation.XtextAnnotation in project xtext-eclipse by eclipse.
the class XtextMarkerRulerAction method hasQuickFixableAnnotationInCurrentLine.
protected boolean hasQuickFixableAnnotationInCurrentLine() {
try {
AbstractMarkerAnnotationModel annotationModel = getAnnotationModel();
if (annotationModel == null)
return false;
int line = ruler.getLineOfLastMouseButtonActivity();
IDocument document = getDocument();
IRegion region = document.getLineInformation(line);
Iterator<?> iterator = annotationModel.getAnnotationIterator(region.getOffset(), region.getLength(), true, true);
while (iterator.hasNext()) {
Object element = iterator.next();
if (element instanceof XtextAnnotation) {
XtextAnnotation annotation = (XtextAnnotation) element;
if (annotation.isQuickFixable())
return true;
} else if (element instanceof MarkerAnnotation) {
MarkerAnnotation annotation = (MarkerAnnotation) element;
if (annotation.isQuickFixableStateSet() && annotation.isQuickFixable())
return true;
}
}
} catch (BadLocationException e) {
// Ignore -> false is returned anyway
}
return false;
}
Aggregations