use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class Aadl2Validator method checkIncomingFeatureDirection.
private boolean checkIncomingFeatureDirection(Feature inFeature, FlowImplementation flow, boolean inverseOf, boolean report) {
// Test for L2
if (inFeature instanceof Port || inFeature instanceof Parameter || inFeature instanceof AbstractFeature) {
DirectionType fDirection = ((DirectedFeature) inFeature).getDirection();
if (inverseOf) {
fDirection = fDirection.getInverseDirection();
}
if (!fDirection.incoming()) {
if (report) {
error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must be an in or in out feature.");
}
return false;
} else {
return true;
}
} else // Test for L4
if (inFeature instanceof DataAccess) {
AccessRights accessRight = org.osate.aadl2.contrib.memory.MemoryProperties.getAccessRight(inFeature).orElse(AccessRights.READ_WRITE);
if (inverseOf) {
accessRight = AadlContribUtils.getInverseDirection(accessRight);
}
if (accessRight != AccessRights.READ_ONLY && accessRight != AccessRights.READ_WRITE) {
if (report) {
error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must have an access right of Read_Only or Read_Write.");
}
return false;
} else {
return true;
}
} else // Test for L6
if (inFeature instanceof FeatureGroup) {
FeatureGroupType fgt = ((FeatureGroup) inFeature).getAllFeatureGroupType();
boolean inInverseof = ((FeatureGroup) inFeature).isInverse();
if (!Aadl2Util.isNull(fgt)) {
if (!Aadl2Util.isNull(fgt.getInverse()) && fgt.getOwnedFeatures().isEmpty()) {
inInverseof = !inInverseof;
}
if (fgt.getAllFeatures().isEmpty()) {
return true;
}
for (Feature f : fgt.getAllFeatures()) {
// the feature group
if (checkIncomingFeatureDirection(f, flow, inInverseof ? !inverseOf : inverseOf, false)) {
return true;
}
}
if (report) {
error(flow.getInEnd(), '\'' + (flow.getInEnd().getContext() != null ? flow.getInEnd().getContext().getName() + '.' : "") + inFeature.getName() + "' must contain at least one in or in out port or parameter, at least data access with an access right of Read_Only or Read_Write, or be empty.");
return false;
}
}
return true;
}
return false;
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class GetProperties method sumElementsDataSize.
private static double sumElementsDataSize(final NamedElement ne, UnitLiteral unit, Property DataSize, Property SourceDataSize, int nesting) {
double res = 0.0;
Classifier cl = null;
if (ne instanceof Classifier) {
cl = (Classifier) ne;
} else if (ne instanceof FeatureInstance) {
cl = ((FeatureInstance) ne).getFeature().getAllClassifier();
} else if (ne instanceof Feature) {
cl = ((Feature) ne).getClassifier();
} else if (ne instanceof DataSubcomponent) {
cl = ((DataSubcomponent) ne).getClassifier();
}
if (cl != null) {
if (cl instanceof FeatureGroupType) {
EList<Feature> fl = ((FeatureGroupType) cl).getAllFeatures();
for (Feature f : fl) {
res = res + getDataSize(f, unit, DataSize, SourceDataSize, nesting);
}
} else if (cl instanceof DataImplementation) {
for (Subcomponent ds : ((DataImplementation) cl).getAllSubcomponents()) {
if (!AadlUtil.isSameOrExtends(cl, ds.getAllClassifier())) {
res = res + getDataSize(ds, unit, DataSize, SourceDataSize, nesting);
}
}
}
}
return res;
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class InstanceUtil method resolveFeatureGroupPrototype.
/**
* Find the binding for a given feature group 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 feature group prototype actual the prototype is bound to.
*/
public static FeatureGroupPrototypeActual resolveFeatureGroupPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
FeatureGroupPrototypeActual result = null;
FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) resolvePrototype(proto, context, classifierCache);
if (fgpb == null) {
// cannot resolve
return null;
}
FeatureGroupPrototypeActual actual = fgpb.getActual();
if (actual.getFeatureType() instanceof FeatureGroupType) {
result = actual;
} else {
// resolve recursively
result = resolveFeatureGroupPrototype((FeatureGroupPrototype) actual.getFeatureType(), context.getContainingComponentInstance(), classifierCache);
}
return result;
}
use of org.osate.aadl2.FeatureGroupType in project osate2 by osate.
the class AadlBaUtils method getClassifier.
/**
* Returns the given Element object's classifier.
* If the Element object is a prototype, it will try to resolve it as
* follow: returns the data prototype binded classifier at first withing the
* element's parent container otherwise the constraining classifier.
* It returns {@code null} if the prototype is not defined.
* <BR><BR>
* This method support instances of:<BR>
* <BR>_Feature (port, data access, subprogram access, parameter, etc.)
* <BR>_Subcomponent (data subcomponent, subprogram subcomponent, etc.)
* <BR>_BehaviorVariable
* <BR>_IterativeVariable (for/forall's iterative variable)
* <BR>_Prototype (all excepted FeatureGroupPrototype)
* <BR>_PrototypeBinding (all excepted FeatureGroupPrototypeBinding)
* <BR>_ClassifierValue (struct or union data subcomponent)
* <BR><BR>
* If the given Element object is not one of those types, an
* UnsupportedOperationException is thrown.
*
* @param el the given Element object
* @param parentContainer the element's parent component.
* @return the given element's classifier or {@code null} if the prototype is
* not defined
* @exception UnsupportedOperationException for unsupported element
* object types.
*/
public static Classifier getClassifier(Element el, Classifier parentContainer) {
Classifier result = null;
if (el instanceof Feature) {
Feature f = (Feature) el;
if (el instanceof FeatureGroup) {
org.osate.aadl2.FeatureType ft = ((FeatureGroup) el).getFeatureType();
if (ft != null) {
if (ft instanceof FeatureGroupType) {
result = (FeatureGroupType) ft;
} else // FeatureGroupPrototype case
{
result = getClassifier((FeatureGroupPrototype) ft, parentContainer);
}
}
} else {
// Feature case.
result = f.getClassifier();
// Feature without classifier returns null.
if (result == null && f.getPrototype() != null) {
result = prototypeResolver(f.getPrototype(), parentContainer);
}
}
} else if (el instanceof Subcomponent) {
Subcomponent sub = (Subcomponent) el;
if (el instanceof SubprogramGroupSubcomponent) {
result = ((SubprogramGroupSubcomponent) el).getClassifier();
} else {
// Subcomponent case.
result = sub.getClassifier();
// Subcomponent without classifier returns null.
if (result == null && sub.getPrototype() != null) {
result = prototypeResolver(sub.getPrototype(), parentContainer);
}
}
} else if (el instanceof BehaviorVariable) {
// Local variable case (BehaviorVariable).
BehaviorVariable bv = (BehaviorVariable) el;
result = bv.getDataClassifier();
} else if (el instanceof IterativeVariable) {
// Iterative variable case.
result = ((IterativeVariable) el).getDataClassifier();
} else if (el instanceof Prototype) {
result = prototypeResolver((Prototype) el, parentContainer);
} else if (el instanceof PrototypeBinding) {
// Prototype binding case.
result = prototypeBindingResolver((PrototypeBinding) el);
} else if (el instanceof ClassifierValue) {
// struct or union member case (ClassifierValue).
result = ((ClassifierValue) el).getClassifier();
} else if (el instanceof StructUnionElement) {
return ((StructUnionElement) el).getDataClassifier();
} else {
// Reports error.
String errorMsg = "getClassifier : " + el.getClass().getSimpleName() + " is not supported yet.";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
return result;
}
use of org.osate.aadl2.FeatureGroupType 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;
}
Aggregations