Search in sources :

Example 16 with FeatureGroupType

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;
}
Also used : AccessRights(org.osate.aadl2.contrib.memory.AccessRights) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature)

Example 17 with FeatureGroupType

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;
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataImplementation(org.osate.aadl2.DataImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature)

Example 18 with FeatureGroupType

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;
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeatureGroupType(org.osate.aadl2.FeatureGroupType) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual)

Example 19 with FeatureGroupType

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;
}
Also used : IterativeVariable(org.osate.ba.aadlba.IterativeVariable) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) AadlString(org.osate.aadl2.AadlString) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 20 with FeatureGroupType

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;
}
Also used : PortSpecification(org.osate.aadl2.PortSpecification) FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) AccessSpecification(org.osate.aadl2.AccessSpecification) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) AadlString(org.osate.aadl2.AadlString) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding)

Aggregations

FeatureGroupType (org.osate.aadl2.FeatureGroupType)49 Classifier (org.osate.aadl2.Classifier)23 FeatureGroup (org.osate.aadl2.FeatureGroup)22 ComponentClassifier (org.osate.aadl2.ComponentClassifier)20 Feature (org.osate.aadl2.Feature)16 Subcomponent (org.osate.aadl2.Subcomponent)13 ComponentPrototype (org.osate.aadl2.ComponentPrototype)10 ComponentType (org.osate.aadl2.ComponentType)10 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)10 NamedElement (org.osate.aadl2.NamedElement)10 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)9 AadlPackage (org.osate.aadl2.AadlPackage)8 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)8 EObject (org.eclipse.emf.ecore.EObject)7 ComponentImplementation (org.osate.aadl2.ComponentImplementation)7 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)7 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)7 ArrayList (java.util.ArrayList)6 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)6 EClass (org.eclipse.emf.ecore.EClass)5