@Check(CheckType.FAST) public void checkTransitionPropertySpec(final Transition transition) { for (ReactionProperty property : transition.getProperties()) { if (property instanceof EntryPointSpec) { if (transition.getTarget() instanceof org.yakindu.sct.model.sgraph.State) { org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) transition.getTarget(); if (!state.isComposite()) { warning(TRANSITION_ENTRY_SPEC_NOT_COMPOSITE, transition, null, -1); } } } else if (property instanceof ExitPointSpec) { final ExitPointSpec exitPointSpec = (ExitPointSpec) property; if (transition.getSource() instanceof org.yakindu.sct.model.sgraph.State) { org.yakindu.sct.model.sgraph.State state = (org.yakindu.sct.model.sgraph.State) transition.getSource(); if (!state.isComposite()) { warning(TRANSITION_EXIT_SPEC_NOT_COMPOSITE, transition, null, -1); } else { // Validate an exit point is continued on one transition // only. for (Transition t : state.getOutgoingTransitions()) { if (transition != t && STextValidationModelUtils.isNamedExitTransition( t, exitPointSpec.getExitpoint())) { warning(TRANSITION_EXIT_SPEC_ON_MULTIPLE_SIBLINGS, transition, null, -1); } } // Validate the state has minimally one named exit // region boolean hasExit = false; Iterator<Region> regionIter = state.getRegions().iterator(); while (regionIter.hasNext() && !hasExit) { Iterator<Exit> exitIter = STextValidationModelUtils.getExits(regionIter.next().eContents()).iterator(); while (exitIter.hasNext() && !hasExit) { Exit exit = exitIter.next(); hasExit = exitPointSpec.getExitpoint().equals(exit.getName()); } } if (!hasExit) { error(TRANSITION_NOT_EXISTING_NAMED_EXIT_POINT, transition, null, -1); } } } } } }
protected void createExitPoint(Edge edge, Diagram subdiagram) { Transition transition = (Transition) edge.getElement(); // create semantic exit point Region exitPointContainer = getExitPointContainer(transition); Exit exitPoint = createSemanticExitPoint(transition); // create node for exit point View exitPointContainerView = helper.getViewForSemanticElement(exitPointContainer, subdiagram); View exitPointRegionCompartment = ViewUtil.getChildBySemanticHint(exitPointContainerView, SemanticHints.REGION_COMPARTMENT); Node exitNode = ViewService.createNode( exitPointRegionCompartment, exitPoint, SemanticHints.EXIT, preferencesHint); // re-wire existing transition to new exit point Vertex oldTarget = transition.getTarget(); transition.setTarget(exitPoint); ViewService.createEdge( edge.getSource(), exitNode, transition, SemanticHints.TRANSITION, preferencesHint); // create transition from selected state to former transition target Transition exitPointTransition = SGraphFactory.eINSTANCE.createTransition(); exitPointTransition.setSource((State) subdiagram.getElement()); exitPointTransition.setTarget(oldTarget); ViewService.createEdge( getContextObject(), edge.getTarget(), exitPointTransition, SemanticHints.TRANSITION, preferencesHint); addExitPointSpec(exitPointTransition, exitPoint); }
/** * Retrieves the target from an entry. TODO: validation of preconditions for entry targets e.g * every region needs an entry with appropriate target */ public State target(final Entry entry) { State _xifexpression = null; EList<Transition> _outgoingTransitions = entry == null ? (EList<Transition>) null : entry.getOutgoingTransitions(); boolean _notEquals = (!Objects.equal(_outgoingTransitions, null)); if (_notEquals) { State _xifexpression_1 = null; EList<Transition> _outgoingTransitions_1 = entry.getOutgoingTransitions(); int _size = _outgoingTransitions_1.size(); boolean _greaterThan = (_size > 0); if (_greaterThan) { State _xblockexpression = null; { EList<Transition> _outgoingTransitions_2 = entry.getOutgoingTransitions(); Transition _get = _outgoingTransitions_2.get(0); final Vertex target = _get.getTarget(); State _xifexpression_2 = null; if ((target instanceof State)) { _xifexpression_2 = ((State) target); } _xblockexpression = (_xifexpression_2); } _xifexpression_1 = _xblockexpression; } _xifexpression = _xifexpression_1; } return _xifexpression; }
protected String getEntryPointName(Transition transition) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("entry_"); stringBuilder.append(transition.getTarget().getName()); int index = transition.getSource().getOutgoingTransitions().indexOf(transition); stringBuilder.append(index); return stringBuilder.toString(); }
@Check public void orthogonalTransition(Transition transition) { Vertex source = transition.getSource(); Vertex target = transition.getTarget(); if ((source instanceof Synchronization) || (target instanceof Synchronization)) return; // ... the check does not apply. EObject commonAncestor = commonAncestor(source, target); if (commonAncestor instanceof CompositeElement) { error(ISSUE_TRANSITION_ORTHOGONAL, transition, null, -1); } }
@Check public void orthogonalSynchronizedTransition(Synchronization sync) { List<Transition> incoming = sync.getIncomingTransitions(); List<List<EObject>> inAncestorsList = new ArrayList<List<EObject>>(); for (Transition trans : incoming) { inAncestorsList.add(collectAncestors(trans.getSource(), new ArrayList<EObject>())); } List<Transition> outgoing = sync.getOutgoingTransitions(); List<List<EObject>> outAncestorsList = new ArrayList<List<EObject>>(); for (Transition trans : outgoing) { outAncestorsList.add(collectAncestors(trans.getTarget(), new ArrayList<EObject>())); } Set<Transition> inOrthogonal = new HashSet<Transition>(incoming); Set<Transition> outOrthogonal = new HashSet<Transition>(outgoing); for (int i = 0; i < incoming.size(); i++) { for (int j = 0; j < outgoing.size(); j++) { EObject commonAncestor = findCommonAncestor(inAncestorsList.get(i), outAncestorsList.get(j)); if (commonAncestor instanceof Region) { inOrthogonal.remove(incoming.get(i)); outOrthogonal.remove(outgoing.get(j)); } } } for (Transition trans : inOrthogonal) { error(ISSUE_SYNCHRONIZATION_SOURCE_STATES_NOT_WITHIN_SAME_PARENTSTATE, trans, null, -1); } for (Transition trans : outOrthogonal) { error(ISSUE_SYNCHRONIZATION_TARGET_STATES_NOT_WITHIN_SAME_PARENTSTATE, trans, null, -1); } }
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; }
private Region getEntryPointContainer(Transition transition) { // entry point container is the subdiagram's state's region which // contains the transition target EObject firstParentRegion = transition.getTarget().getParentRegion(); return getOutermostParentRegion(firstParentRegion); }
@Check(CheckType.FAST) public void initialEntryWithTransitionToContainer(Transition t) { if (t.getSource() instanceof Entry && !isChildOrSibling(t.getSource(), t.getTarget())) { error(ISSUE_INITIAL_ENTRY_WITH_TRANSITION_TO_CONTAINER, t, null, -1); } }