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);
}
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;
}
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);
}
}
}
}
}
}
}
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);
}
}
}
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);
}
}
}
}
Aggregations