Search in sources :

Example 1 with ComponentPrototypeActual

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;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) Element(org.osate.aadl2.Element) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeBehaviorElement(org.osate.ba.declarative.DeclarativeBehaviorElement) NamedElement(org.osate.aadl2.NamedElement) SubprogramType(org.osate.aadl2.SubprogramType) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) CalledSubprogram(org.osate.aadl2.CalledSubprogram) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 2 with ComponentPrototypeActual

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;
}
Also used : ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) DataClassifier(org.osate.aadl2.DataClassifier) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 3 with ComponentPrototypeActual

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;
}
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 4 with ComponentPrototypeActual

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;
}
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)

Example 5 with ComponentPrototypeActual

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;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Aggregations

ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)13 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)10 ComponentClassifier (org.osate.aadl2.ComponentClassifier)7 ComponentPrototype (org.osate.aadl2.ComponentPrototype)6 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)6 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)6 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)5 AccessSpecification (org.osate.aadl2.AccessSpecification)4 Classifier (org.osate.aadl2.Classifier)4 DataClassifier (org.osate.aadl2.DataClassifier)4 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)4 PrototypeBinding (org.osate.aadl2.PrototypeBinding)4 DataPrototype (org.osate.aadl2.DataPrototype)3 FeaturePrototype (org.osate.aadl2.FeaturePrototype)3 FeaturePrototypeReference (org.osate.aadl2.FeaturePrototypeReference)3 PortSpecification (org.osate.aadl2.PortSpecification)3 EObject (org.eclipse.emf.ecore.EObject)2 AadlString (org.osate.aadl2.AadlString)2 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)2