Search in sources :

Example 1 with ReactionProperty

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

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

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

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

the class STextValidationModelUtils method getExitSpecSortedTransitions.

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

Example 5 with ReactionProperty

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

the class StextResource method serializeReaction.

private String serializeReaction(Reaction reaction) {
    StringBuilder builder = new StringBuilder();
    builder.append(serialize(reaction.getTrigger()));
    if (reaction.getEffect() != null) {
        builder.append(" / ");
        builder.append(serialize(reaction.getEffect()));
    }
    if (reaction.getProperties().size() > 0) {
        builder.append(" # ");
        for (ReactionProperty property : reaction.getProperties()) {
            builder.append(serialize(property));
        }
    }
    return builder.toString();
}
Also used : ReactionProperty(org.yakindu.sct.model.sgraph.ReactionProperty)

Aggregations

ReactionProperty (org.yakindu.sct.model.sgraph.ReactionProperty)8 Transition (org.yakindu.sct.model.sgraph.Transition)4 EntryPointSpec (org.yakindu.sct.model.stext.stext.EntryPointSpec)4 List (java.util.List)3 ExitPointSpec (org.yakindu.sct.model.stext.stext.ExitPointSpec)3 ArrayList (java.util.ArrayList)2 Check (org.eclipse.xtext.validation.Check)2 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