org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic Java Examples

The following examples show how to use org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic. 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: ReducedXtextResourceValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void issueFromXtextResourceDiagnostic(Diagnostic diagnostic, Severity severity,
		IAcceptor<Issue> acceptor) {
	if (diagnostic instanceof XtextSyntaxDiagnostic) {
		super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor);
	} else if (diagnostic instanceof XtextLinkingDiagnostic) {
		XtextLinkingDiagnostic linkingDiagnostic = (XtextLinkingDiagnostic) diagnostic;
		if (linkingDiagnostic.getCode().equals(XtextLinkingDiagnosticMessageProvider.UNRESOLVED_RULE)) {
			super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor);
		} else if (linkingDiagnostic.getMessage().contains("reference to Grammar")) {
			super.issueFromXtextResourceDiagnostic(diagnostic, severity, acceptor);
		}
	}
}
 
Example #2
Source File: AbstractSCTResource.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void createDiagnostic(Triple<EObject, EReference, INode> triple) {
	SpecificationElement specificationElement = EcoreUtil2.getContainerOfType(triple.getFirst(),
			SpecificationElement.class);
	DiagnosticMessage message = createDiagnosticMessage(triple);
	Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(),
			message.getIssueCode(), message.getIssueData());
	linkingDiagnostics.put(specificationElement, diagnostic);

}
 
Example #3
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Assert linking errors on resource with the given message exist.
 *
 * @param object
 *          the object
 * @param referenceType
 *          the type of the referenced elements
 * @param referenceNames
 *          the names of the referenced elements
 */
public static void assertLinkingErrorsOnResourceExist(final EObject object, final String referenceType, final String... referenceNames) {
  final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList());
  final List<String> errorMessages = Lists.transform(linkingErrors, Resource.Diagnostic::getMessage);
  for (final String referenceName : referenceNames) {
    boolean found = false;
    for (final String errMessage : errorMessages) {
      if (errMessage.contains(referenceName)) {
        found = true;
        break;
      }
    }
    assertTrue(NLS.bind("Expected linking error on \"{0}\" but could not find it", referenceName), found);
  }
}
 
Example #4
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Assert no linking errors on resource with the given message exist.
 *
 * @param object
 *          the object
 * @param referenceType
 *          the type of the referenced elements
 * @param referenceNames
 *          the names of the referenced elements
 */
public static void assertNoLinkingErrorsOnResource(final EObject object, final String referenceType, final String... referenceNames) {
  final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList());
  final List<String> errorMessages = Lists.transform(linkingErrors, Resource.Diagnostic::getMessage);
  for (final String referenceName : referenceNames) {
    boolean found = false;
    for (final String errMessage : errorMessages) {
      if (errMessage.startsWith(referenceName)) {
        found = true;
        break;
      }
    }
    assertFalse(NLS.bind("Expecting no linking errors on resource for \"{0}\".", referenceName), found);
  }
}
 
Example #5
Source File: Bug362902Test.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoExceptionUncaught() throws Exception {
	String modelAsString = "Hello max ! Hello peter! favourite peter";
	Model model = (Model)getModelAndExpect(modelAsString, 2);
	EList<Diagnostic> errors = model.eResource().getErrors();
	Diagnostic diagnosticSyntax = errors.get(0);
	Diagnostic diagnosticLinking = errors.get(1);
	assertTrue(diagnosticSyntax instanceof XtextSyntaxDiagnostic);
	assertTrue(diagnosticLinking instanceof XtextLinkingDiagnostic);
}
 
Example #6
Source File: XtextResourceTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testErrorMarkers() throws Exception {
	String model = "spielplatz 1 {kind(B 1) erwachsener(E 1) familie(F E E B, C)}";
	resource.update(0, 0, model);
	EcoreUtil.resolveAll(resource);
	assertEquals(1, resource.getErrors().size());
	XtextLinkingDiagnostic diag = (XtextLinkingDiagnostic) resource.getErrors().get(0);
	assertEquals(model.indexOf("C)"), diag.getOffset());
	assertEquals(1, diag.getLength());
}
 
Example #7
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testStaticImports_02() throws Exception {
	String fileAsText= "import static java.util.Collections.* class Clazz { def void method() { ''.singletonList() } }";
	XtendFile file = file(fileAsText, false);
	EcoreUtil.resolveAll(file);
	List<Diagnostic> errors = file.eResource().getErrors();
	assertEquals(1, errors.size());
	assertTrue(errors.get(0) instanceof XtextLinkingDiagnostic);
	XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errors.get(0);
	assertEquals(fileAsText.indexOf("singletonList"),  diagnostic.getOffset());
}
 
Example #8
Source File: LinkingTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testStaticImports_01() throws Exception {
	String fileAsText= "import java.util.Collections.* class Clazz { def void method() { ''.singletonList() } }";
	XtendFile file = file(fileAsText, false);
	EcoreUtil.resolveAll(file);
	List<Diagnostic> errors = file.eResource().getErrors();
	assertEquals(1, errors.size());
	assertTrue(errors.get(0) instanceof XtextLinkingDiagnostic);
	XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errors.get(0);
	assertEquals(fileAsText.indexOf("singletonList"),  diagnostic.getOffset());
}
 
