use of org.osate.aadl2.FeaturePrototypeBinding in project osate2 by osate.
the class AadlBaTypeChecker method typeCheck.
/**
* Checks the type of the reference binded to the given declarative behavior
* element within the given rule's expected types. Returns the
* matching feature type or {@code null} otherwise. Reports any error if
* hasToReport is {@code true}.
*
* @param dbe the declarative behavior element to be checked
* @param name the behavior element's name
* @param rule the checking rule that contains the expected types
* @param hasToReport flag for report error
* @return the matching feature type or {@code null}
*/
private Enum<?> typeCheck(DeclarativeBehaviorElement dbe, String name, TypeCheckRule rule, boolean hasToReport) {
Enum<?> result = rule.test(dbe, _baParentContainer);
if (result == null && hasToReport) {
Enum<?> testedEnum = AadlBaTypeChecker.getType(dbe);
// Resolves feature prototype binding.
if (testedEnum == FeatureType.FEATURE_PROTOTYPE_BINDING) {
Element el = AadlBaTypeChecker.getBindedElement(dbe);
testedEnum = AadlBaUtils.getFeatPrototypeType((FeaturePrototypeBinding) el);
}
String expectedTypes = rule.getExpectedTypes(STRING_TYPE_SEPARATOR);
String typeFound = ((Enumerator) testedEnum).getLiteral();
reportTypeError(dbe, name, expectedTypes, typeFound);
}
return result;
}
use of org.osate.aadl2.FeaturePrototypeBinding in project osate2 by osate.
the class InstanceUtil method resolveFeaturePrototype.
/**
* Find the binding for a given feature prototype.
*
* @param proto the prototype to resolve
* @param context the context in which the prototype is used, e.g., a
* subcomponent instance
* @param classifierCache an optional cache of known instantiated
* classifiers, may be null
* @return The actual feature this prototype resolves to.
*/
public static FeaturePrototypeActual resolveFeaturePrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
FeaturePrototypeActual result = null;
FeaturePrototypeBinding fpb = (FeaturePrototypeBinding) resolvePrototype(proto, context, classifierCache);
if (fpb == null) {
return null;
}
result = fpb.getActual();
if (result instanceof FeaturePrototypeReference) {
// resolve recursively
result = resolveFeaturePrototype(((FeaturePrototypeReference) fpb.getActual()).getPrototype(), context.getContainingComponentInstance(), classifierCache);
}
return result;
}
use of org.osate.aadl2.FeaturePrototypeBinding in project osate2 by osate.
the class SubcomponentPrototypeBindingsModel method buildComparisonString.
/**
* Builds a string that can be used to compare a list of prototype bindings
* @param bindings for which to build a comparison string
* @return is the comparison string that was built.
*/
private String buildComparisonString(final List<PrototypeBinding> bindings) {
final StringBuilder sb = new StringBuilder();
bindings.stream().sorted((b1, b2) -> getPrototypeName(b1).compareToIgnoreCase(getPrototypeName(b2))).forEachOrdered(b -> {
sb.append(getPrototypeName(b));
sb.append(':');
if (b instanceof ComponentPrototypeBinding) {
final ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) b;
cpb.getActuals().stream().forEachOrdered(a -> {
sb.append(a.getCategory());
sb.append(',');
addQualfiedNameIfNamedElement(sb, a.getSubcomponentType());
sb.append('(');
sb.append(buildComparisonString(a.getBindings()));
sb.append(')');
});
} else if (b instanceof FeatureGroupPrototypeBinding) {
final FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) b;
final FeatureGroupPrototypeActual a = fgpb.getActual();
if (a != null) {
addQualfiedNameIfNamedElement(sb, a.getFeatureType());
sb.append('(');
sb.append(buildComparisonString(a.getBindings()));
sb.append(')');
}
} else if (b instanceof FeaturePrototypeBinding) {
FeaturePrototypeBinding fpb = (FeaturePrototypeBinding) b;
final FeaturePrototypeActual a = fpb.getActual();
if (a instanceof AccessSpecification) {
final AccessSpecification as = (AccessSpecification) a;
sb.append(as.getCategory());
sb.append(',');
sb.append(as.getKind());
sb.append(',');
addQualfiedNameIfNamedElement(sb, as.getClassifier());
} else if (a instanceof PortSpecification) {
final PortSpecification ps = (PortSpecification) a;
sb.append(ps.getCategory());
sb.append(',');
sb.append(ps.getDirection());
sb.append(',');
addQualfiedNameIfNamedElement(sb, ps.getClassifier());
} else if (a instanceof FeaturePrototypeReference) {
final FeaturePrototypeReference r = (FeaturePrototypeReference) a;
sb.append(r.getDirection());
sb.append(',');
addQualfiedNameIfNamedElement(sb, r.getPrototype());
}
}
sb.append(';');
});
return sb.toString();
}
use of org.osate.aadl2.FeaturePrototypeBinding in project osate2 by osate.
the class FeatureReferenceBindingType method loadBindingData.
// Populate the model's data structure based on the specified bindings
protected void loadBindingData(final PrototypeBindingsModelNode parent, final Collection<PrototypeBinding> bindings) {
for (final PrototypeBinding b : bindings) {
// Create a new node for the binding
PrototypeBindingsModelNode newChild = new PrototypeBindingsModelNode(parent, b);
// Ignore null bindings
if (b == null) {
} else if (b instanceof ComponentPrototypeBinding) {
final List<ComponentPrototypeActual> actuals = ((ComponentPrototypeBinding) b).getActuals();
// If the actual specified multiple values, flag the model as having an unsupported value
if (actuals.size() == 1) {
final ComponentPrototypeActual actual = actuals.get(0);
if (actual != null) {
setNodeDataClassifier(newChild, actual.getSubcomponentType());
loadBindingData(newChild, actual.getBindings());
}
} else {
unsupportedValue = true;
return;
}
} else if (b instanceof FeatureGroupPrototypeBinding) {
final FeatureGroupPrototypeActual actual = ((FeatureGroupPrototypeBinding) b).getActual();
if (actual != null) {
setNodeDataClassifier(newChild, actual.getFeatureType());
loadBindingData(newChild, actual.getBindings());
}
} else if (b instanceof FeaturePrototypeBinding) {
final FeaturePrototypeActual actual = ((FeaturePrototypeBinding) b).getActual();
// Populate data based on the type of actual
if (actual == null) {
} else if (actual instanceof AccessSpecification) {
final AccessSpecification as = (AccessSpecification) actual;
data(newChild).direction = as.getKind();
data(newChild).type = new AccessSpecificationBindingType(as.getCategory());
setNodeDataClassifier(newChild, as.getClassifier());
} else if (actual instanceof FeaturePrototypeReference) {
final FeaturePrototypeReference fpr = (FeaturePrototypeReference) actual;
data(newChild).direction = fpr.getDirection();
data(newChild).type = new FeatureReferenceBindingType();
setNodeDataClassifier(newChild, fpr.getPrototype());
} else if (actual instanceof PortSpecification) {
final PortSpecification ps = (PortSpecification) actual;
data(newChild).direction = ps.getDirection();
data(newChild).type = new PortSpecificationBindingType(ps.getCategory());
setNodeDataClassifier(newChild, ps.getClassifier());
} else {
throw new RuntimeException("Unhandled feature prototype actual type: " + actual);
}
} else {
throw new RuntimeException("Unhandled prototype binding type: " + b);
}
}
}
Aggregations