Search in sources :

Example 1 with XtextLinkingDiagnostic

use of org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic in project statecharts by Yakindu.

the class AbstractSCTResource method createDiagnostic.

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);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic)

Example 2 with XtextLinkingDiagnostic

use of org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic in project xtext-xtend by eclipse.

the class UTF8ParserErrorTest method testInvalidReference_01.

@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"));
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XFeatureCall(org.eclipse.xtext.xbase.XFeatureCall) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 3 with XtextLinkingDiagnostic

use of org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic in project n4js by eclipse.

the class ErrorAwareLinkingService method addError.

/**
 * 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;
    List<Diagnostic> 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);
}
Also used : XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) ArrayList(java.util.ArrayList) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic)

Example 4 with XtextLinkingDiagnostic

use of org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic in project xtext-xtend by eclipse.

the class LinkingTest method testStaticImports_01.

@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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 5 with XtextLinkingDiagnostic

use of org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic in project xtext-xtend by eclipse.

the class LinkingTest method testStaticImports_02.

@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());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) XtextLinkingDiagnostic(org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Aggregations

XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)8 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)6 Test (org.junit.Test)6 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtextSyntaxDiagnostic (org.eclipse.xtext.resource.XtextSyntaxDiagnostic)2 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)2 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)2 ArrayList (java.util.ArrayList)1 DiagnosticMessage (org.eclipse.xtext.diagnostics.DiagnosticMessage)1 Model (org.eclipse.xtext.linking.bug362902.Model)1 SpecificationElement (org.yakindu.sct.model.sgraph.SpecificationElement)1