use of org.osate.aadl2.impl.DirectedFeatureImpl in project osate-plugin by sireum.
the class Visitor method buildFeature.
private org.sireum.hamr.ir.Feature buildFeature(FeatureInstance featureInst, List<String> path) {
final Feature f = featureInst.getFeature();
final List<String> currentPath = VisitorUtil.add(path, featureInst.getName());
org.sireum.hamr.ir.Classifier classifier = null;
if (f.getFeatureClassifier() != null) {
if (f.getFeatureClassifier() instanceof NamedElement) {
if (((NamedElement) f.getFeatureClassifier()).getQualifiedName() != null) {
classifier = factory.classifier(((NamedElement) f.getFeatureClassifier()).getQualifiedName().toString());
} else {
System.out.println("failing here");
}
} else {
throw new RuntimeException("Unexepcted classifier " + f.getFeatureClassifier() + " for feature " + featureInst.getQualifiedName());
}
}
final List<org.sireum.hamr.ir.Property> properties = featureInst.getOwnedPropertyAssociations().stream().map(pa -> buildProperty(pa, currentPath)).collect(Collectors.toList());
AadlASTJavaFactory.FeatureCategory category = null;
switch(featureInst.getCategory()) {
case ABSTRACT_FEATURE:
category = AadlASTJavaFactory.FeatureCategory.AbstractFeature;
break;
case BUS_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.BusAccess;
break;
case DATA_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.DataAccess;
break;
case DATA_PORT:
category = AadlASTJavaFactory.FeatureCategory.DataPort;
break;
case EVENT_PORT:
category = AadlASTJavaFactory.FeatureCategory.EventPort;
break;
case EVENT_DATA_PORT:
category = AadlASTJavaFactory.FeatureCategory.EventDataPort;
break;
case FEATURE_GROUP:
category = AadlASTJavaFactory.FeatureCategory.FeatureGroup;
break;
case PARAMETER:
category = AadlASTJavaFactory.FeatureCategory.Parameter;
break;
case SUBPROGRAM_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.SubprogramAccess;
break;
case SUBPROGRAM_GROUP_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.SubprogramAccessGroup;
break;
default:
throw new RuntimeException("Unexpected category: " + featureInst.getCategory());
}
switch(featureInst.getCategory()) {
case DATA_ACCESS:
case DATA_PORT:
case EVENT_DATA_PORT:
case PARAMETER:
if (f.getClassifier() instanceof DataClassifier) {
processDataType((DataClassifier) f.getClassifier());
}
// do nothing
default:
}
org.sireum.hamr.ir.Name identifier = factory.name(currentPath, VisitorUtil.buildPosInfo(featureInst.getInstantiatedObjects().get(0)));
final List<FeatureInstance> featureInstances = featureInst.getFeatureInstances();
if (featureInstances.isEmpty()) {
if (f instanceof AccessImpl) {
final AccessImpl accessImpl = (AccessImpl) f;
final AadlASTJavaFactory.AccessType accessType = accessImpl.getKind() == AccessType.PROVIDES ? AadlASTJavaFactory.AccessType.Provides : AadlASTJavaFactory.AccessType.Requires;
AadlASTJavaFactory.AccessCategory accessCategory = null;
switch(accessImpl.getCategory()) {
case BUS:
accessCategory = AadlASTJavaFactory.AccessCategory.Bus;
break;
case DATA:
accessCategory = AadlASTJavaFactory.AccessCategory.Data;
break;
case SUBPROGRAM:
accessCategory = AadlASTJavaFactory.AccessCategory.Subprogram;
break;
case SUBPROGRAM_GROUP:
accessCategory = AadlASTJavaFactory.AccessCategory.SubprogramGroup;
break;
case VIRTUAL_BUS:
accessCategory = AadlASTJavaFactory.AccessCategory.VirtualBus;
break;
}
return factory.featureAccess(identifier, category, classifier, accessType, accessCategory, properties, VisitorUtil.getUriFragment(featureInst));
} else if (f instanceof DirectedFeatureImpl) {
final AadlASTJavaFactory.Direction direction = handleDirection(featureInst.getDirection());
return factory.featureEnd(identifier, direction, category, classifier, properties, VisitorUtil.getUriFragment(featureInst));
} else {
throw new RuntimeException("Not expecting feature: " + featureInst);
}
} else {
final boolean isInverse = ((FeatureGroupImpl) f).isInverse();
final List<org.sireum.hamr.ir.Feature> features = featureInstances.stream().map(fi -> buildFeature(fi, currentPath)).collect(Collectors.toList());
return factory.featureGroup(identifier, features, isInverse, category, properties, VisitorUtil.getUriFragment(featureInst));
}
}
use of org.osate.aadl2.impl.DirectedFeatureImpl in project osate-plugin by sireum.
the class Visitor method buildEndPoint.
private List<org.sireum.hamr.ir.EndPoint> buildEndPoint(ConnectedElement connElem, List<String> path) {
List<org.sireum.hamr.ir.EndPoint> result = VisitorUtil.iList();
final List<String> component = (connElem.getContext() != null) && (connElem.getContext() instanceof Subcomponent) ? VisitorUtil.add(path, connElem.getContext().getName()) : path;
final List<String> feature = (connElem.getContext() instanceof FeatureGroup) ? VisitorUtil.add(component, connElem.getContext().getName() + "_" + connElem.getConnectionEnd().getName()) : VisitorUtil.add(component, connElem.getConnectionEnd().getName());
AadlASTJavaFactory.Direction dir = null;
if (connElem.getConnectionEnd() instanceof DirectedFeatureImpl) {
final DirectedFeatureImpl inFeature = (DirectedFeatureImpl) connElem.getConnectionEnd();
if (inFeature.isIn() && inFeature.isOut()) {
dir = AadlASTJavaFactory.Direction.InOut;
} else if (inFeature.isIn() && !inFeature.isOut()) {
dir = AadlASTJavaFactory.Direction.In;
} else {
dir = AadlASTJavaFactory.Direction.Out;
}
}
final ConnectionEnd ce = connElem.getConnectionEnd();
// String cname = AadlUtil.getConnectionEndName(connElem);
if (ce instanceof FeatureGroupImpl) {
final FeatureGroupImpl fgce = (FeatureGroupImpl) ce;
result = VisitorUtil.addAll(result, flattenFeatureGroup(component, fgce.getFullName(), fgce, connElem));
} else if (ce instanceof BusSubcomponentImpl) {
result = VisitorUtil.add(result, factory.endPoint(factory.name(feature, VisitorUtil.buildPosInfo(connElem.getConnectionEnd())), null, AadlASTJavaFactory.Direction.InOut));
} else if (ce instanceof BusAccessImpl) {
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, (connElem.getContext() != null) ? VisitorUtil.buildPosInfo(connElem.getContext()) : null), factory.name(feature, VisitorUtil.buildPosInfo(connElem.getConnectionEnd())), AadlASTJavaFactory.Direction.InOut));
} else {
result = VisitorUtil.add(result, factory.endPoint(factory.name(component, (connElem.getContext() != null) ? VisitorUtil.buildPosInfo(connElem.getContext()) : null), factory.name(feature, VisitorUtil.buildPosInfo(connElem.getConnectionEnd())), dir));
}
if (result.size() > 1) {
// System.out.println("");
}
return result;
}
Aggregations