Search in sources :

Example 11 with Transition

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

the class STextJavaValidator method checkUnusedEntry.

@Check(CheckType.FAST)
public void checkUnusedEntry(final Entry entry) {
    if (entry.getParentRegion().getComposite() instanceof org.yakindu.sct.model.sgraph.State && entry.getIncomingTransitions().isEmpty()) {
        org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) entry.getParentRegion().getComposite();
        if (!STextValidationModelUtils.isDefault(entry)) {
            boolean hasIncomingTransition = false;
            Iterator<Transition> transitionIt = state.getIncomingTransitions().iterator();
            while (transitionIt.hasNext() && !hasIncomingTransition) {
                Iterator<ReactionProperty> propertyIt = transitionIt.next().getProperties().iterator();
                while (propertyIt.hasNext() && !hasIncomingTransition) {
                    ReactionProperty property = propertyIt.next();
                    if (property instanceof EntryPointSpec) {
                        hasIncomingTransition = entry.getName().equals(((EntryPointSpec) property).getEntrypoint());
                    }
                }
            }
            if (!hasIncomingTransition) {
                warning(ENTRY_UNUSED, entry, null, -1);
            }
        }
    }
}
Also used : EntryPointSpec(org.yakindu.sct.model.stext.stext.EntryPointSpec) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty) Transition(org.yakindu.sct.model.sgraph.Transition) Check(org.eclipse.xtext.validation.Check)

Example 12 with Transition

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

the class STextJavaValidator method checkUnusedExit.

@Check(CheckType.NORMAL)
public void checkUnusedExit(final Exit exit) {
    if (exit.getParentRegion().getComposite() instanceof org.yakindu.sct.model.sgraph.State && exit.getOutgoingTransitions().isEmpty()) {
        org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) exit.getParentRegion().getComposite();
        if (!STextValidationModelUtils.isDefault(exit)) {
            boolean hasOutgoingTransition = false;
            Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
            while (transitionIt.hasNext() && !hasOutgoingTransition) {
                Transition transition = transitionIt.next();
                hasOutgoingTransition = STextValidationModelUtils.isDefaultExitTransition(transition) ? true : STextValidationModelUtils.isNamedExitTransition(transition, exit.getName());
            }
            if (!hasOutgoingTransition) {
                error(EXIT_UNUSED, exit, null, -1);
            }
        } else {
            boolean hasOutgoingTransition = false;
            Iterator<Transition> transitionIt = state.getOutgoingTransitions().iterator();
            while (transitionIt.hasNext() && !hasOutgoingTransition) {
                hasOutgoingTransition = STextValidationModelUtils.isDefaultExitTransition(transitionIt.next());
            }
            if (!hasOutgoingTransition) {
                error(EXIT_DEFAULT_UNUSED, exit, null, -1);
            }
        }
    }
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition) Check(org.eclipse.xtext.validation.Check)

Example 13 with Transition

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

the class STextValidationModelUtils method getExitSpecSortedTransitions.

/**
 * Sorts the given elements in transition without and with
 * {@link ExitPointSpec}s
 *
 * @param elements
 *            - list of transitions to sort
 * @return an array with the sorted elements. The first index contains a
 *         list of the transitions without {@link ExitPointSpec}s. The
 *         second index contains a list of the transitions with
 *         {@link ExitPointSpec}s.
 */
public static List<Transition>[] getExitSpecSortedTransitions(List<Transition> elements) {
    @SuppressWarnings("unchecked") final List<Transition>[] transitions = new ArrayList[2];
    // first list contains Transitions without exit spec
    transitions[0] = new ArrayList<Transition>();
    // second list contains Transitions with exit spec
    transitions[1] = new ArrayList<Transition>();
    for (Transition transition : elements) {
        boolean hasExitSpec = false;
        for (ReactionProperty property : transition.getProperties()) {
            if (property instanceof ExitPointSpec) {
                transitions[1].add(transition);
                hasExitSpec = true;
                break;
            }
        }
        if (!hasExitSpec) {
            transitions[0].add(transition);
        }
    }
    return transitions;
}
Also used : ExitPointSpec(org.yakindu.sct.model.stext.stext.ExitPointSpec) ArrayList(java.util.ArrayList) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList) List(java.util.List) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty)

Example 14 with Transition

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

the class SGraphJavaValidator method orthogonalSynchronizedTransition.

@Check
public void orthogonalSynchronizedTransition(Synchronization sync) {
    List<Transition> incoming = sync.getIncomingTransitions();
    List<List<EObject>> inAncestorsList = new ArrayList<>();
    for (Transition trans : incoming) {
        inAncestorsList.add(collectAncestors(trans.getSource(), new ArrayList<EObject>()));
    }
    List<Transition> outgoing = sync.getOutgoingTransitions();
    List<List<EObject>> outAncestorsList = new ArrayList<>();
    for (Transition trans : outgoing) {
        outAncestorsList.add(collectAncestors(trans.getTarget(), new ArrayList<EObject>()));
    }
    Set<Transition> inOrthogonal = new HashSet<>();
    Set<Transition> outOrthogonal = new HashSet<>();
    if (incoming.size() == 0 || outgoing.size() == 0) {
        return;
    }
    for (int i = 0; i < incoming.size(); i++) {
        for (int j = 0; j < outgoing.size(); j++) {
            List<Vertex> states = new ArrayList<>(Arrays.asList(incoming.get(i).getSource(), outgoing.get(j).getTarget()));
            if (areOrthogonal(states)) {
                inOrthogonal.add(incoming.get(i));
                outOrthogonal.add(outgoing.get(j));
            }
        }
    }
    for (Transition trans : inOrthogonal) {
        error(ISSUE_SYNCHRONIZATION_SOURCE_TARGET_STATES_PARENT_REGION, trans, null, -1);
    }
    for (Transition trans : outOrthogonal) {
        error(ISSUE_SYNCHRONIZATION_SOURCE_TARGET_STATES_PARENT_REGION, trans, null, -1);
    }
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 15 with Transition

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

the class TransitionItemProvider method getText.

/**
 * This returns the label text for the adapted class. <!-- begin-user-doc
 * --> <!-- end-user-doc -->
 *
 * @generated NOT
 */
@Override
public String getText(Object object) {
    Transition transition = (Transition) object;
    String specification = transition.getSpecification() != null ? " (" + transition.getSpecification() + ")" : "";
    return getVertexName(transition.getSource()) + " -> " + getVertexName(transition.getTarget()) + specification;
}
Also used : Transition(org.yakindu.sct.model.sgraph.Transition)

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