Search in sources :

Example 16 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 17 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 18 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)

Example 19 with BasicDiagnostic

use of org.eclipse.emf.common.util.BasicDiagnostic in project dsl-devkit by dsldevkit.

the class CheckExtensionGenerator method catalogValidates.

/**
 * Catalog validates.
 *
 * @param catalog
 *          the catalog
 * @return true, if successful
 */
private boolean catalogValidates(final CheckCatalog catalog) {
    EValidator.Registry eValidatorRegistry = EValidator.Registry.INSTANCE;
    EValidator eValidator = eValidatorRegistry.getEValidator(catalog.eClass().getEPackage());
    BasicDiagnostic diag = new BasicDiagnostic();
    eValidator.validate(catalog, diag, Maps.newHashMap());
    Iterable<Diagnostic> children = diag.getChildren();
    Iterable<Diagnostic> errors = Iterables.filter(children, new Predicate<Diagnostic>() {

        @Override
        public boolean apply(final Diagnostic input) {
            return input.getSeverity() == Diagnostic.ERROR;
        }
    });
    return Iterables.isEmpty(errors);
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) EValidator(org.eclipse.emf.ecore.EValidator)

Example 20 with BasicDiagnostic

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

the class FsmlEditor 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.softlang.metalib.sirius.fsml.model.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.softlang.metalib.sirius.fsml.model.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)

Aggregations

BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)103 Diagnostic (org.eclipse.emf.common.util.Diagnostic)48 EObject (org.eclipse.emf.ecore.EObject)41 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)16 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