Search in sources :

Example 26 with PrototypeBinding

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

the class InstanceUtil method getInstantiatedClassifier.

/**
 * Get the component or feature group classifier that is instantiated by an
 * instance object. Resolve prototypes if needed.
 *
 * @param iobj the instance object
 * @param index the index of the instance object in an array
 * @param classifierCache an optional cache of known instantiated
 *            classifiers, may be null
 * @return the instantiated classifier together with bindings for anonymous
 *         classifiers
 */
public static InstantiatedClassifier getInstantiatedClassifier(InstanceObject iobj, int index, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    InstantiatedClassifier ic = null;
    if (classifierCache != null) {
        final InstantiatedClassifier temp = classifierCache.get(iobj);
        if (temp != null) {
            return temp == InstantiatedClassifier.NULL ? null : temp;
        }
    }
    if (iobj instanceof SystemInstance) {
        ic = new InstantiatedClassifier(((SystemInstance) iobj).getComponentImplementation(), null);
    }
    if (ic == null) {
        Classifier classifier = null;
        EList<PrototypeBinding> prototypeBindings = null;
        Prototype prototype = null;
        if (iobj instanceof ComponentInstance) {
            Subcomponent sub = ((ComponentInstance) iobj).getSubcomponent();
            classifier = sub.getClassifier();
            prototypeBindings = sub.getOwnedPrototypeBindings();
            prototype = sub.getPrototype();
        } else if (iobj instanceof FeatureInstance) {
            FeatureType ft = ((FeatureGroup) ((FeatureInstance) iobj).getFeature()).getFeatureType();
            classifier = (ft instanceof Classifier) ? (Classifier) ft : null;
            prototype = (ft instanceof Prototype) ? (Prototype) ft : null;
        } else {
            return null;
        }
        if (classifier != null) {
            ic = new InstantiatedClassifier(classifier, prototypeBindings);
        }
        // no classifier => try prototype
        if (ic == null) {
            if (prototype != null) {
                // resolve prototype
                if (prototype instanceof ComponentPrototype) {
                    ComponentPrototypeActual cpa = resolveComponentPrototype(prototype, iobj, classifierCache);
                    if (cpa != null) {
                        ic = new InstantiatedClassifier((ComponentClassifier) cpa.getSubcomponentType(), cpa.getBindings());
                    } else {
                        // ISSUE 986: If the constraining classifier is missing (null), then don't create an InstantiatedClassifier object
                        final ComponentClassifier cc = ((ComponentPrototype) prototype).getConstrainingClassifier();
                        if (cc != null) {
                            ic = new InstantiatedClassifier(cc, noBindings);
                        }
                    }
                } else if (prototype instanceof FeatureGroupPrototype) {
                    FeatureGroupPrototypeActual fpa = resolveFeatureGroupPrototype(prototype, iobj, classifierCache);
                    if (fpa != null) {
                        ic = new InstantiatedClassifier((FeatureGroupType) fpa.getFeatureType(), fpa.getBindings());
                    } else {
                        ic = new InstantiatedClassifier(((FeatureGroupPrototype) prototype).getConstrainingFeatureGroupType(), noBindings);
                    }
                }
            }
        }
    }
    if (classifierCache != null) {
        classifierCache.put(iobj, ic == null ? InstantiatedClassifier.NULL : ic);
    }
    return ic;
}
Also used : FeatureType(org.osate.aadl2.FeatureType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Prototype(org.osate.aadl2.Prototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) SystemInstance(org.osate.aadl2.instance.SystemInstance) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Example 27 with PrototypeBinding

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

the class InstanceUtil method resolvePrototype.

/**
 * Find the binding for a given 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 binding that assigns the value to the prototype relative to
 *         its usage context.
 */
public static PrototypeBinding resolvePrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    PrototypeBinding result = null;
    InstanceObject parent = (InstanceObject) context.getOwner();
    // prototype binding may be attached to parent (anonymous component classifier)
    if (parent instanceof SystemInstance) {
        ComponentImplementation impl = ((SystemInstance) parent).getComponentImplementation();
        if (impl == null) {
            return null;
        }
        result = impl.lookupPrototypeBinding(proto);
    } else if (parent instanceof ComponentInstance) {
        Subcomponent parentSub = ((ComponentInstance) parent).getSubcomponent();
        if (parentSub == null) {
            return null;
        }
        result = parentSub.lookupPrototypeBinding(proto);
    }
    // lookup in parent's classifier (nested prototype bindings)
    if (result == null && parent != null) {
        InstantiatedClassifier parentClassifier = getInstantiatedClassifier(parent, 0, classifierCache);
        if (parentClassifier.bindings != null) {
            for (PrototypeBinding binding : parentClassifier.bindings) {
                if (binding.getFormal() == proto) {
                    result = binding;
                    break;
                }
            }
        }
        if (result == null) {
            result = parentClassifier.classifier.lookupPrototypeBinding(proto);
        }
    }
    return result;
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) ComponentImplementation(org.osate.aadl2.ComponentImplementation) SystemInstance(org.osate.aadl2.instance.SystemInstance) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Example 28 with PrototypeBinding

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

