org.eclipse.xtext.ui.editor.validation.XtextAnnotation Java Examples

The following examples show how to use org.eclipse.xtext.ui.editor.validation.XtextAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canFix(Annotation annotation) {
	if (annotation.isMarkedDeleted())
		return false;

	// non-persisted annotation
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation a = (XtextAnnotation) annotation;
		return getResolutionProvider().hasResolutionFor(a.getIssueCode());
	}

	// persisted markerAnnotation
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
		if (!markerAnnotation.isQuickFixableStateSet())
			markerAnnotation.setQuickFixable(getResolutionProvider().hasResolutionFor(
					issueUtil.getCode(markerAnnotation)));
		return markerAnnotation.isQuickFixable();
	}

	if (annotation instanceof SpellingAnnotation) {
		return true;
	}

	return false;
}
 
Example #2
Source File: MarkerIdentity.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Instantiates a new MarkerIdentity.
 *
 * @param annotation
 *          the Annotation
 * @return MarkerIdentity - this
 */
public MarkerIdentity create(final Annotation annotation) {
  MarkerIdentity result = provider.get();
  if (annotation instanceof XtextAnnotation) {
    Issue issue = ((XtextAnnotation) annotation).getIssue();
    result.start = issue.getOffset();
    result.end = result.start == ATTRIBUTE_MISSING ? ATTRIBUTE_MISSING : result.start + issue.getLength();
    result.message = issue.getMessage();
  } else if (annotation instanceof org.eclipse.ui.texteditor.MarkerAnnotation) {
    result.start = MarkerUtilities.getCharStart(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
    result.end = MarkerUtilities.getCharEnd(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
    result.message = MarkerUtilities.getMessage(((org.eclipse.ui.texteditor.MarkerAnnotation) annotation).getMarker());
  } else {
    result.end = ATTRIBUTE_MISSING;
    result.start = ATTRIBUTE_MISSING;
    result.message = null; // NOPMD
  }
  result.problemCode = issueUtil.getCode(annotation);
  result.problemURI = issueUtil.getUriToProblem(annotation);
  result.resourceURI = result.problemURI == null ? null : result.problemURI.trimFragment();
  return result;
}
 
Example #3
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public Issue getIssueFromAnnotation(Annotation annotation) {
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xtextAnnotation = (XtextAnnotation) annotation;
		return xtextAnnotation.getIssue();
	} else if(annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
		return createIssue(markerAnnotation.getMarker());
	} else
		return null;
}
 
Example #4
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public String getCode(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getCode(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getIssueCode();	
	}
	return null;
}
 
Example #5
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public String[] getIssueData(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getIssueData(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getIssueData();	
	}
	return null;
}
 
Example #6
Source File: IssueUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public URI getUriToProblem(Annotation annotation) {
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation ma = (MarkerAnnotation) annotation;
		return getUriToProblem(ma.getMarker());
	}
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation xa = (XtextAnnotation) annotation;
		return xa.getUriToProblem();
	}
	return null;
}
 
Example #7
Source File: IssueDataTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@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()));
}
 
Example #8
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Check whether the given annotation type is supported, i.e. {@link #canFix(Annotation)} might return {@code true}.
 * This could be made protected in a future release.
 */
private boolean isSupported(Annotation annotation) {
	return !annotation.isMarkedDeleted()
			&& (annotation instanceof XtextAnnotation || annotation instanceof MarkerAnnotation
				|| annotation instanceof SpellingAnnotation);
}