Example #9
Source File: UTF8ParserErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testInvalidReference_02() throws Exception {
	XtendFunction func = function("def m() { invalid\\u0020Part }");
	XBlockExpression block = (XBlockExpression) func.getExpression();
	XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
	String featureName = featureCall.getConcreteSyntaxFeatureName();
	assertEquals("invalid\\u0020Part", featureName);
	assertTrue(featureCall.getFeature().eIsProxy());
	List<Diagnostic> errorList = func.eResource().getErrors();
	assertEquals(2, errorList.size());
	XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
	assertTrue(diagnostic.getMessage().contains("invalidPart"));
}
 
Example #10
Source File: UTF8ParserErrorTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testInvalidReference_01() throws Exception {
	XtendFunction func = function("def m() { \\u0020invalidStart }");
	XBlockExpression block = (XBlockExpression) func.getExpression();
	XFeatureCall featureCall = (XFeatureCall) block.getExpressions().get(0);
	String featureName = featureCall.getConcreteSyntaxFeatureName();
	assertEquals("\\u0020invalidStart", featureName);
	assertTrue(featureCall.getFeature().eIsProxy());
	List<Diagnostic> errorList = func.eResource().getErrors();
	assertEquals(2, errorList.size());
	XtextLinkingDiagnostic diagnostic = (XtextLinkingDiagnostic) errorList.get(1);
	assertTrue(diagnostic.getMessage().contains("invalidStart"));
}
 
Example #11
Source File: AbstractUnresolvableReferenceWithNode.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected Resource.Diagnostic createDiagnostic(DiagnosticMessage message) {
	Diagnostic diagnostic = new XtextLinkingDiagnostic(
			node, 
			message.getMessage(),
			message.getIssueCode(), message.getIssueData());
	return diagnostic;
}
 
Example #12
Source File: ErrorAwareLinkingService.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add the error to the resource of the given {@code context} if it does support validation.
 *
 * @param context
 *            the context object that caused the error.
 * @param node
 *            the error location.
 * @param error
 *            the actual error description.
 */
protected void addError(EObject context, INode node, IEObjectDescriptionWithError error) {
	N4JSResource resource = (N4JSResource) context.eResource();
	if (resource.isValidationDisabled())
		return;

	final Severity severity = error.getSeverity();
	List<Diagnostic> list;
	if (severity == Severity.WARNING) {
		list = resource.getWarnings();
	} else {
		list = resource.getErrors();
	}

	// Convert key value user data to String array
	String[] userData = null;
	if (error.getUserDataKeys() != null) {
		ArrayList<String> userDataList = new ArrayList<>(error.getUserDataKeys().length * 2);
		for (String userDataKey : error.getUserDataKeys()) {
			final String userDataValue = error.getUserData(userDataKey);
			if (userDataValue != null) {
				userDataList.add(userDataKey);
				userDataList.add(userDataValue);
			}
		}
		userData = userDataList.toArray(new String[userDataList.size()]);
	}

	Diagnostic diagnostic = new XtextLinkingDiagnostic(node, error.getMessage(), error.getIssueCode(), userData);

	if (!list.contains(diagnostic))
		list.add(diagnostic);
}
 
Example #13
Source File: ASTStructureDiagnosticProducer.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected Diagnostic createDiagnostic(DiagnosticMessage message) {
	return new XtextLinkingDiagnostic(getNode(), message.getMessage(), message.getIssueCode(),
			message.getIssueData());
}
 
Example #14
Source File: LazyLinkingResource.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Diagnostic createDiagnostic(Triple<EObject, EReference, INode> triple, DiagnosticMessage message) {
	Diagnostic diagnostic = new XtextLinkingDiagnostic(triple.getThird(), message.getMessage(),
			message.getIssueCode(), message.getIssueData());
	return diagnostic;
}
 
Example #15
Source File: AbstractTypeResolverTest.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Iterable<Resource.Diagnostic> getLinkingAndSyntaxErrors(final Resource resource) {
  final Function1<Resource.Diagnostic, Boolean> _function = (Resource.Diagnostic it) -> {
    return Boolean.valueOf(((it instanceof XtextSyntaxDiagnostic) || (it instanceof XtextLinkingDiagnostic)));
  };
  return IterableExtensions.<Resource.Diagnostic>filter(resource.getErrors(), _function);
}
 
Example #16
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Expect the given linking error messages on the resource of the given model.
 *
 * @param object
 *          the object, must not be {@code null}
 * @param errorStrings
 *          the expected linking error error messages, must not be {@code null}
 */
public static void assertLinkingErrorsWithCustomMessageOnResourceExist(final EObject object, final String... errorStrings) {
  final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList());
  final List<String> errorMessages = Lists.transform(linkingErrors, Resource.Diagnostic::getMessage);
  for (final String s : errorStrings) {
    assertTrue(NLS.bind("Expected linking error \"{0}\" but could not find it", s), errorMessages.contains(s));
  }
}
 
Example #17
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Assert no linking errors on resource with the given message exist.
 *
 * @param object
 *          the object, must not be {@code null}
 * @param messages
 *          the linking error messages, must not be {@code null}
 */
public static void assertNoLinkingErrorsWithCustomMessageOnResource(final EObject object, final String... messages) {
  List<String> messageList = Arrays.asList(messages);
  final List<Resource.Diagnostic> linkingErrors = object.eResource().getErrors().stream().filter(error -> error instanceof XtextLinkingDiagnostic).collect(Collectors.toList());
  for (String errorMessage : Lists.transform(linkingErrors, Resource.Diagnostic::getMessage)) {
    assertFalse(NLS.bind("Expecting no linking errors on resource with message \"{0}\".", errorMessage), messageList.contains(errorMessage));
  }
}