use of org.osate.aadl2.Abstract in project osate2 by osate.
the class Aadl2Validator method checkDirectionOfFeatureGroupMembers.
/**
* Checks that direction of matching features in feature group are opposite or the same.
* This method is useful when the feature group types of the source and destination are independently specified
* We check that by checking whether the connection has SUBSET, EQUIVALNCE, CONVERSION
*/
private void checkDirectionOfFeatureGroupMembers(Connection connection) {
if (!(connection.getAllLastSource() instanceof FeatureGroup) || !(connection.getAllLastDestination() instanceof FeatureGroup)) {
return;
}
FeatureGroup source = (FeatureGroup) connection.getAllLastSource();
FeatureGroup destination = (FeatureGroup) connection.getAllLastDestination();
FeatureGroupType sourceType = source.getAllFeatureGroupType();
FeatureGroupType destinationType = destination.getAllFeatureGroupType();
if (sourceType == null || destinationType == null) {
return;
}
Context srcContext = connection.getAllSourceContext();
Context dstContext = connection.getAllDestinationContext();
// connection across or through a component
boolean isSibling = (srcContext instanceof Subcomponent && dstContext instanceof Subcomponent);
final ClassifierMatchingRule classifierMatchingRuleValue = org.osate.aadl2.contrib.modeling.ModelingProperties.getClassifierMatchingRule(connection).orElse(ClassifierMatchingRule.CLASSIFIER_MATCH);
if (classifierMatchingRuleValue == ClassifierMatchingRule.EQUIVALENCE || classifierMatchingRuleValue == ClassifierMatchingRule.CONVERSION || classifierMatchingRuleValue == ClassifierMatchingRule.SUBSET) {
EList<Feature> srcFeatures = sourceType.getAllFeatures();
EList<Feature> dstFeatures = destinationType.getAllFeatures();
if (srcFeatures.isEmpty() || dstFeatures.isEmpty()) {
return;
}
for (Feature destinationFeature : dstFeatures) {
if (destinationFeature instanceof DirectedFeature && !((DirectedFeature) destinationFeature).getDirection().equals(DirectionType.IN_OUT)) {
DirectionType destinationDirection = ((DirectedFeature) destinationFeature).getDirection();
List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
destinationChain.add(destinationFeature);
if (isInvertNeeded(destinationChain)) {
destinationDirection = destinationDirection.getInverseDirection();
}
for (Feature sourceFeature : srcFeatures) {
if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
if (sourceFeature instanceof DirectedFeature && !((DirectedFeature) sourceFeature).getDirection().equals(DirectionType.IN_OUT)) {
DirectionType sourceDirection = ((DirectedFeature) sourceFeature).getDirection();
List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
sourceChain.add(sourceFeature);
if (isInvertNeeded(sourceChain)) {
sourceDirection = sourceDirection.getInverseDirection();
}
// check for opposite or matching direction
if (isSibling) {
// opposite direction
if (sourceDirection == destinationDirection) {
error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
}
} else {
// matching direction
if (sourceDirection != destinationDirection) {
error(connection, "The direction of the source feature group feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
}
}
} else {
// source not a directional feature while destination is
if (!(destinationFeature instanceof AbstractFeature && destinationDirection == DirectionType.IN_OUT && sourceFeature instanceof Access)) {
error(connection, "The source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group directional feature '" + destination.getName() + "." + destinationFeature.getName());
}
}
}
}
} else if (destinationFeature instanceof Access) {
AccessType destinationDirection = ((Access) destinationFeature).getKind();
List<NamedElement> destinationChain = getConnectionChain(connection.getRootConnection().getDestination());
destinationChain.add(destinationFeature);
if (isInvertNeeded(destinationChain)) {
destinationDirection = destinationDirection.getInverseType();
}
for (Feature sourceFeature : srcFeatures) {
if (destinationFeature.getName().equalsIgnoreCase(sourceFeature.getName())) {
if (sourceFeature instanceof Access) {
AccessType sourceDirection = ((Access) sourceFeature).getKind();
List<NamedElement> sourceChain = getConnectionChain(connection.getRootConnection().getSource());
sourceChain.add(sourceFeature);
if (isInvertNeeded(sourceChain)) {
sourceDirection = sourceDirection.getInverseType();
}
// check for opposite or matching direction
if (isSibling) {
// opposite direction
if (sourceDirection == destinationDirection) {
error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be opposites.");
}
} else {
// matching direction
if (sourceDirection != destinationDirection) {
error(connection, "The direction of the source feature group access feature '" + source.getName() + "." + sourceFeature.getName() + "' and destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName() + "' of connection " + connection.getName() + " must be same.");
}
}
} else {
// destination not a directional feature while is. Must be an abstract to be ok
if (!(sourceFeature instanceof AbstractFeature && ((AbstractFeature) sourceFeature).getDirection() == DirectionType.IN_OUT)) {
error(connection, "The source feature group directional feature '" + source.getName() + "." + sourceFeature.getName() + "' cannot be connected to destination feature group access feature '" + destination.getName() + "." + destinationFeature.getName());
}
}
}
}
}
}
}
}
use of org.osate.aadl2.Abstract in project osate2 by osate.
the class SetFeatureClassifierPropertySection method setFeatureClassifier.
private static void setFeatureClassifier(final NamedElement feature, final Object classifier) {
if (classifier != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) feature.getElementRoot();
if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
// If the feature is an abstract feature, need to reset the feature prototype. Only a prototype or a classifier may be set.
if (feature instanceof AbstractFeature) {
((AbstractFeature) feature).setFeaturePrototype(null);
}
}
final FeatureClassifierMetadata setterInfo = featureTypeToMetadataMap.get(feature.eClass());
try {
final Method method = feature.getClass().getMethod(setterInfo.setterName, setterInfo.classifierClass);
method.invoke(feature, classifier);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
use of org.osate.aadl2.Abstract in project AGREE by loonwerks.
the class AgreeASTBuilder method gatherUnspecifiedAadlProperties.
private void gatherUnspecifiedAadlProperties(Map<String, GetPropertyExpr> unspecifiedAadlProperties, List<AgreeVar> inputs, List<AgreeStatement> assumptions, List<AgreeStatement> guarantees) {
for (Entry<String, GetPropertyExpr> entry : unspecifiedAadlProperties.entrySet()) {
String propInputName = entry.getKey();
GetPropertyExpr expr = entry.getValue();
Property prop = (Property) expr.getProp();
Expr propInputIdExpr = new IdExpr(propInputName);
Type type;
Expr bound = null;
if (prop.getReferencedPropertyType() instanceof AadlBoolean) {
type = NamedType.BOOL;
} else if (prop.getReferencedPropertyType() instanceof AadlInteger) {
AadlInteger aadlInteger = (AadlInteger) prop.getReferencedPropertyType();
type = NamedType.INT;
if (aadlInteger.getRange() != null) {
PropertyExpression lowerBound = aadlInteger.getRange().getLowerBound();
PropertyExpression upperBound = aadlInteger.getRange().getUpperBound();
Expr lowVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) lowerBound).getScaledValue()).toBigInteger());
Expr highVal = new IntExpr(BigDecimal.valueOf(((IntegerLiteral) upperBound).getScaledValue()).toBigInteger());
Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
}
} else if (prop.getReferencedPropertyType() instanceof AadlReal) {
AadlReal aadlReal = (AadlReal) prop.getReferencedPropertyType();
type = NamedType.REAL;
if (aadlReal.getRange() != null) {
PropertyExpression lowerBound = aadlReal.getRange().getLowerBound();
PropertyExpression upperBound = aadlReal.getRange().getUpperBound();
Expr lowVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) lowerBound).getValue()));
Expr highVal = new RealExpr(BigDecimal.valueOf(((RealLiteral) upperBound).getValue()));
Expr lowBound = new BinaryExpr(lowVal, BinaryOp.LESSEQUAL, propInputIdExpr);
Expr highBound = new BinaryExpr(propInputIdExpr, BinaryOp.LESSEQUAL, highVal);
bound = LustreExprFactory.makeANDExpr(lowBound, highBound);
}
} else {
throw new AgreeException("Could not locate property value '\" + prop.getFullName() + \"' in component '\"\n" + "// + compName.getName() + \"'. Analysis on abstract values not supported for " + "AADL property type " + prop.getReferencedPropertyType() + ".");
}
AgreeVar propInputVar = new AgreeVar(propInputName, type, expr, curInst, null);
Expr constraint = getUnchangingConstraintExpr(propInputIdExpr);
if (bound != null) {
constraint = LustreExprFactory.makeANDExpr(constraint, bound);
}
inputs.add(propInputVar);
assumptions.add(new AgreeStatement("", constraint, prop));
}
}
Aggregations