use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeUtils method containsTransitiveAgreeAnnex.
public static boolean containsTransitiveAgreeAnnex(ComponentInstance compInst, boolean isMonolithic) {
Subcomponent subComp = compInst.getSubcomponent();
if (!isMonolithic) {
return liftedTypeContainsAgreeAnnex(subComp.getComponentImplementation()) || typeContainsAgreeAnnex(subComp);
}
if (containsAgreeAnnex(subComp)) {
return true;
}
EList<ComponentInstance> transitiveSubs = compInst.getAllComponentInstances();
for (ComponentInstance transInst : transitiveSubs) {
if (AgreeUtils.containsAgreeAnnex(transInst.getSubcomponent())) {
return true;
}
}
return false;
}
use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method getArgNames.
private List<NamedElement> getArgNames(DoubleDotRef recType) {
NamedElement rec = recType.getElm();
// =======
// private List<NamedElement> getArgNames(DoubleDotRef recId) {
//
// NamedElement rec = recId.getElm();
// >>>>>>> origin/develop
List<NamedElement> names = new ArrayList<>();
if (rec instanceof RecordDef) {
RecordDef recDef = (RecordDef) rec;
for (Arg arg : recDef.getArgs()) {
names.add(arg);
}
} else if (rec instanceof DataImplementation) {
DataImplementation dataImpl = (DataImplementation) rec;
for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
names.add(sub);
}
} else {
error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
}
return names;
}
use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method checkNamedElement.
@Check(CheckType.FAST)
public void checkNamedElement(NamedElement namedEl) {
// check for namespace collision in component types of component
// implementations
// and for collisions between subcomponent and feature names
EObject container = namedEl.eContainer();
if (container == null) {
return;
}
if (container instanceof RecordDef || container instanceof NodeDef) {
// TODO: perhaps we can ignore all arguments?
return;
}
while (!(container instanceof AadlPackage || container instanceof ComponentImplementation || container instanceof ComponentType)) {
container = container.eContainer();
}
ComponentImplementation compImpl = null;
ComponentType type = null;
if (container instanceof ComponentImplementation) {
compImpl = (ComponentImplementation) container;
type = compImpl.getType();
checkDupNames(namedEl, type, compImpl);
} else if (container instanceof ComponentType) {
type = (ComponentType) container;
}
if (type != null && (namedEl.getName() != null)) {
for (Feature feat : type.getAllFeatures()) {
if (namedEl.getName().equals(feat.getName())) {
error(feat, "Element of the same name ('" + namedEl.getName() + "') in AGREE Annex in '" + (compImpl == null ? type.getName() : compImpl.getName()) + "'");
error(namedEl, "Feature of the same name ('" + namedEl.getName() + "') in component type");
}
}
}
// check name space collision with enumerated types
}
use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method checkOrderStatement.
@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
Classifier container = order.getContainingClassifier();
if (container instanceof ComponentImplementation) {
ComponentImplementation compImpl = (ComponentImplementation) container;
for (int index = 0; index < order.getComps().size(); ++index) {
NamedElement comp = order.getComps().get(index);
if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
}
}
List<NamedElement> notPresent = new ArrayList<>();
for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
boolean found = false;
for (NamedElement el : order.getComps()) {
if (el.equals(subcomp)) {
found = true;
break;
}
}
if (!found) {
notPresent.add(subcomp);
}
}
if (notPresent.size() != 0) {
String delim = "";
StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
for (NamedElement subcomp : notPresent) {
errorStr.append(delim);
errorStr.append(subcomp.getName());
delim = ", ";
}
error(order, errorStr.toString());
}
} else {
error(order, "Ordering statements can appear only in component implementations");
}
}
use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method checkLiftContract.
@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
Classifier comp = lcst.getContainingClassifier();
if (comp instanceof ComponentImplementation) {
ComponentType ct = ((ComponentImplementation) comp).getType();
List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (agreeAnnexes.size() > 0) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
}
List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
if (subcomps.size() == 1) {
Subcomponent subcomp = subcomps.get(0);
Classifier subCls = subcomp.getClassifier();
ComponentType subCt = null;
if (subCls instanceof ComponentImplementation) {
subCt = ((ComponentImplementation) subCls).getType();
} else if (subCls instanceof ComponentType) {
subCt = (ComponentType) subCls;
} else {
throw new RuntimeException();
}
{
Set<String> usedParentInPorts = new HashSet<>();
Set<String> usedParentOutPorts = new HashSet<>();
Set<String> usedChildInPorts = new HashSet<>();
Set<String> usedChildOutPorts = new HashSet<>();
EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
{
NamedElement sourceNe = conn.getSource().getConnectionEnd();
if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedChildOutPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
}
usedChildOutPorts.add(sourceNe.getName());
}
if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
if (usedParentInPorts.contains(sourceNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
}
usedParentInPorts.add(sourceNe.getName());
}
}
{
NamedElement destNe = conn.getDestination().getConnectionEnd();
if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedChildInPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
}
usedChildInPorts.add(destNe.getName());
}
if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
if (usedParentOutPorts.contains(destNe.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
}
usedParentOutPorts.add(destNe.getName());
}
}
}
for (Feature feat : comp.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedParentInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
}
} else {
if (!usedParentOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
}
}
}
for (Feature feat : subCt.getAllFeatures()) {
boolean isIn = false;
if (feat instanceof DataPort) {
isIn = ((DataPort) feat).isIn();
} else if (feat instanceof EventDataPort) {
isIn = ((EventDataPort) feat).isIn();
} else if (feat instanceof EventPort) {
isIn = ((EventPort) feat).isIn();
}
if (isIn) {
if (!usedChildInPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
}
} else {
if (!usedChildOutPorts.contains(feat.getName())) {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
}
}
}
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
}
} else {
error(lcst, "'lift contract;' statement is not allowed in component interface.");
}
}
Aggregations