use of org.osate.aadl2.ComponentPrototypeActual in project osate2 by osate.
the class AadlBaTypeChecker method subprogramTypeCheck.
// Gets subprogram type binded to the given subprogram call action.
// On error, reports error and returns null.
private Classifier subprogramTypeCheck(CommAction comAct) {
Element el = null;
if (comAct.getReference() != null) {
el = comAct.getReference().getOsateRef();
} else {
el = comAct.getQualifiedName().getOsateRef();
}
Classifier result = null;
String errorMsg = null;
if (el instanceof ComponentPrototype) {
ComponentPrototype cp = (ComponentPrototype) el;
if (cp instanceof SubprogramPrototype) {
ComponentClassifier cc = cp.getConstrainingClassifier();
if (cc != null && cc instanceof SubprogramType) {
result = cc;
} else {
errorMsg = " is not a defined subprogram prototype";
result = null;
}
} else {
errorMsg = " is not an subprogram prototype";
result = null;
}
} else if (// Always after ComponentPrototype
el instanceof CalledSubprogram) {
// case.
result = getSubprogramType((CalledSubprogram) el);
} else if (el instanceof ComponentPrototypeBinding) {
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) el;
// Takes the last binding.
ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
if (cpa.getSubcomponentType() instanceof SubprogramType) {
result = (SubprogramType) cpa.getSubcomponentType();
} else {
errorMsg = " is not an subprogram prototype";
result = null;
}
} else // Error case : the binded object is not an subprogram.
{
errorMsg = "is not subprogram";
result = null;
}
// Error reporting.
if (result == null && errorMsg != null) {
String subprogramName = unparseReference(comAct.getReference());
reportError(comAct, '\'' + subprogramName + '\'' + errorMsg);
}
return result;
}
use of org.osate.aadl2.ComponentPrototypeActual in project osate2 by osate.
the class AadlBaUtils method getDataClassifier.
/**
* Returns the DataClassifier object associated to the given List of PrototypeBinging objects.
*
* @param prototypeBindings the list of PrototypeBinging object
* @param dp the DataPrototype searched for in prototypeBindings
* @return the DataClassifier object (null if not found)
*/
private static DataClassifier getDataClassifier(List<PrototypeBinding> prototypeBindings, DataPrototype dp) {
for (PrototypeBinding pb : prototypeBindings) {
if (pb instanceof ComponentPrototypeBinding && pb.getFormal().equals(dp)) {
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) pb;
ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
if (cpa.getSubcomponentType() instanceof DataClassifier) {
return (DataClassifier) cpa.getSubcomponentType();
}
}
}
return null;
}
use of org.osate.aadl2.ComponentPrototypeActual in project osate2 by osate.
the class AadlBaUtils method prototypeBindingResolver.
/**
* Resolves the given prototype binding by returning the binded classifier
* It returns {@code null} if the given prototype binding is not defined.
*
* @param pb the given prototype binding
* @return the binded classifier or {@code null}
*/
public static Classifier prototypeBindingResolver(PrototypeBinding pb) {
Classifier result = null;
if (pb instanceof ComponentPrototypeBinding) {
ComponentPrototypeBinding cpb;
cpb = (ComponentPrototypeBinding) pb;
// Takes the last binding.
ComponentPrototypeActual cpa = cpb.getActuals().get(cpb.getActuals().size() - 1);
result = (Classifier) cpa.getSubcomponentType();
} else if (pb instanceof FeaturePrototypeBinding) {
FeaturePrototypeBinding fpb;
fpb = (FeaturePrototypeBinding) pb;
FeaturePrototypeActual fpa = fpb.getActual();
if (fpa instanceof AccessSpecification) {
result = ((AccessSpecification) fpa).getClassifier();
} else if (fpa instanceof PortSpecification) {
result = ((PortSpecification) fpa).getClassifier();
} else {
// Reports error.
String errorMsg = "prototypeBindingResolver : " + fpa.getClass().getSimpleName() + " is not supported yet.";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
} else if (pb instanceof FeatureGroupPrototypeBinding) {
FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) pb;
result = (FeatureGroupType) fgpb.getActual().getFeatureType();
} else {
// Reports error.
String errorMsg = "prototypeBindingResolver : " + pb.getClass().getSimpleName() + " is not supported yet.";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
return result;
}
use of org.osate.aadl2.ComponentPrototypeActual in project osate2 by osate.
the class Aadl2Utils method getBindedFeature.
private static Feature getBindedFeature(List<PrototypeBinding> bindings, Feature f) {
FeatureClassifier cl = f.getFeatureClassifier();
if ((!(cl instanceof DataPrototype)) || bindings == null || bindings.isEmpty()) {
return f;
}
if ((f instanceof EventPort) || (f instanceof AbstractFeature)) {
return f;
}
DataPrototype proto = (DataPrototype) cl;
for (PrototypeBinding b : bindings) {
if (!(b instanceof ComponentPrototypeBinding)) {
continue;
}
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) b;
Prototype p = b.getFormal();
if (p.getName().equals(proto.getName())) {
List<ComponentPrototypeActual> actuals = cpb.getActuals();
if (actuals != null && !actuals.isEmpty()) {
ComponentPrototypeActual actual = actuals.get(0);
SubcomponentType st = actual.getSubcomponentType();
if (!(st instanceof DataClassifier)) {
continue;
}
DataClassifier dc = (DataClassifier) st;
return setFeatureClassifier(f, dc);
}
}
}
return f;
}
use of org.osate.aadl2.ComponentPrototypeActual in project osate2 by osate.
the class ResolvePrototypeUtil method resolveComponentPrototype.
/**
* Find the binding for a given component prototype.
*
* @param proto the prototype to resolve
* @param context the context of the feature or subcomponent in which the prototype is used, e.g., a
* ComponentType, FeatureGroupType, ComponentImplementation
* @return The component prototype actual that the prototype resolves to.
*/
public static ComponentClassifier resolveComponentPrototype(ComponentPrototype proto, Element context) {
ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) resolvePrototype(proto, context);
if (cpb == null) {
// look for constraining classifier
ComponentPrototype refinedPrototype = proto;
while (refinedPrototype.getConstrainingClassifier() != null && refinedPrototype.getRefined() instanceof ComponentPrototype) {
refinedPrototype = (ComponentPrototype) refinedPrototype.getRefined();
}
if (refinedPrototype.getConstrainingClassifier() != null) {
return refinedPrototype.getConstrainingClassifier();
} else {
return null;
}
}
EList<ComponentPrototypeActual> actuals = cpb.getActuals();
if (actuals != null && actuals.size() > 0) {
ComponentPrototypeActual actual = actuals.get(0);
if (actual.getSubcomponentType() instanceof ComponentClassifier) {
return (ComponentClassifier) actual.getSubcomponentType();
} else {
if (actual.getSubcomponentType() instanceof ComponentPrototype && context instanceof ContainmentPathElement) {
// resolve recursively if we are in a containment path
return resolveComponentPrototype((ComponentPrototype) actual.getSubcomponentType(), getPrevious((ContainmentPathElement) context));
}
}
}
return null;
}
Aggregations