Search in sources :

Example 31 with Prototype

use of org.osate.aadl2.Prototype in project osate2 by osate.

the class AadlBaUtils method prototypeResolver.

/**
 * Resolves the given prototype by returning the binded classifier
 * or if there is no binded classifier, the constraining classifier.
 * It returns {@code null} if the given prototype is not defined.
 *
 * @param prototype the given prototype
 * @param parentContainer the element's parent component
 * @return the binded classifier at first then the constraining classifier or
 * {@code null}
 */
public static Classifier prototypeResolver(Prototype prototype, Classifier parentContainer) {
    Classifier result = null;
    // First find a prototype bind as prototype may be binded several times.
    PrototypeBinding pb = Aadl2Visitors.findPrototypeBindingInComponent(parentContainer, prototype.getName());
    if (pb != null) {
        result = prototypeBindingResolver(pb);
    } else {
        if (prototype instanceof ComponentPrototype) {
            result = ((ComponentPrototype) prototype).getConstrainingClassifier();
        } else if (prototype instanceof FeaturePrototype) {
            result = ((FeaturePrototype) prototype).getConstrainingClassifier();
        } else if (prototype instanceof FeatureGroupPrototype) {
            result = ((FeatureGroupPrototype) prototype).getConstrainingFeatureGroupType();
        } else {
            // Reports error.
            String errorMsg = "prototypeResolver : " + prototype.getClass().getSimpleName() + " is not supported yet.";
            System.err.println(errorMsg);
            throw new UnsupportedOperationException(errorMsg);
        }
    }
    return result;
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) 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) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 32 with Prototype

use of org.osate.aadl2.Prototype 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 33 with Prototype

use of org.osate.aadl2.Prototype in project osate2 by osate.

the class AadlBaUtils method prototypeBindingResolverForDataComponentReference.

/**
 * Returns the DataClassifier object associated to prototype binding in a DataComponentReference
 *
 * @param r the DataComponentRefenrence object from which the binding will be resolved
 * @param dp the DataPrototpye object that enables to identify the targeted prototype binding
 * @param parentContainer the object that contains the element binded to the
 * given DataComponentRefenrence
 * @return the DataClassifier object
 */
private static DataClassifier prototypeBindingResolverForDataComponentReference(DataComponentReference r, DataPrototype dp, NamedElement parentContainer) {
    if (r.getData().size() > 1) {
        DataHolder h = r.getData().get(r.getData().size() - 2);
        NamedElement parent = h.getElement();
        if (parent instanceof Classifier) {
            Classifier c = (Classifier) parent;
            return getDataClassifier(c.getOwnedPrototypeBindings(), dp);
        }
        if (parent instanceof Subcomponent) {
            Subcomponent s = (Subcomponent) parent;
            return getDataClassifier(s.getOwnedPrototypeBindings(), dp);
        } else if (parent instanceof DataAccess) {
            DataAccess da = (DataAccess) parent;
            DataSubcomponentType parentDst = da.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataAccess && f.getName().equals(parent.getName())) {
                            DataAccess containerDa = (DataAccess) f;
                            DataSubcomponentType containerDst = containerDa.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        } else if (parent instanceof DataPort) {
            DataPort dataport = (DataPort) parent;
            DataSubcomponentType parentDst = dataport.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataPort && f.getName().equals(parent.getName())) {
                            DataPort containerDp = (DataPort) f;
                            DataSubcomponentType containerDst = containerDp.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) DataHolder(org.osate.ba.aadlba.DataHolder) 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) 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) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) DataAccess(org.osate.aadl2.DataAccess)

Example 34 with Prototype

use of org.osate.aadl2.Prototype 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)

Example 35 with Prototype

use of org.osate.aadl2.Prototype 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;
}
Also used : FeatureClassifier(org.osate.aadl2.FeatureClassifier) DataPrototype(org.osate.aadl2.DataPrototype) Prototype(org.osate.aadl2.Prototype) EventPort(org.osate.aadl2.EventPort) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) SubcomponentType(org.osate.aadl2.SubcomponentType) AbstractFeature(org.osate.aadl2.AbstractFeature) DataPrototype(org.osate.aadl2.DataPrototype) DataClassifier(org.osate.aadl2.DataClassifier) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Aggregations

Prototype (org.luaj.vm2.Prototype)39 Prototype (org.osate.aadl2.Prototype)24 Classifier (org.osate.aadl2.Classifier)20 ComponentPrototype (org.osate.aadl2.ComponentPrototype)20 ComponentClassifier (org.osate.aadl2.ComponentClassifier)19 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)17 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)16 FeaturePrototype (org.osate.aadl2.FeaturePrototype)14 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)14 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)13 PrototypeBinding (org.osate.aadl2.PrototypeBinding)13 Subcomponent (org.osate.aadl2.Subcomponent)13 FeatureGroupType (org.osate.aadl2.FeatureGroupType)11 DataPrototype (org.osate.aadl2.DataPrototype)10 NamedElement (org.osate.aadl2.NamedElement)10 ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)9 DataClassifier (org.osate.aadl2.DataClassifier)9 Feature (org.osate.aadl2.Feature)9 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)9 EClass (org.eclipse.emf.ecore.EClass)7