use of org.osate.aadl2.instance.ConnectionInstanceEnd in project osate2 by osate.
the class ConnectionInfo method resolveFeatureInstance.
protected ConnectionInstanceEnd resolveFeatureInstance(ConnectionInstanceEnd origCIE, ConnectionInstanceEnd rootCIE) {
if (origCIE instanceof ComponentInstance || rootCIE instanceof ComponentInstance) {
return rootCIE;
}
FeatureInstance rootFI = (FeatureInstance) rootCIE;
if (rootFI.getFeatureInstances().isEmpty()) {
return rootCIE;
}
ConnectionInstanceEnd parentFI = rootFI;
FeatureInstance origFI = (FeatureInstance) origCIE;
Element origParent = origFI.getOwner();
if (origParent instanceof FeatureInstance) {
FeatureInstance origParentFI = (FeatureInstance) origParent;
if (origParentFI.getOwner() instanceof FeatureInstance) {
ConnectionInstanceEnd resFI = resolveFeatureInstance(origParentFI, rootFI);
if (resFI != null) {
parentFI = resFI;
}
}
EList<FeatureInstance> filist = ((FeatureInstance) parentFI).getFeatureInstances();
for (FeatureInstance featureInstance : filist) {
if (Aadl2InstanceUtil.isSame(origFI, featureInstance)) {
return featureInstance;
}
}
}
return rootFI;
}
use of org.osate.aadl2.instance.ConnectionInstanceEnd in project osate2 by osate.
the class CreateConnectionsSwitch method findDestinationFeatureInstance.
/**
* Find the feature instance under FGI, whose name matches the the Feature at the other end
* We do this by finding the connection declaration that goes down at the other end
* It is found by matching the FGT name and then retrieving the feature instance matching the name
* @param connInfo
* @param fgi
* @return FeatureInstance
*/
FeatureInstance findDestinationFeatureInstance(ConnectionInfo connInfo, FeatureInstance fgi) {
List<ConnectionInstanceEnd> srclist = connInfo.sources;
List<ConnectionInstanceEnd> dstlist = connInfo.destinations;
ConnectionInstanceEnd target = null;
for (int i = 0; i < srclist.size(); i++) {
ConnectionInstanceEnd src = srclist.get(i);
ConnectionInstanceEnd dst = dstlist.get(i);
if (target != null && target != src) {
if (src == target.eContainer()) {
// we have a feature in a FG
FeatureInstance targetFI = findFeatureInstance(fgi, target.getName());
if (targetFI == null) {
// name does not match. We may have an inverse of feature group type with its own set of feature names
// In this case it is an index based match
int idx = dst.eContents().indexOf(target);
if (idx >= 0) {
targetFI = fgi.getFeatureInstances().get(idx);
}
}
return targetFI;
} else {
target = dst;
}
} else {
target = dst;
}
}
return null;
}
use of org.osate.aadl2.instance.ConnectionInstanceEnd in project osate-plugin by sireum.
the class Visitor method buildEndPoint.
private org.sireum.hamr.ir.EndPoint buildEndPoint(ConnectionInstanceEnd cie) {
final List<String> component = Arrays.asList(cie.getComponentInstance().getInstanceObjectPath().split("\\."));
final Position componentPos = VisitorUtil.buildPosInfo(cie.getComponentInstance().getInstantiatedObjects().get(0));
if (cie instanceof FeatureInstance) {
final List<String> feature = Arrays.asList(cie.getInstanceObjectPath().split("\\."));
final Position featurePos = VisitorUtil.buildPosInfo(cie.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = handleDirection(((FeatureInstance) cie).getDirection());
return factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction);
} else if (cie instanceof ComponentInstance) {
return factory.endPoint(factory.name(component, componentPos), null, null);
} else if (cie instanceof ModeTransitionInstance) {
throw new RuntimeException("Need to handle ModeTransitionInstanceImpl: " + cie);
} else {
throw new RuntimeException("Unexpected: " + cie);
}
}
use of org.osate.aadl2.instance.ConnectionInstanceEnd in project osate-plugin by sireum.
the class Visitor method buildEndPoint.
private List<org.sireum.hamr.ir.EndPoint> buildEndPoint(ConnectionInstanceEnd connInstEnd, List<String> path) {
List<org.sireum.hamr.ir.EndPoint> result = VisitorUtil.iList();
final List<String> component = Arrays.asList(connInstEnd.getComponentInstance().getInstanceObjectPath().split("\\."));
final Position componentPos = VisitorUtil.buildPosInfo(connInstEnd.getComponentInstance().getInstantiatedObjects().get(0));
if (connInstEnd instanceof FeatureInstance) {
FeatureInstance connElem = (FeatureInstance) connInstEnd;
String featurePre = connElem.getFeature().getName();
FeatureInstance temp = connElem;
while (temp.eContainer() instanceof FeatureInstance) {
featurePre = ((FeatureInstance) temp.eContainer()).getName() + "_" + featurePre;
temp = (FeatureInstance) temp.eContainer();
}
if (connElem.getCategory() == FeatureCategory.FEATURE_GROUP && !connElem.getFeatureInstances().isEmpty()) {
// Feature ff = connElem.getFeature().getRefined();
final String fp = featurePre;
result = VisitorUtil.addAll(result, connElem.getFeatureInstances().stream().flatMap(fii -> flattenFeatureGroupInstance(fii, fp, component, componentPos, false).stream()).collect(Collectors.toList()));
} else if (connElem.getCategory() == FeatureCategory.BUS_ACCESS) {
final List<String> feature = VisitorUtil.add(component, featurePre);
final Position featurePos = VisitorUtil.buildPosInfo(connElem.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = AadlASTJavaFactory.Direction.InOut;
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction));
} else {
final List<String> feature = VisitorUtil.add(component, featurePre);
final Position featurePos = VisitorUtil.buildPosInfo(connElem.getInstantiatedObjects().get(0));
final AadlASTJavaFactory.Direction direction = handleDirection(connElem.getDirection());
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, componentPos), factory.name(feature, featurePos), direction));
}
// org.sireum.hamr.ir.Feature f = buildFeature(connElem, component);
// if(connElem.getCategory() == FeatureCategory.FEATURE_GROUP) {
// connElem.getFeatureInstances().forEach(fi -> {
//
// });
// }
// final List<String> component = (connElem.getgetContext() != null) && (connElem
// .getContext() instanceof Subcomponent)
// ? VisitorUtil.add(path, connElem.getContext().getName())
// : path;
} else if (connInstEnd instanceof ComponentInstance) {
result = VisitorUtil.toIList(factory.endPoint(factory.name(component, componentPos), null, null));
} else if (connInstEnd instanceof ModeTransitionInstance) {
throw new RuntimeException("Need to handle ModeTransitionInstanceImpl: " + connInstEnd);
} else {
throw new RuntimeException("Unexpected: " + connInstEnd);
}
if (result.size() > 1) {
// System.out.println("");
}
return result;
}
use of org.osate.aadl2.instance.ConnectionInstanceEnd in project AMASE by loonwerks.
the class AsymFaultASTBuilder method processFaults.
/**
* Process all faults in the list of fault statements and return a list of
* those faults. It is assumed that all faults in faultGroup are part of multiple
* faults on a single output.
*
* @param faultGroup List of asymmetric FaultStatements.
* @return List of processed faults.
*/
public List<Fault> processFaults(List<FaultStatement> faultGroup) {
if (faultGroup.isEmpty()) {
new SafetyException("Problem with multiple faults on the same output.");
}
List<Fault> faultList = new ArrayList<Fault>();
List<ConnectionInstanceEnd> senderConnections = new ArrayList<>();
DataPortImpl senderOutput = null;
// 1. Create fault nodes using parent method
for (FaultStatement fs : faultGroup) {
faultList.add(super.createSenderFault(fs));
}
// 2. Gather connections and add to parent map - can use any fstmt to do this.
senderOutput = super.findSenderOutput(faultGroup.get(0));
senderConnections = super.populateMapSenderToReceiver(senderOutput);
// 3. Create communication nodes
createCommNodes(senderConnections, senderOutput, faultList);
setPathForFaults(faultList, agreeNode);
return faultList;
}
Aggregations