Search in sources :

Example 1 with EntryPointSpec

use of org.yakindu.sct.model.stext.stext.EntryPointSpec in project statecharts by Yakindu.

the class ExtractSubdiagramRefactoring method addEntryPointSpec.

private void addEntryPointSpec(Transition transition, Entry entryPoint) {
    EList<ReactionProperty> properties = transition.getProperties();
    EntryPointSpec entryPointSpec = StextFactory.eINSTANCE.createEntryPointSpec();
    // A transition can only have one entry point so alter the existing
    for (ReactionProperty reactionProperty : properties) {
        if (reactionProperty instanceof EntryPointSpec) {
            entryPointSpec = (EntryPointSpec) reactionProperty;
        }
    }
    entryPointSpec.setEntrypoint(entryPoint.getName());
    properties.add(entryPointSpec);
}
Also used : EntryPointSpec(org.yakindu.sct.model.stext.stext.EntryPointSpec) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty)

Example 2 with EntryPointSpec

use of org.yakindu.sct.model.stext.stext.EntryPointSpec 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 3 with EntryPointSpec

use of org.yakindu.sct.model.stext.stext.EntryPointSpec 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 4 with EntryPointSpec

use of org.yakindu.sct.model.stext.stext.EntryPointSpec in project statecharts by Yakindu.

the class STextValidationModelUtils method getEntrySpecSortedTransitions.

/**
 * Sorts the given elements in transition without and with
 * {@link EntryPointSpec}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 EntryPointSpec}s. The
 *         second index contains a list of the transitions with
 *         {@link EntryPointSpec}s.
 */
public static List<Transition>[] getEntrySpecSortedTransitions(List<Transition> elements) {
    @SuppressWarnings("unchecked") final List<Transition>[] transitions = new ArrayList[2];
    // first list contains Transitions without entry spec
    transitions[0] = new ArrayList<Transition>();
    // second list contains Transitions with entry spec
    transitions[1] = new ArrayList<Transition>();
    for (Transition transition : elements) {
        boolean hasEntrySpec = false;
        for (ReactionProperty property : transition.getProperties()) {
            if (property instanceof EntryPointSpec) {
                transitions[1].add(transition);
                hasEntrySpec = true;
                break;
            }
        }
        if (!hasEntrySpec) {
            transitions[0].add(transition);
        }
    }
    return transitions;
}
Also used : ArrayList(java.util.ArrayList) Transition(org.yakindu.sct.model.sgraph.Transition) ArrayList(java.util.ArrayList) List(java.util.List) EntryPointSpec(org.yakindu.sct.model.stext.stext.EntryPointSpec) ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty)

Aggregations

ReactionProperty (org.yakindu.sct.model.sgraph.ReactionProperty)4 EntryPointSpec (org.yakindu.sct.model.stext.stext.EntryPointSpec)4 Transition (org.yakindu.sct.model.sgraph.Transition)3 List (java.util.List)2 Check (org.eclipse.xtext.validation.Check)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 EList (org.eclipse.emf.common.util.EList)1 Entry (org.yakindu.sct.model.sgraph.Entry)1 Region (org.yakindu.sct.model.sgraph.Region)1