Search in sources :

Example 6 with Region

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

the class STextJavaValidator method checkTopLeveEntryIsDefaultEntry.

@Check(CheckType.NORMAL)
public void checkTopLeveEntryIsDefaultEntry(final Entry entry) {
    Region parentRegion = entry.getParentRegion();
    // 1. check if is toplevel
    if (isTopLevelRegion(parentRegion)) {
        boolean isDefaultEntry = STextValidationModelUtils.isDefault(entry);
        // 2. check if is default entry
        if (!isDefaultEntry) {
            Map<Region, List<Entry>> regionsWithoutDefaultEntry = STextValidationModelUtils.getRegionsWithoutDefaultEntry(Lists.newArrayList(parentRegion));
            List<Entry> list = regionsWithoutDefaultEntry.get(parentRegion);
            if (list != null)
                error(TOP_LEVEL_REGION_ENTRY_HAVE_TO_BE_A_DEFAULT_ENTRY, entry, SGraphPackage.Literals.ENTRY__KIND, -1);
            else
                warning(TOP_LEVEL_REGION_ENTRY_HAVE_TO_BE_A_DEFAULT_ENTRY, entry, SGraphPackage.Literals.ENTRY__KIND, -1);
        }
    }
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) Region(org.yakindu.sct.model.sgraph.Region) List(java.util.List) LinkedList(java.util.LinkedList) EList(org.eclipse.emf.common.util.EList) Check(org.eclipse.xtext.validation.Check)

Example 7 with Region

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

the class STextValidationModelUtils method getRegionsWithoutDefaultExit.

/**
 * If a {@link Region} contains no 'default' named {@link exit} it is added
 * as key to a map with a list of all exits of the region.
 *
 * @param elements
 *            - a list with {@link Region} elements.
 * @return a map with a region (key) which contains no default {@link exit}
 *         and a list of all {@link exit} elements of the {@link Region}
 *         (value).
 */
public static Map<Region, List<Exit>> getRegionsWithoutDefaultExit(List<Region> elements) {
    Map<Region, List<Exit>> regions = new HashMap<Region, List<Exit>>();
    for (Region region : elements) {
        boolean hasDefaultExit = false;
        final List<Exit> exits = getExits(region.eContents());
        if (!exits.isEmpty()) {
            for (Exit exit : exits) {
                if (isDefault(exit)) {
                    hasDefaultExit = true;
                    break;
                }
            }
        } else {
            hasDefaultExit = true;
        }
        if (!hasDefaultExit) {
            regions.put(region, exits);
        }
    }
    return regions;
}
Also used : HashMap(java.util.HashMap) Region(org.yakindu.sct.model.sgraph.Region) ArrayList(java.util.ArrayList) List(java.util.List) Exit(org.yakindu.sct.model.sgraph.Exit)

Example 8 with Region

use of org.yakindu.sct.model.sgraph.Region 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 9 with Region

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

the class SGraphNameProvider method qualifiedName.

public QualifiedName qualifiedName(Synchronization ele) {
    QualifiedName qualifiedNameFromConverter = null;
    if (!Strings.isEmpty(ele.getName())) {
        qualifiedNameFromConverter = QualifiedName.create(ele.getName());
    } else {
        LinkedList<Synchronization> list = new LinkedList<Synchronization>();
        Iterables.addAll(list, Iterables.filter(((Region) ele.eContainer()).getVertices(), Synchronization.class));
        qualifiedNameFromConverter = QualifiedName.create(_SYNC_NAME + list.indexOf(ele));
    }
    return getParentQualifiedName(ele, qualifiedNameFromConverter);
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) Region(org.yakindu.sct.model.sgraph.Region) Synchronization(org.yakindu.sct.model.sgraph.Synchronization) LinkedList(java.util.LinkedList)

Example 10 with Region

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

the class SGraphJavaValidator method regionCantBeEnteredUsingShallowHistory.

/**
 * Checks if all composite states that are siblings of a shallow history can
 * enter their regions.
 *
 * @param e
 */
@Check(CheckType.FAST)
public void regionCantBeEnteredUsingShallowHistory(Entry e) {
    if (e.getKind() == EntryKind.SHALLOW_HISTORY) {
        // get all regions off all sibling states
        List<Region> regions = new ArrayList<>();
        for (Vertex v : e.getParentRegion().getVertices()) {
            if (v instanceof org.yakindu.sct.model.sgraph.State) {
                org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) v;
                regions.addAll(state.getRegions());
            }
        }
        // check each region
        for (Region r : regions) {
            // first determine if the region contains a default entry
            Entry defaultEntry = null;
            for (Vertex v : r.getVertices()) {
                if (v instanceof Entry) {
                    String name = v.getName().trim().toLowerCase();
                    if (name != null || "".equals(name) || "default".equals(name)) {
                        defaultEntry = (Entry) v;
                        break;
                    }
                }
            }
            // now check error conditions
            if (defaultEntry == null) {
                error(ISSUE_REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NO_DEFAULT_ENTRY, r, null, -1);
            } else if (defaultEntry.getOutgoingTransitions().size() != 1) {
                error(ISSUE_REGION_CANT_BE_ENTERED_USING_SHALLOW_HISTORY_NON_CONNECTED_DEFAULT_ENTRY, r, null, -1);
            }
        }
    }
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) ArrayList(java.util.ArrayList) Entry(org.yakindu.sct.model.sgraph.Entry) FinalState(org.yakindu.sct.model.sgraph.FinalState) Region(org.yakindu.sct.model.sgraph.Region) Check(org.eclipse.xtext.validation.Check)

Aggregations

Region (org.yakindu.sct.model.sgraph.Region)93 Test (org.junit.Test)71 State (org.yakindu.sct.model.sgraph.State)63 Statechart (org.yakindu.sct.model.sgraph.Statechart)59 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)57 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)57 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)53 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)51 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)48 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)48 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)47 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)47 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)41 Entry (org.yakindu.sct.model.sgraph.Entry)38 Sequence (org.yakindu.sct.model.sexec.Sequence)36 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 Transition (org.yakindu.sct.model.sgraph.Transition)26 FinalState (org.yakindu.sct.model.sgraph.FinalState)25 Reaction (org.yakindu.sct.model.sexec.Reaction)22