use of org.osate.aadl2.Feature 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.");
}
}
use of org.osate.aadl2.Feature in project AGREE by loonwerks.
the class AgreeValidator method getFieldTypes.
private Map<String, TypeDef> getFieldTypes(DoubleDotRef recType) {
NamedElement rec = recType.getElm();
Map<String, TypeDef> typeMap = new HashMap<>();
if (rec instanceof RecordDef) {
RecordDef recDef = (RecordDef) rec;
for (Arg arg : recDef.getArgs()) {
typeMap.put(arg.getName(), AgreeTypeSystem.typeDefFromType(arg.getType()));
}
} else if (rec instanceof DataImplementation) {
DataImplementation dataImpl = (DataImplementation) rec;
for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
typeMap.put(sub.getName(), AgreeTypeSystem.typeDefFromClassifier((sub.getClassifier())));
}
} else {
error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
}
return typeMap;
}
use of org.osate.aadl2.Feature in project AGREE by loonwerks.
the class AgreeValidator method checkRecordDefExpr.
// =======
// // private List<AgreeType> getArgTypes(NestedDotID recId){
// //
// // NamedElement rec = getFinalNestId(recId);
// // List<AgreeType> types = new ArrayList<AgreeType>();
// //
// // if(rec instanceof RecordDefExpr){
// // RecordDefExpr recDef = (RecordDefExpr)rec;
// // for(Arg arg : recDef.getArgs()){
// // types.add(getAgreeType(arg.getType()));
// // }
// // }else if(rec instanceof FeatureGroupType){
// // FeatureGroupType featGroup = (FeatureGroupType)rec;
// // for(Feature feat : featGroup.getAllFeatures()){
// // types.add(getAgreeType(feat));
// // }
// // }
// //
// // return types;
// // }
//
// private void dataImplCycleCheck(NestedDotID dataID) {
// NamedElement finalId = dataID.getBase();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
// private void dataImplCycleCheck(DoubleDotRef dataID) {
// NamedElement finalId = dataID.getElm();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
//
// private void dataImplCycleCheck(DataImplementation dataImpl, EObject errorSource) {
// Set<DataImplementation> dataClosure = new HashSet<>();
// Set<DataImplementation> prevClosure = null;
//
// for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
// ComponentImplementation subImpl = sub.getComponentImplementation();
// if (subImpl != null) {
// dataClosure.add((DataImplementation) subImpl);
// }
// }
//
// do {
// prevClosure = new HashSet<>(dataClosure);
// for (DataImplementation subImpl : prevClosure) {
// if (subImpl == dataImpl) {
// error(errorSource, "The component implementation '" + dataImpl.getName()
// + "' has a cyclic definition. This cannot be reasoned about by AGREE.");
// break;
// }
// for (Subcomponent subSub : subImpl.getAllSubcomponents()) {
// ComponentImplementation subSubImpl = subSub.getComponentImplementation();
// if (subSubImpl != null) {
// dataClosure.add((DataImplementation) subSubImpl);
// }
// }
//
// }
//
// } while (!prevClosure.equals(dataClosure));
//
// }
// >>>>>>> origin/develop
@Check(CheckType.FAST)
public void checkRecordDefExpr(RecordDef recordDef) {
Set<RecordDef> recordClosure = new HashSet<>();
Set<RecordDef> prevClosure = null;
for (Arg arg : recordDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement finalId = ((DoubleDotRef) type).getElm();
if (finalId instanceof RecordDef) {
recordClosure.add((RecordDef) finalId);
}
}
}
do {
prevClosure = new HashSet<>(recordClosure);
for (RecordDef subRecDef : prevClosure) {
if (subRecDef == recordDef) {
error(recordDef, "The definition of type '" + recordDef.getName() + "' is involved in a cyclic definition");
break;
}
for (Arg arg : subRecDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement subFinalEl = ((DoubleDotRef) type).getElm();
if (subFinalEl instanceof RecordDef) {
recordClosure.add((RecordDef) subFinalEl);
// =======
// if (type instanceof RecordType) {
// DoubleDotRef subRecId = ((RecordType) type).getRecord();
// NamedElement subFinalEl = subRecId.getElm();
// if (subFinalEl instanceof RecordDefExpr) {
// recordClosure.add((RecordDefExpr) subFinalEl);
// >>>>>>> origin/develop
}
}
}
}
} while (!prevClosure.equals(recordClosure));
}
use of org.osate.aadl2.Feature in project osate2 by osate.
the class Aadl2InstanceUtil method getIncomingConnection.
/**
* find incoming connection that goes through the feature of the specified component instance
* @param ci Component instance
* @param fi Feature instance
* @return list of connection instances going through the feature
*/
public static EList<ConnectionInstance> getIncomingConnection(ComponentInstance ci, FeatureInstance fi) {
Feature f = fi.getFeature();
EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
// allEnclosingConnectionInstances();
Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
for (ConnectionInstance connectionInstance : it) {
ConnectionInstanceEnd dest = connectionInstance.getDestination();
ComponentInstance destci = dest.getContainingComponentInstance();
if (containedIn(destci, ci)) {
EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
for (ConnectionReference connectionReference : connreflist) {
ComponentInstance pci = connectionReference.getContext();
Connection conn = connectionReference.getConnection();
ConnectionEnd ce = conn.getAllSource();
if (pci == ci.getContainingComponentInstance() && ce == f) {
result.add(connectionInstance);
}
}
}
}
return result;
}
use of org.osate.aadl2.Feature in project osate2 by osate.
the class Aadl2InstanceUtil method getOutgoingConnection.
/**
* find outgoing connection that goes through the feature of the specified component instance
* @param ci Component instance
* @param fi Feature instance
* @return list of connection instances going through the feature
*/
public static EList<ConnectionInstance> getOutgoingConnection(ComponentInstance ci, FeatureInstance fi) {
Feature f = fi.getFeature();
EList<ConnectionInstance> result = new BasicEList<ConnectionInstance>();
// allEnclosingConnectionInstances();
Iterable<ConnectionInstance> it = ci.getSystemInstance().getAllConnectionInstances();
for (ConnectionInstance connectionInstance : it) {
ConnectionInstanceEnd src = connectionInstance.getSource();
ComponentInstance srcci = src.getContainingComponentInstance();
if (containedIn(srcci, ci)) {
EList<ConnectionReference> connreflist = connectionInstance.getConnectionReferences();
for (ConnectionReference connectionReference : connreflist) {
ComponentInstance pci = connectionReference.getContext();
Connection conn = connectionReference.getConnection();
ConnectionEnd ce = conn.getAllSource();
if (pci == ci.getContainingComponentInstance() && ce == f) {
// add connection if it goes through feature instance
result.add(connectionInstance);
}
}
}
}
return result;
}
Aggregations