use of org.yakindu.sct.model.sgraph.Region 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.Region in project statecharts by Yakindu.
the class STextValidationModelUtils method getRegionsWithoutDefaultExit.
/**
* If a {@link Region} contains no 'default' named {@link exit} it is added
* as key to a map with a list of all exits of the region.
*
* @param elements
* - a list with {@link Region} elements.
* @return a map with a region (key) which contains no default {@link exit}
* and a list of all {@link exit} elements of the {@link Region}
* (value).
*/
public static Map<Region, List<Exit>> getRegionsWithoutDefaultExit(List<Region> elements) {
Map<Region, List<Exit>> regions = new HashMap<Region, List<Exit>>();
for (Region region : elements) {
boolean hasDefaultExit = false;
final List<Exit> exits = getExits(region.eContents());
if (!exits.isEmpty()) {
for (Exit exit : exits) {
if (isDefault(exit)) {
hasDefaultExit = true;
break;
}
}
} else {
hasDefaultExit = true;
}
if (!hasDefaultExit) {
regions.put(region, exits);
}
}
return regions;
}
use of org.yakindu.sct.model.sgraph.Region in project statecharts by Yakindu.
the class SGraphNameProvider method qualifiedName.
public QualifiedName qualifiedName(Choice ele) {
// first get order number of choice node
List<Vertex> choiceList = new ArrayList<Vertex>();
choiceList.addAll(Collections2.filter(((Region) ele.eContainer()).getVertices(), new Predicate<Vertex>() {
public boolean apply(Vertex input) {
return input instanceof Choice;
}
}));
int index = choiceList.indexOf(ele);
QualifiedName qualifiedNameFromConverter = QualifiedName.create(_CHOICE_NAME + index);
return getParentQualifiedName(ele, qualifiedNameFromConverter);
}
use of org.yakindu.sct.model.sgraph.Region in project statecharts by Yakindu.
the class SGraphNameProvider method qualifiedName.
public QualifiedName qualifiedName(Synchronization ele) {
QualifiedName qualifiedNameFromConverter = null;
if (!Strings.isEmpty(ele.getName())) {
qualifiedNameFromConverter = QualifiedName.create(ele.getName());
} else {
LinkedList<Synchronization> list = new LinkedList<Synchronization>();
Iterables.addAll(list, Iterables.filter(((Region) ele.eContainer()).getVertices(), Synchronization.class));
qualifiedNameFromConverter = QualifiedName.create(_SYNC_NAME + list.indexOf(ele));
}
return getParentQualifiedName(ele, qualifiedNameFromConverter);
}
use of org.yakindu.sct.model.sgraph.Region 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