use of org.osate.ba.declarative.DeclarativeBehaviorElement in project osate2 by osate.
the class AadlBaTypeChecker method getType.
/**
* Returns the feature type of the element binded to the given behavior
* annex element.
*
* @param el the given behavior annex element
* @return the feature type of the binded element
*/
static Enum<?> getType(DeclarativeBehaviorElement el) {
org.osate.aadl2.Element testedEl = AadlBaTypeChecker.getBindedElement(el);
Enum<?> result;
if (testedEl instanceof BehaviorElement) {
result = AadlBaUtils.getBehaviorAnnexFeatureType((BehaviorElement) testedEl);
} else {
result = AadlBaUtils.getFeatureType(testedEl);
}
return result;
}
use of org.osate.ba.declarative.DeclarativeBehaviorElement in project osate2 by osate.
the class AadlBaNameResolver method classifierFeaturePropertyReferenceResolver.
private boolean classifierFeaturePropertyReferenceResolver(DeclarativePropertyReference ref) {
Reference component = ref.getReference();
if (refResolver(component)) {
PropertyAssociation pa = null;
Classifier type = null;
Identifier propertyNameId = ref.getPropertyNames().get(0).getPropertyName();
Element el = (component.getOsateRef() != null) ? component.getOsateRef() : component.getBaRef();
if (el instanceof PrototypeBinding) {
PrototypeBinding pb = (PrototypeBinding) el;
type = AadlBaUtils.getClassifier(pb, pb.getContainingClassifier());
} else if (el instanceof ClassifierFeature) {
ClassifierFeature cf = (ClassifierFeature) el;
// Fetch the own property association of the classifier feature.
pa = PropertyUtils.findPropertyAssociation(propertyNameId.getId(), cf);
if (pa == null) {
type = AadlBaUtils.getClassifier(cf, cf.getContainingClassifier());
}
} else if (el instanceof BehaviorVariable) {
BehaviorVariable bv = (BehaviorVariable) el;
DeclarativeBehaviorElement de = (DeclarativeBehaviorElement) bv.getDataClassifier();
if (de.getOsateRef() instanceof Classifier) {
type = (Classifier) de.getOsateRef();
}
} else // Cannot resolve or unimplemented cases.
{
String msg = "the type of \'" + ((NamedElement) el).getName() + "\' cannot be resolved";
_errManager.error(el, msg);
}
// search within its type.
if (pa == null && type != null) {
pa = PropertyUtils.findPropertyAssociation(propertyNameId.getId(), type);
}
if (pa != null) {
ref.getPropertyNames().get(0).setOsateRef(pa);
propertyNameId.setOsateRef(pa);
return propertyNameResolver(ref.getPropertyNames());
} else {
reportNameError(propertyNameId, propertyNameId.getId());
return false;
}
} else {
// refResolver has already reported the error.
return false;
}
}
use of org.osate.ba.declarative.DeclarativeBehaviorElement 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;
}
Aggregations