Search in sources :

Example 26 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.

the class SmokeTest method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, LazyLinkingResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    throwError(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throwError(new RuntimeException("Dangling reference found."));
                }
            }
        }

        private void throwError(Throwable e) {
            ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
            result.setStackTrace(e.getStackTrace());
            throw result;
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                throwError(e);
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) IOException(java.io.IOException) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ComparisonFailure(org.junit.ComparisonFailure) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 27 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic 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 28 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic 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)

Example 29 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.

the class LinkingErrorTest method validateWithoutException.

protected void validateWithoutException(XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    // and AssertionError does not take a throwable as argument
                    throw new Error(t);
                }
            }
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                // and AssertionError does not take a throwable as argument
                throw new Error(new RuntimeException(e));
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 30 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-xtend by eclipse.

the class UTF8ParserErrorTest method testInvalidReference_02.

@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"));
}
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)

Aggregations

Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)32 Test (org.junit.Test)12 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 XtextResource (org.eclipse.xtext.resource.XtextResource)8 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)7 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Issue (org.eclipse.xtext.validation.Issue)6 List (java.util.List)5 EObject (org.eclipse.emf.ecore.EObject)5 Severity (org.eclipse.xtext.diagnostics.Severity)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5 IOException (java.io.IOException)4 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)3 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)3 ComparisonFailure (org.junit.ComparisonFailure)3 ArrayList (java.util.ArrayList)2 URI (org.eclipse.emf.common.util.URI)2