use of com.rockwellcollins.atc.agree.agree.NamedSpecStatement in project AGREE by loonwerks.
the class AgreeValidator method checkNoDuplicateIdInSpec.
@Check(CheckType.NORMAL)
public void checkNoDuplicateIdInSpec(AadlPackage toppkg) {
// namedSpecs associates an agree spec ID with all the agree specs that have that ID
HashMultimap<String, NamedSpecStatement> namedSpecs = HashMultimap.create();
// Get the set of packages referenced in model
Set<AadlPackage> pkgs = new HashSet<>();
getPackageDependencies(toppkg, pkgs);
for (AadlPackage pkg : pkgs) {
// Get the list of agree specs in each package
List<NamedSpecStatement> specs = getNamedSpecStatements(pkg);
for (NamedSpecStatement spec : specs) {
String id = spec.getName();
if (id != null) {
namedSpecs.put(id, spec);
}
}
}
// Get the agree specs in the current package
List<NamedSpecStatement> specs = getNamedSpecStatements(toppkg);
Iterator<NamedSpecStatement> i = specs.iterator();
while (i.hasNext()) {
NamedSpecStatement spec = i.next();
String id = spec.getName();
// If the current spec name is associated with multiple agree specs, we've found a duplicate
if (namedSpecs.get(id).size() > 1) {
Iterator<NamedSpecStatement> ii = namedSpecs.get(id).iterator();
while (ii.hasNext()) {
String pkgName = AadlUtil.getContainingPackage(ii.next()).getName();
// // If the specs are from the same package, the error will be generated from the
// // NamedElement check.
// if (!pkgName.contentEquals(AadlUtil.getContainingPackage(spec).getName())) {
error("Duplicate AGREE property ID in package " + pkgName, spec, Aadl2Package.eINSTANCE.getNamedElement_Name());
// }
}
namedSpecs.removeAll(id);
}
}
}
use of com.rockwellcollins.atc.agree.agree.NamedSpecStatement in project AGREE by loonwerks.
the class AgreeValidator method checkNameOverlap.
@Check(CheckType.FAST)
public void checkNameOverlap(AgreeContract contract) {
Set<SynchStatement> syncs = new HashSet<>();
Set<InitialStatement> inits = new HashSet<>();
List<ConnectionStatement> conns = new ArrayList<>();
// check that there are zero or more synchrony statements
for (SpecStatement spec : contract.getSpecs()) {
if (spec instanceof SynchStatement) {
syncs.add((SynchStatement) spec);
} else if (spec instanceof CalenStatement) {
syncs.add((CalenStatement) spec);
} else if (spec instanceof InitialStatement) {
inits.add((InitialStatement) spec);
} else if (spec instanceof ConnectionStatement) {
conns.add((ConnectionStatement) spec);
}
}
if (syncs.size() > 1) {
for (SynchStatement sync : syncs) {
error(sync, "Multiple synchrony or calender statements in a single contract");
}
}
if (inits.size() > 1) {
for (InitialStatement init : inits) {
error(init, "Multiple initially statements in a single contract");
}
}
for (int i = 0; i < conns.size(); i++) {
ConnectionStatement connStat0 = conns.get(i);
NamedElement conn0 = connStat0.getConn();
for (int j = i + 1; j < conns.size(); j++) {
ConnectionStatement connStat1 = conns.get(j);
NamedElement conn1 = connStat1.getConn();
if (conn0 == null || conn1 == null) {
break;
}
if (conn0.equals(conn1)) {
error(connStat0, "Multiple connection overrides for connection: '" + conn0.getName() + "'");
error(connStat1, "Multiple connection overrides for connection: '" + conn1.getName() + "'");
}
}
}
ComponentImplementation ci = EcoreUtil2.getContainerOfType(contract, ComponentImplementation.class);
if (ci == null) {
return;
}
Set<String> parentNames = getParentNames(ci);
for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ci, AgreeSubclause.class)) {
List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
for (NamedElement e : es) {
if (!(e.eContainer() instanceof NodeDef || e instanceof NamedSpecStatement)) {
// ignore elements in node defs
if (parentNames.contains(e.getName())) {
// =======
// if (!(e.eContainer() instanceof NodeDefExpr)) { // ignore elements in node defs
// if (e.getName() != null && parentNames.contains(e.getName())) {
// >>>>>>> origin/develop
error(e, e.getName() + " already defined in component type contract");
}
}
}
}
}
use of com.rockwellcollins.atc.agree.agree.NamedSpecStatement in project AGREE by loonwerks.
the class AgreeValidator method getParentNames.
private Set<String> getParentNames(ComponentImplementation ci) {
Set<String> result = new HashSet<>();
ComponentType ct = ci.getType();
for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ct, AgreeSubclause.class)) {
List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
for (NamedElement e : es) {
if (!(e.eContainer() instanceof NodeDef || e.eContainer() instanceof LinearizationDef || e.eContainer() instanceof RecordDef || e instanceof NamedSpecStatement)) {
result.add(e.getName());
}
}
}
return result;
}
Aggregations