Search in sources :

Example 91 with Region

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

the class STextScopeProvider method getActiveStateNormalizer.

protected List<ImportNormalizer> getActiveStateNormalizer(EObject context) {
    List<ImportNormalizer> normalizer = Lists.newArrayList();
    SpecificationElement contextElement = getContextElement(context);
    if (contextElement == null)
        return normalizer;
    Region containingRegion = EcoreUtil2.getContainerOfType(contextElement, Region.class);
    if (containingRegion == null)
        return normalizer;
    QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(containingRegion);
    while (!fullyQualifiedName.getSegments().isEmpty()) {
        normalizer.add(new ImportNormalizer(fullyQualifiedName, true, false));
        fullyQualifiedName = fullyQualifiedName.skipLast(1);
    }
    return normalizer;
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) SpecificationElement(org.yakindu.sct.model.sgraph.SpecificationElement) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Region(org.yakindu.sct.model.sgraph.Region)

Example 92 with Region

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

the class STextValidationModelUtils method getRegionsWithoutDefaultEntry.

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

Example 93 with Region

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

the class SGraphJavaValidator method vertexNotReachable.

@Check(CheckType.FAST)
public void vertexNotReachable(final Vertex vertex) {
    if (!(vertex instanceof Entry)) {
        final Set<Object> stateScopeSet = new HashSet<>();
        for (EObject obj : EcoreUtil2.eAllContents(vertex)) {
            stateScopeSet.add(obj);
        }
        stateScopeSet.add(vertex);
        final List<Object> externalPredecessors = new ArrayList<>();
        DFS dfs = new DFS() {

            @Override
            public Iterator<Object> getElementLinks(Object element) {
                List<Object> elements = new ArrayList<>();
                if (element instanceof org.yakindu.sct.model.sgraph.State) {
                    if (!stateScopeSet.contains(element)) {
                        externalPredecessors.add(element);
                    } else {
                        elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getRegions());
                        elements.addAll(((org.yakindu.sct.model.sgraph.State) element).getIncomingTransitions());
                    }
                } else if (element instanceof Region) {
                    elements.addAll(((Region) element).getVertices());
                } else if (element instanceof Entry) {
                    if (!stateScopeSet.contains(element)) {
                        externalPredecessors.add(element);
                    } else {
                        elements.addAll(((Entry) element).getIncomingTransitions());
                    }
                } else if (element instanceof Vertex) {
                    elements.addAll(((Vertex) element).getIncomingTransitions());
                } else if (element instanceof Transition) {
                    elements.add(((Transition) element).getSource());
                }
                return elements.iterator();
            }
        };
        dfs.perform(vertex);
        if (externalPredecessors.size() == 0) {
            error(ISSUE_NODE_NOT_REACHABLE, vertex, 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) EObject(org.eclipse.emf.ecore.EObject) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) EObject(org.eclipse.emf.ecore.EObject) HashSet(java.util.HashSet) 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