Search in sources :

Example 1 with Entry

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

the class ExtractSubdiagramRefactoring method createEntryPoint.

protected void createEntryPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    Region entryPointContainer = getEntryPointContainer(transition);
    Entry entryPoint = createSemanticEntryPoint(transition);
    // re-wire old transition to targeting the selected state
    transition.setTarget((State) subdiagram.getElement());
    View oldTarget = edge.getTarget();
    edge.setTarget(getContextObject());
    // create node for entry point
    View entryPointContainerView = helper.getViewForSemanticElement(entryPointContainer, subdiagram);
    View entryPointRegionCompartment = ViewUtil.getChildBySemanticHint(entryPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node entryNode = ViewService.createNode(entryPointRegionCompartment, entryPoint, SemanticHints.ENTRY, preferencesHint);
    ViewService.createEdge(entryNode, oldTarget, entryPoint.getOutgoingTransitions().get(0), SemanticHints.TRANSITION, preferencesHint);
    addEntryPointSpec(transition, entryPoint);
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) Node(org.eclipse.gmf.runtime.notation.Node) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region) View(org.eclipse.gmf.runtime.notation.View)

Example 2 with Entry

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

the class ExtractSubdiagramRefactoring method createSemanticEntryPoint.

protected Entry createSemanticEntryPoint(Transition transition) {
    Region entryPointTarget = getEntryPointContainer(transition);
    String name = getEntryPointName(transition);
    Entry entryPoint = null;
    Iterator<Vertex> iterator = entryPointTarget.getVertices().iterator();
    while (iterator.hasNext()) {
        Vertex next = iterator.next();
        if (next instanceof Entry) {
            Entry current = (Entry) next;
            if (name.equals(current.getName())) {
                // Do nothing, there already exists an entry point
                return current;
            }
        }
    }
    entryPoint = SGraphFactory.eINSTANCE.createEntry();
    entryPoint.setName(name);
    entryPointTarget.getVertices().add(entryPoint);
    Transition entryPointTransition = SGraphFactory.eINSTANCE.createTransition();
    entryPointTransition.setSource(entryPoint);
    entryPointTransition.setTarget(transition.getTarget());
    return entryPoint;
}
Also used : Vertex(org.yakindu.sct.model.sgraph.Vertex) Entry(org.yakindu.sct.model.sgraph.Entry) Transition(org.yakindu.sct.model.sgraph.Transition) Region(org.yakindu.sct.model.sgraph.Region)

Example 3 with Entry

use of org.yakindu.sct.model.sgraph.Entry 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)

Example 4 with Entry

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

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

Entry (org.yakindu.sct.model.sgraph.Entry)47 Test (org.junit.Test)38 Region (org.yakindu.sct.model.sgraph.Region)38 State (org.yakindu.sct.model.sgraph.State)30 Statechart (org.yakindu.sct.model.sgraph.Statechart)30 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)29 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)29 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)28 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)27 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)27 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)26 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)25 Sequence (org.yakindu.sct.model.sexec.Sequence)22 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)22 EnterState (org.yakindu.sct.model.sexec.EnterState)13 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)13 Reaction (org.yakindu.sct.model.sexec.Reaction)10 Transition (org.yakindu.sct.model.sgraph.Transition)10