the class SubcomponentPrototypeBindingsModel method buildComparisonString.

/**
 * Builds a string that can be used to compare a list of prototype bindings
 * @param bindings for which to build a comparison string
 * @return is the comparison string that was built.
 */
private String buildComparisonString(final List<PrototypeBinding> bindings) {
    final StringBuilder sb = new StringBuilder();
    bindings.stream().sorted((b1, b2) -> getPrototypeName(b1).compareToIgnoreCase(getPrototypeName(b2))).forEachOrdered(b -> {
        sb.append(getPrototypeName(b));
        sb.append(':');
        if (b instanceof ComponentPrototypeBinding) {
            final ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) b;
            cpb.getActuals().stream().forEachOrdered(a -> {
                sb.append(a.getCategory());
                sb.append(',');
                addQualfiedNameIfNamedElement(sb, a.getSubcomponentType());
                sb.append('(');
                sb.append(buildComparisonString(a.getBindings()));
                sb.append(')');
            });
        } else if (b instanceof FeatureGroupPrototypeBinding) {
            final FeatureGroupPrototypeBinding fgpb = (FeatureGroupPrototypeBinding) b;
            final FeatureGroupPrototypeActual a = fgpb.getActual();
            if (a != null) {
                addQualfiedNameIfNamedElement(sb, a.getFeatureType());
                sb.append('(');
                sb.append(buildComparisonString(a.getBindings()));
                sb.append(')');
            }
        } else if (b instanceof FeaturePrototypeBinding) {
            FeaturePrototypeBinding fpb = (FeaturePrototypeBinding) b;
            final FeaturePrototypeActual a = fpb.getActual();
            if (a instanceof AccessSpecification) {
                final AccessSpecification as = (AccessSpecification) a;
                sb.append(as.getCategory());
                sb.append(',');
                sb.append(as.getKind());
                sb.append(',');
                addQualfiedNameIfNamedElement(sb, as.getClassifier());
            } else if (a instanceof PortSpecification) {
                final PortSpecification ps = (PortSpecification) a;
                sb.append(ps.getCategory());
                sb.append(',');
                sb.append(ps.getDirection());
                sb.append(',');
                addQualfiedNameIfNamedElement(sb, ps.getClassifier());
            } else if (a instanceof FeaturePrototypeReference) {
                final FeaturePrototypeReference r = (FeaturePrototypeReference) a;
                sb.append(r.getDirection());
                sb.append(',');
                addQualfiedNameIfNamedElement(sb, r.getPrototype());
            }
        }
        sb.append(';');
    });
    return sb.toString();
}
Also used : SubcomponentType(org.osate.aadl2.SubcomponentType) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) AadlSubcomponentUtil(org.osate.ge.aadl2.internal.util.AadlSubcomponentUtil) ArrayList(java.util.ArrayList) BusinessObjectSelection(org.osate.ge.BusinessObjectSelection) Strings(com.google.common.base.Strings) EClass(org.eclipse.emf.ecore.EClass) AccessSpecification(org.osate.aadl2.AccessSpecification) FeaturePrototypeReference(org.osate.aadl2.FeaturePrototypeReference) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) Aadl2Package(org.osate.aadl2.Aadl2Package) Subcomponent(org.osate.aadl2.Subcomponent) Prototype(org.osate.aadl2.Prototype) PortSpecification(org.osate.aadl2.PortSpecification) Iterator(java.util.Iterator) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) PrototypeBinding(org.osate.aadl2.PrototypeBinding) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ComponentCategory(org.osate.aadl2.ComponentCategory) PrototypeBindingsModel(org.osate.ge.swt.classifiers.PrototypeBindingsModel) AadlModelAccessUtil(org.osate.ge.aadl2.ui.AadlModelAccessUtil) NamedElement(org.osate.aadl2.NamedElement) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) PortSpecification(org.osate.aadl2.PortSpecification) FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) AccessSpecification(org.osate.aadl2.AccessSpecification) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) FeaturePrototypeReference(org.osate.aadl2.FeaturePrototypeReference) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding)

Example 29 with PrototypeBinding

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

the class FeatureReferenceBindingType method loadBindingData.

