Search in sources :

Example 1 with FSMState

use of org.softlang.metalib.emf.fsml.fsml.FSMState in project metalib by softlang.

the class FSMTransitionImpl method setTarget.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setTarget(FSMState newTarget) {
    FSMState oldTarget = target;
    target = newTarget;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, FsmlPackage.FSM_TRANSITION__TARGET, oldTarget, target));
}
Also used : FSMState(org.softlang.metalib.emf.fsml.fsml.FSMState) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 2 with FSMState

use of org.softlang.metalib.emf.fsml.fsml.FSMState 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 3 with FSMState

use of org.softlang.metalib.emf.fsml.fsml.FSMState in project metalib by softlang.

the class StandaloneTurnstile method main.

public static void main(String[] args) {
    // Register package as a side-effect.
    FsmlPackage.eINSTANCE.eClass();
    // The ResourceSet that this standalone application is using.
    ResourceSet resourceSet = new ResourceSetImpl();
    // Get the registry for ResourceFactories.
    Registry resourceFactoryRegistry = resourceSet.getResourceFactoryRegistry();
    // Register the XMIResourceFactory for files with fsml extension.
    XMIResourceFactoryImpl xmiResourceFactory = new XMIResourceFactoryImpl();
    resourceFactoryRegistry.getExtensionToFactoryMap().put("fsml", xmiResourceFactory);
    // Deserialize XMI File.
    Resource fsmlResource = resourceSet.getResource(URI.createURI("Turnstile.fsml"), true);
    // Read the Turnstile model.
    FSM fsmTurnstileEObject = (FSM) fsmlResource.getContents().get(0);
    EList<FSMState> fsmTurnstileStateEObjects = fsmTurnstileEObject.getStates();
}
Also used : FSM(org.softlang.metalib.emf.fsml.fsml.FSM) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) FSMState(org.softlang.metalib.emf.fsml.fsml.FSMState) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry)

Aggregations

FSMState (org.softlang.metalib.emf.fsml.fsml.FSMState)3 FSM (org.softlang.metalib.emf.fsml.fsml.FSM)2 HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Registry (org.eclipse.emf.ecore.resource.Resource.Factory.Registry)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)1 FSMTransition (org.softlang.metalib.emf.fsml.fsml.FSMTransition)1