Search in sources :

Example 1 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-eclipse by eclipse.

the class NoJRESmokeTester method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    Assert.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) 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 2 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project xtext-eclipse by eclipse.

the class ValidatorTester method diagnose.

public AssertableDiagnostics diagnose() {
    if (!validatorCalled)
        throw new IllegalStateException("You have to call validator() before you call diagnose()");
    validatorCalled = false;
    AssertableDiagnostics ad = new AssertableDiagnostics((Diagnostic) validator.setMessageAcceptor(validator).getState().chain);
    validator.setMessageAcceptor(validator).getState().chain = new BasicDiagnostic();
    return ad;
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic)

Example 3 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project iobserve-analysis by research-iobserve.

the class cloudprofileEditor method analyzeResourceProblems.

/**
 * Returns a diagnostic describing the errors and warnings listed in the resource
 * and the specified exception (if any).
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
    boolean hasErrors = !resource.getErrors().isEmpty();
    if (hasErrors || !resource.getWarnings().isEmpty()) {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "org.iobserve.planning.cloudprofile.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception == null ? (Object) resource : exception });
        basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
        return basicDiagnostic;
    } else if (exception != null) {
        return new BasicDiagnostic(Diagnostic.ERROR, "org.iobserve.planning.cloudprofile.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception });
    } else {
        return Diagnostic.OK_INSTANCE;
    }
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EventObject(java.util.EventObject)

Example 4 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project iobserve-analysis by research-iobserve.

the class systemadaptationEditor method analyzeResourceProblems.

/**
 * Returns a diagnostic describing the errors and warnings listed in the resource
 * and the specified exception (if any).
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) {
    boolean hasErrors = !resource.getErrors().isEmpty();
    if (hasErrors || !resource.getWarnings().isEmpty()) {
        BasicDiagnostic basicDiagnostic = new BasicDiagnostic(hasErrors ? Diagnostic.ERROR : Diagnostic.WARNING, "planning.systemadaptation.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception == null ? (Object) resource : exception });
        basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true));
        return basicDiagnostic;
    } else if (exception != null) {
        return new BasicDiagnostic(Diagnostic.ERROR, "planning.systemadaptation.editor", 0, getString("_UI_CreateModelError_message", resource.getURI()), new Object[] { exception });
    } else {
        return Diagnostic.OK_INSTANCE;
    }
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EventObject(java.util.EventObject)

Example 5 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project n4js by eclipse.

the class AutomaticCancelationTest method testCancelIndicatorGetsInvokedAutomatically.

@Test
public void testCancelIndicatorGetsInvokedAutomatically() throws Exception {
    String program = " class X { \n\t a: any; \n\t a: any; } } ";
    Script s;
    try {
        s = ph.parse(program);
        N4ClassDeclaration clazz = (N4ClassDeclaration) s.getScriptElements().get(0);
        Map<Object, Object> context = new HashMap<>();
        context.put(CancelableDiagnostician.CANCEL_INDICATOR, new TraceLeavingCancelIndicator());
        // the cancel indicator in use sets a flag in case its isCanceled() was queried
        assertTrue(!(wasChecked.get()));
        DiagnosticChain chain = new BasicDiagnostic();
        try {
            v.validate(clazz, chain, context);
            fail("expected OperationCanceledException or OperationCanceledError was not thrown");
        } catch (Throwable th) {
            assertTrue("wrong kind of throwable; expected: OperationCanceledException or OperationCanceledError, actual: " + th.getClass().getSimpleName(), operationCanceledManager.isOperationCanceledException(th));
        }
        assertTrue(wasChecked.get());
        // now validate with a cancel indicator that never cancels,
        // upon which validation methods run and errors are recorded.
        context.put(CancelableDiagnostician.CANCEL_INDICATOR, CancelIndicator.NullImpl);
        final boolean isValid02 = v.validate(clazz, chain, context);
        assertTrue(!isValid02);
        // validate again (this time with the default cancel indicator, which never cancels),
        // check expected errors one by one.
        String[] expectedErrorMsgs = { "The field a (line 2) duplicates field a (line 3).", "The field a (line 3) duplicates field a (line 2)." };
        for (String expectedErrorMsg : expectedErrorMsgs) {
            vth.assertError(s, N4JSPackage.Literals.N4_MEMBER_DECLARATION, IssueCodes.CLF_DUP_MEMBER, expectedErrorMsg);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Script(org.eclipse.n4js.n4JS.Script) HashMap(java.util.HashMap) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) N4ClassDeclaration(org.eclipse.n4js.n4JS.N4ClassDeclaration) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) Test(org.junit.Test)

Aggregations

BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)106 Diagnostic (org.eclipse.emf.common.util.Diagnostic)49 EObject (org.eclipse.emf.ecore.EObject)43 EventObject (java.util.EventObject)30 CoreException (org.eclipse.core.runtime.CoreException)30 ProblemEditorPart (org.eclipse.emf.common.ui.editor.ProblemEditorPart)30 Point (org.eclipse.swt.graphics.Point)30 PartInitException (org.eclipse.ui.PartInitException)30 Test (org.junit.Test)19 List (java.util.List)13 Iterator (java.util.Iterator)8 BasicEList (org.eclipse.emf.common.util.BasicEList)8 EList (org.eclipse.emf.common.util.EList)8 WrappedException (org.eclipse.emf.common.util.WrappedException)8 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)5 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)5 Severity (org.eclipse.xtext.diagnostics.Severity)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 Issue (org.eclipse.xtext.validation.Issue)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5