Search in sources :

Example 1 with Choice

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

the class SGraphNameProvider method qualifiedName.

public QualifiedName qualifiedName(Choice ele) {
    // first get order number of choice node
    List<Vertex> choiceList = new ArrayList<Vertex>();
    choiceList.addAll(Collections2.filter(((Region) ele.eContainer()).getVertices(), new Predicate<Vertex>() {

        public boolean apply(Vertex input) {
            return input instanceof Choice;
        }
    }));
    int index = choiceList.indexOf(ele);
    QualifiedName qualifiedNameFromConverter = QualifiedName.create(_CHOICE_NAME + index);
    return getParentQualifiedName(ele, qualifiedNameFromConverter);
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Choice(org.yakindu.sct.model.sgraph.Choice) QualifiedName(org.eclipse.xtext.naming.QualifiedName) ArrayList(java.util.ArrayList) Region(org.yakindu.sct.model.sgraph.Region) Predicate(com.google.common.base.Predicate)

Example 2 with Choice

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

the class SGraphJavaValidationTest method vertexNotReachable_AcceptThroughSubchoice.

/**
 * A transition to a sub choice is considered implies reachability.
 */
@Test
public void vertexNotReachable_AcceptThroughSubchoice() {
    prepareStateTest();
    State stateA = factory.createState();
    Region subRegion = factory.createRegion();
    state.getRegions().add(subRegion);
    State stateC = factory.createState();
    subRegion.getVertices().add(stateC);
    Choice choice = factory.createChoice();
    subRegion.getVertices().add(choice);
    Transition t1 = factory.createTransition();
    t1.setSource(stateA);
    t1.setTarget(choice);
    Transition t2 = factory.createTransition();
    t2.setSource(choice);
    t2.setTarget(stateC);
    validate(state);
    assertNoIssues(diagnostics);
}
Also used : Choice(org.yakindu.sct.model.sgraph.Choice) FinalState(org.yakindu.sct.model.sgraph.FinalState) State(org.yakindu.sct.model.sgraph.State) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) Test(org.junit.Test)

Example 3 with Choice

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

the class SGraphJavaValidationTest method vertexNotReachable_FailOnExternalPseudoPath.

/**
 * If an incoming transitions is part of an external transition path that
 * only consists of pseudo states and only has state predecessors within the
 * state then the state is not reachable and the validation must fail with
 * an error.
 */
@Test
public void vertexNotReachable_FailOnExternalPseudoPath() {
    prepareStateTest();
    Choice choice = factory.createChoice();
    region.getVertices().add(choice);
    createTransition(state, choice);
    createTransition(choice, state);
    validate(state);
    assertIssue(diagnostics, ISSUE_NODE_NOT_REACHABLE);
}
Also used : Choice(org.yakindu.sct.model.sgraph.Choice) Test(org.junit.Test)

Example 4 with Choice

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

the class SGraphJavaValidationTest method vertexNotReachable_FailOnExternalPseudoPathToSubstate.

/**
 * If an incoming transitions is part of an external transition path to an
 * internal state that only consists of pseudo states and only has state
 * predecessors within the state then the state is not reachable and the
 * validation must fail with an error.
 */
@Test
public void vertexNotReachable_FailOnExternalPseudoPathToSubstate() {
    prepareStateTest();
    Region subRegion = factory.createRegion();
    state.getRegions().add(subRegion);
    State stateA = factory.createState();
    subRegion.getVertices().add(stateA);
    Choice choice = factory.createChoice();
    region.getVertices().add(choice);
    createTransition(stateA, choice);
    createTransition(choice, stateA);
    validate(state);
    assertIssue(diagnostics, ISSUE_NODE_NOT_REACHABLE);
}
Also used : Choice(org.yakindu.sct.model.sgraph.Choice) FinalState(org.yakindu.sct.model.sgraph.FinalState) State(org.yakindu.sct.model.sgraph.State) Region(org.yakindu.sct.model.sgraph.Region) Test(org.junit.Test)

Example 5 with Choice

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

the class SGraphJavaValidationTest method choiceWithoutOutgoingTransition.

/**
 * A choice must have at least one outgoing transition
 */
@Test
public void choiceWithoutOutgoingTransition() {
    statechart = factory.createStatechart();
    Region region = factory.createRegion();
    statechart.getRegions().add(region);
    Choice choice = factory.createChoice();
    region.getVertices().add(choice);
    State state = factory.createState();
    region.getVertices().add(state);
    createTransition(state, choice);
    assertFalse(validator.validate(choice, diagnostics, new HashMap<Object, Object>()));
    assertIssueCount(diagnostics, 1);
    assertError(diagnostics, ISSUE_CHOICE_WITHOUT_OUTGOING_TRANSITION);
}
Also used : Choice(org.yakindu.sct.model.sgraph.Choice) HashMap(java.util.HashMap) FinalState(org.yakindu.sct.model.sgraph.FinalState) State(org.yakindu.sct.model.sgraph.State) Region(org.yakindu.sct.model.sgraph.Region) Test(org.junit.Test)

Aggregations

Choice (org.yakindu.sct.model.sgraph.Choice)5 Test (org.junit.Test)4 Region (org.yakindu.sct.model.sgraph.Region)4 FinalState (org.yakindu.sct.model.sgraph.FinalState)3 State (org.yakindu.sct.model.sgraph.State)3 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 QualifiedName (org.eclipse.xtext.naming.QualifiedName)1 Transition (org.yakindu.sct.model.sgraph.Transition)1 Vertex (org.yakindu.sct.model.sgraph.Vertex)1