Search in sources :

Example 21 with BasicDiagnostic

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

the class FSMStateImpl method isReachable.

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 *
 * @generated NOT
 */
public boolean isReachable(DiagnosticChain diagnostics, Map<Object, Object> context) {
    FSM fsm = (FSM) eContainer();
    Set<FSMState> reachable = new HashSet<>();
    Stack<FSMState> currents = new Stack<FSMState>();
    currents.addAll(fsm.getStates().stream().filter(x -> x.isInitial()).collect(Collectors.toSet()));
    while (!currents.isEmpty()) {
        FSMState current = currents.pop();
        if (current == this)
            return true;
        if (reachable.contains(current))
            continue;
        reachable.add(current);
        for (FSMTransition transition : current.getTransitions()) if (transition.getTarget() != null)
            currents.push(transition.getTarget());
    }
    if (diagnostics != null) {
        diagnostics.add(new BasicDiagnostic(Diagnostic.ERROR, FsmlValidator.DIAGNOSTIC_SOURCE, FsmlValidator.FSM_STATE__IS_REACHABLE, EcorePlugin.INSTANCE.getString("_UI_GenericInvariant_diagnostic", new Object[] { "isReachable", EObjectValidator.getObjectLabel(this, context) }), new Object[] { this }));
    }
    return false;
}
Also used : FSM(org.softlang.metalib.emf.fsml.fsml.FSM) FSMState(org.softlang.metalib.emf.fsml.fsml.FSMState) FSMTransition(org.softlang.metalib.emf.fsml.fsml.FSMTransition) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) InternalEObject(org.eclipse.emf.ecore.InternalEObject) HashSet(java.util.HashSet) Stack(java.util.Stack)

Example 22 with BasicDiagnostic

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

the class SGraphJavaValidationTest method assertError.

protected void assertError(BasicDiagnostic diag, String message) {
    Diagnostic d = issueByName(diag, message);
    assertNotNull("Issue '" + message + "' does not exist.", issueByName(diag, message));
    assertEquals("Issue '" + message + "' is no error.", Diagnostic.ERROR, d.getSeverity());
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic)

Example 23 with BasicDiagnostic

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

the class SGraphJavaValidationTest method setUp.

@Before
public void setUp() throws Exception {
    diagnostics = new BasicDiagnostic();
    factory = SGraphFactory.eINSTANCE;
    sTextFactory = StextFactory.eINSTANCE;
    statechart = factory.createStatechart();
    statechart.setName("SC");
}
Also used : BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Before(org.junit.Before)

Example 24 with BasicDiagnostic

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

the class ColumnPropertiesEditionComponent method validateValue.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
    Diagnostic ret = Diagnostic.OK_INSTANCE;
    if (event.getNewValue() != null) {
        try {
            if (DatabaseViewsRepository.Column.Properties.name == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getNamedElement_Name().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getNamedElement_Name().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.nullable == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getColumn_Nullable().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getColumn_Nullable().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.primaryKey == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getColumn_InPrimaryKey().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getColumn_InPrimaryKey().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.NullablePkAndUnique.unique == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getColumn_Unique().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getColumn_Unique().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.Sequence.autoincrement == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getColumn_Autoincrement().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getColumn_Autoincrement().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.defaultValue == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getColumn_DefaultValue().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getColumn_DefaultValue().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.comments == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(DatabasePackage.eINSTANCE.getDatabaseElement_Comments().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(DatabasePackage.eINSTANCE.getDatabaseElement_Comments().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.TypeAttributes.length == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(TypesLibraryPackage.eINSTANCE.getTypeInstance_Length().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(TypesLibraryPackage.eINSTANCE.getTypeInstance_Length().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.TypeAttributes.precision == event.getAffectedEditor()) {
                Object newValue = event.getNewValue();
                if (newValue instanceof String) {
                    newValue = EEFConverterUtil.createFromString(TypesLibraryPackage.eINSTANCE.getTypeInstance_Precision().getEAttributeType(), (String) newValue);
                }
                ret = Diagnostician.INSTANCE.validate(TypesLibraryPackage.eINSTANCE.getTypeInstance_Precision().getEAttributeType(), newValue);
            }
            if (DatabaseViewsRepository.Column.Properties.literals == event.getAffectedEditor()) {
                BasicDiagnostic chain = new BasicDiagnostic();
                for (Iterator iterator = ((List) event.getNewValue()).iterator(); iterator.hasNext(); ) {
                    chain.add(Diagnostician.INSTANCE.validate(TypesLibraryPackage.eINSTANCE.getTypeInstance_Literals().getEAttributeType(), iterator.next()));
                }
                ret = chain;
            }
        } catch (IllegalArgumentException iae) {
            ret = BasicDiagnostic.toDiagnostic(iae);
        } catch (WrappedException we) {
            ret = BasicDiagnostic.toDiagnostic(we);
        }
    }
    return ret;
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Iterator(java.util.Iterator) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) BasicEList(org.eclipse.emf.common.util.BasicEList) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 25 with BasicDiagnostic

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

the class StateMachineEditor method updateProblemIndication.

/**
 * Updates the problems indication with the information described in the specified diagnostic.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected void updateProblemIndication() {
    if (updateProblemIndication) {
        BasicDiagnostic diagnostic = new BasicDiagnostic(Diagnostic.OK, "org.obeonetwork.dsl.statemachine.editor", 0, null, new Object[] { editingDomain.getResourceSet() });
        for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) {
            if (childDiagnostic.getSeverity() != Diagnostic.OK) {
                diagnostic.add(childDiagnostic);
            }
        }
        int lastEditorPage = getPageCount() - 1;
        if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) {
            ((ProblemEditorPart) getEditor(lastEditorPage)).setDiagnostic(diagnostic);
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                setActivePage(lastEditorPage);
            }
        } else if (diagnostic.getSeverity() != Diagnostic.OK) {
            ProblemEditorPart problemEditorPart = new ProblemEditorPart();
            problemEditorPart.setDiagnostic(diagnostic);
            problemEditorPart.setMarkerHelper(markerHelper);
            try {
                addPage(++lastEditorPage, problemEditorPart, getEditorInput());
                setPageText(lastEditorPage, problemEditorPart.getPartName());
                setActivePage(lastEditorPage);
                showTabs();
            } catch (PartInitException exception) {
                StateMachineEditorPlugin.INSTANCE.log(exception);
            }
        }
        if (markerHelper.hasMarkers(editingDomain.getResourceSet())) {
            markerHelper.deleteMarkers(editingDomain.getResourceSet());
            if (diagnostic.getSeverity() != Diagnostic.OK) {
                try {
                    markerHelper.createMarkers(diagnostic);
                } catch (CoreException exception) {
                    StateMachineEditorPlugin.INSTANCE.log(exception);
                }
            }
        }
    }
}
Also used : ProblemEditorPart(org.eclipse.emf.common.ui.editor.ProblemEditorPart) CoreException(org.eclipse.core.runtime.CoreException) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) PartInitException(org.eclipse.ui.PartInitException) Point(org.eclipse.swt.graphics.Point)

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