Search in sources :

Example 6 with Transition

use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.

the class FoldOutgoingActionsRefactoring method removeFirstActions.

private void removeFirstActions(EList<Transition> transitions, int number) {
    for (Transition transition : transitions) {
        List<Expression> actionsToRemove = getFirstActions(transition, number);
        Effect effect = transition.getEffect();
        if (effect instanceof ReactionEffect && actionsToRemove.size() == ((ReactionEffect) effect).getActions().size()) {
            // we need to remove all actions, so just remove the effect recursively which avoids serializer exceptions
            EcoreUtil.delete(effect, true);
        } else {
            for (Expression action : actionsToRemove) {
                EcoreUtil.delete(action);
            }
        }
    }
}
Also used : Expression(org.yakindu.base.expressions.expressions.Expression) Transition(org.yakindu.sct.model.sgraph.Transition) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect) Effect(org.yakindu.sct.model.sgraph.Effect) ReactionEffect(org.yakindu.sct.model.stext.stext.ReactionEffect)

Example 7 with Transition

use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.

the class AddOutgoingStateModification method execute.

@Override
protected void execute(EObject semanticElement, View view) {
    State state = (State) semanticElement;
    State newState = SGraphFactory.eINSTANCE.createState();
    Transition transition = SGraphFactory.eINSTANCE.createTransition();
    state.getParentRegion().getVertices().add(newState);
    transition.setSource(state);
    transition.setTarget(newState);
    if (transitionSpecification != null)
        transition.setSpecification(transitionSpecification);
    if (stateName != null)
        newState.setName(stateName);
}
Also used : State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition)

Example 8 with Transition

use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.

the class NotationClipboardOperationHelper method getSemanticPasteTarget.

// PATCH START
/**
 * Customized Method to find the semantic target which should contain the
 * copied elements.
 *
 * @param view
 * @param container
 * @return the semantic target.
 */
public static EObject getSemanticPasteTarget(View view, View container) {
    EObject copiedSemanticObject = view.getElement();
    EObject semanticTarget = container.getElement();
    if (copiedSemanticObject instanceof Transition) {
        semanticTarget = copiedSemanticObject.eContainer();
    }
    EList<EReference> eAllReferences = semanticTarget.eClass().getEAllReferences();
    for (EReference eReference : eAllReferences) {
        EClass eReferenceType = eReference.getEReferenceType();
        if (eReference.isContainment() && eReferenceType.isSuperTypeOf(copiedSemanticObject.eClass())) {
            return semanticTarget;
        }
    }
    return null;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) Transition(org.yakindu.sct.model.sgraph.Transition) EReference(org.eclipse.emf.ecore.EReference)

Example 9 with Transition

use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.

the class VertexEditHelper method getDestroyDependentsCommand.

@Override
protected ICommand getDestroyDependentsCommand(DestroyDependentsRequest req) {
    Vertex elementToDestroy = (Vertex) req.getElementToDestroy();
    EList<Transition> incomingTransitions = elementToDestroy.getIncomingTransitions();
    if (incomingTransitions.size() != 0) {
        CompositeCommand compoundCommand = new CompositeCommand("Delete vertex");
        for (Transition transition : incomingTransitions) {
            DestroyElementCommand destroyCommand = new DestroyElementCommand(new DestroyElementRequest(transition, false));
            compoundCommand.add(destroyCommand);
        }
        return compoundCommand;
    }
    return super.getDestroyDependentsCommand(req);
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) DestroyElementRequest(org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest) Transition(org.yakindu.sct.model.sgraph.Transition) DestroyElementCommand(org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand) CompositeCommand(org.eclipse.gmf.runtime.common.core.command.CompositeCommand)

Example 10 with Transition

use of org.yakindu.sct.model.sgraph.Transition in project statecharts by Yakindu.

the class STextJavaValidator method checkUnboundEntryPoints.

@Check(CheckType.NORMAL)
public void checkUnboundEntryPoints(final org.yakindu.sct.model.sgraph.State state) {
    if (state.isComposite()) {
        final List<Transition>[] transitions = STextValidationModelUtils.getEntrySpecSortedTransitions(state.getIncomingTransitions());
        Map<Region, List<Entry>> regions = null;
        // first list contains Transitions without entry spec
        if (!transitions[0].isEmpty()) {
            regions = STextValidationModelUtils.getRegionsWithoutDefaultEntry(state.getRegions());
            if (!regions.isEmpty()) {
                for (Transition transition : transitions[0]) {
                    error(TRANSITION_UNBOUND_DEFAULT_ENTRY_POINT, transition, null, -1);
                }
                for (Region region : regions.keySet()) {
                    error(REGION_UNBOUND_DEFAULT_ENTRY_POINT, region, null, -1);
                }
            }
        }
        // second list contains Transitions with entry spec
        if (!transitions[1].isEmpty()) {
            if (regions == null) {
                regions = STextValidationModelUtils.getRegionsWithoutDefaultEntry(state.getRegions());
            }
            for (Transition transition : transitions[1]) {
                boolean hasTargetEntry = true;
                for (ReactionProperty property : transition.getProperties()) {
                    if (property instanceof EntryPointSpec) {
                        EntryPointSpec spec = (EntryPointSpec) property;
                        String specName = "'" + spec.getEntrypoint() + "'";
                        for (Region region : regions.keySet()) {
                            boolean hasEntry = false;
                            for (Entry entry : regions.get(region)) {
                                if (entry.getName().equals(spec.getEntrypoint())) {
                                    hasEntry = true;
                                    break;
                                }
                            }
                            if (!hasEntry) {
                                error(REGION_UNBOUND_NAMED_ENTRY_POINT + specName, region, null, -1);
                                hasTargetEntry = false;
                            }
                        }
                        if (!hasTargetEntry) {
                            error(TRANSITION_UNBOUND_NAMED_ENTRY_POINT + specName, transition, null, -1);
                        }
                    }
                }
            }
        }
    }
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) List(java.util.List) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) EntryPointSpec(org.yakindu.sct.model.stext.stext.EntryPointSpec) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty) Check(org.eclipse.xtext.validation.Check)

Aggregations

Transition (org.yakindu.sct.model.sgraph.Transition)63 Test (org.junit.Test)34 Region (org.yakindu.sct.model.sgraph.Region)26 State (org.yakindu.sct.model.sgraph.State)23 Statechart (org.yakindu.sct.model.sgraph.Statechart)19 FinalState (org.yakindu.sct.model.sgraph.FinalState)13 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)13 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)13 SGraphTestFactory._createTransition (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition)13 ReactionTrigger (org.yakindu.sct.model.stext.stext.ReactionTrigger)13 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)10 Entry (org.yakindu.sct.model.sgraph.Entry)10 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)10 StextTestFactory._createReactionTrigger (org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger)9 EventDefinition (org.yakindu.sct.model.stext.stext.EventDefinition)8 LocalReaction (org.yakindu.sct.model.stext.stext.LocalReaction)8 ReactionEffect (org.yakindu.sct.model.stext.stext.ReactionEffect)8 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)7 If (org.yakindu.sct.model.sexec.If)7 Vertex (org.yakindu.sct.model.sgraph.Vertex)7