org.eclipse.jface.text.source.projection.ProjectionAnnotation#org.eclipse.xtext.ui.editor.validation.XtextAnnotation源码实例Demo

下面列出了org.eclipse.jface.text.source.projection.ProjectionAnnotation#org.eclipse.xtext.ui.editor.validation.XtextAnnotation 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xtext-eclipse   文件: XtextQuickAssistProcessor.java
@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;
}
 
源代码2 项目: dsl-devkit   文件: MarkerIdentity.java
/**
 * 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;
}
 
源代码3 项目: xtext-eclipse   文件: IssueUtil.java
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;
}
 
源代码4 项目: xtext-eclipse   文件: IssueUtil.java
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;
}
 
源代码5 项目: xtext-eclipse   文件: IssueUtil.java
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;
}
 
源代码6 项目: xtext-eclipse   文件: IssueUtil.java
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;
}
 
源代码7 项目: xtext-eclipse   文件: IssueDataTest.java
@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()));
}
 
源代码8 项目: xtext-eclipse   文件: XtextQuickAssistProcessor.java
/**
 * 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);
}