// Populate the model's data structure based on the specified bindings
protected void loadBindingData(final PrototypeBindingsModelNode parent, final Collection<PrototypeBinding> bindings) {
    for (final PrototypeBinding b : bindings) {
        // Create a new node for the binding
        PrototypeBindingsModelNode newChild = new PrototypeBindingsModelNode(parent, b);
        // Ignore null bindings
        if (b == null) {
        } else if (b instanceof ComponentPrototypeBinding) {
            final List<ComponentPrototypeActual> actuals = ((ComponentPrototypeBinding) b).getActuals();
            // If the actual specified multiple values, flag the model as having an unsupported value
            if (actuals.size() == 1) {
                final ComponentPrototypeActual actual = actuals.get(0);
                if (actual != null) {
                    setNodeDataClassifier(newChild, actual.getSubcomponentType());
                    loadBindingData(newChild, actual.getBindings());
                }
            } else {
                unsupportedValue = true;
                return;
            }
        } else if (b instanceof FeatureGroupPrototypeBinding) {
            final FeatureGroupPrototypeActual actual = ((FeatureGroupPrototypeBinding) b).getActual();
            if (actual != null) {
                setNodeDataClassifier(newChild, actual.getFeatureType());
                loadBindingData(newChild, actual.getBindings());
            }
        } else if (b instanceof FeaturePrototypeBinding) {
            final FeaturePrototypeActual actual = ((FeaturePrototypeBinding) b).getActual();
            // Populate data based on the type of actual
            if (actual == null) {
            } else if (actual instanceof AccessSpecification) {
                final AccessSpecification as = (AccessSpecification) actual;
                data(newChild).direction = as.getKind();
                data(newChild).type = new AccessSpecificationBindingType(as.getCategory());
                setNodeDataClassifier(newChild, as.getClassifier());
            } else if (actual instanceof FeaturePrototypeReference) {
                final FeaturePrototypeReference fpr = (FeaturePrototypeReference) actual;
                data(newChild).direction = fpr.getDirection();
                data(newChild).type = new FeatureReferenceBindingType();
                setNodeDataClassifier(newChild, fpr.getPrototype());
            } else if (actual instanceof PortSpecification) {
                final PortSpecification ps = (PortSpecification) actual;
                data(newChild).direction = ps.getDirection();
                data(newChild).type = new PortSpecificationBindingType(ps.getCategory());
                setNodeDataClassifier(newChild, ps.getClassifier());
            } else {
                throw new RuntimeException("Unhandled feature prototype actual type: " + actual);
            }
        } else {
            throw new RuntimeException("Unhandled prototype binding type: " + b);
        }
    }
}
Also used : FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) PortSpecification(org.osate.aadl2.PortSpecification) FeaturePrototypeActual(org.osate.aadl2.FeaturePrototypeActual) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) AccessSpecification(org.osate.aadl2.AccessSpecification) List(java.util.List) ArrayList(java.util.ArrayList) FeaturePrototypeReference(org.osate.aadl2.FeaturePrototypeReference) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding)

Example 30 with PrototypeBinding

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

the class ResolvePrototypeUtil method resolvePrototype.

/**
 * Find the binding for a given prototype.
 *
 * @param proto the prototype to resolve
 * @param context the context of the entity in which the prototype is used, e.g., a
 *            ComponentType, ComponentImplementation, FeatureGroupType, Subcomponent
 * @return The binding that assigns the value to the prototype relative to
 *         its usage context.
 */
public static PrototypeBinding resolvePrototype(Prototype proto, Element context) {
    PrototypeBinding result = null;
    if (context instanceof Classifier) {
        Classifier impl = (Classifier) context;
        result = impl.lookupPrototypeBinding(proto);
    } else if (context instanceof Subcomponent) {
        Subcomponent parentSub = (Subcomponent) context;
        result = parentSub.lookupPrototypeBinding(proto);
        if (result == null) {
            result = resolvePrototype(proto, parentSub.getAllClassifier());
        }
    } else if (context instanceof ContainmentPathElement) {
        result = resolvePrototypeInContainmentPath(proto, (ContainmentPathElement) context);
    } else if (context instanceof FeatureGroupPrototypeActual) {
        final FeatureGroupPrototypeActual fgpa = (FeatureGroupPrototypeActual) context;
        for (final PrototypeBinding binding : fgpa.getBindings()) {
            if (binding.getFormal() == proto) {
                result = binding;
                break;
            }
        }
    }
    // }
    return result;
}
Also used : Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding)

Aggregations

PrototypeBinding (org.osate.aadl2.PrototypeBinding)26 ComponentPrototypeBinding (org.osate.aadl2.ComponentPrototypeBinding)15 FeatureGroupPrototypeBinding (org.osate.aadl2.FeatureGroupPrototypeBinding)13 FeaturePrototypeBinding (org.osate.aadl2.FeaturePrototypeBinding)13 ComponentClassifier (org.osate.aadl2.ComponentClassifier)8 Classifier (org.osate.aadl2.Classifier)7 DataClassifier (org.osate.aadl2.DataClassifier)7 ComponentPrototype (org.osate.aadl2.ComponentPrototype)6 ComponentPrototypeActual (org.osate.aadl2.ComponentPrototypeActual)6 FeatureGroupPrototype (org.osate.aadl2.FeatureGroupPrototype)6 Prototype (org.osate.aadl2.Prototype)6 Subcomponent (org.osate.aadl2.Subcomponent)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)5 AadlString (org.osate.aadl2.AadlString)4 AbstractFeature (org.osate.aadl2.AbstractFeature)4 AccessSpecification (org.osate.aadl2.AccessSpecification)4 FeatureGroupPrototypeActual (org.osate.aadl2.FeatureGroupPrototypeActual)4 PortSpecification (org.osate.aadl2.PortSpecification)4 ArrayList (java.util.ArrayList)3