Search in sources :

Example 76 with Prototype

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

the class PrototypesModel method setPrototypeType.

@Override
public void setPrototypeType(final EditablePrototype prototype, final PrototypeType value) {
    // Check if the type is different by comparing EClass values
    final EClass currentEClass = prototype.prototype.eClass();
    final EClass newEClass = prototypeTypeToEClass(value);
    if (newEClass == currentEClass) {
        return;
    }
    modifyOwningClassifier("Set Prototype Type", prototype, c -> {
        getPrototypeByName(c, prototype.name).ifPresent(p -> {
            // Store location in list
            final int index = c.getOwnedPrototypes().indexOf(p);
            if (index == -1) {
                throw new RuntimeException("Unable to get index of prototype being modified");
            }
            // Store fields
            final String name = p.getName();
            final Prototype refined = p.getRefined();
            ComponentClassifier cc = null;
            FeatureGroupType fgt = null;
            boolean in = false;
            boolean out = false;
            boolean array = false;
            if (p instanceof ComponentPrototype) {
                final ComponentPrototype cp = (ComponentPrototype) p;
                cc = cp.getConstrainingClassifier();
                array = cp.isArray();
            } else if (p instanceof FeatureGroupPrototype) {
                final FeatureGroupPrototype fp = (FeatureGroupPrototype) p;
                fgt = fp.getConstrainingFeatureGroupType();
            } else if (p instanceof FeaturePrototype) {
                final FeaturePrototype fp = (FeaturePrototype) p;
                cc = fp.getConstrainingClassifier();
                in = fp.isIn();
                out = fp.isOut();
            }
            // Create new prototype
            final Prototype newPrototype = (Prototype) EcoreUtil.create(newEClass);
            c.getOwnedPrototypes().add(index, newPrototype);
            if (refined == null) {
                newPrototype.setName(name);
            } else {
                newPrototype.setRefined(refined);
            }
            // Set fields
            if (newPrototype instanceof ComponentPrototype) {
                final ComponentPrototype cp = (ComponentPrototype) newPrototype;
                cp.setConstrainingClassifier(cc);
                cp.setArray(array);
            } else if (newPrototype instanceof FeatureGroupPrototype) {
                final FeatureGroupPrototype fp = (FeatureGroupPrototype) newPrototype;
                fp.setConstrainingFeatureGroupType(fgt);
            } else if (newPrototype instanceof FeaturePrototype) {
                final FeaturePrototype fp = (FeaturePrototype) newPrototype;
                fp.setConstrainingClassifier(cc);
                fp.setIn(in);
                fp.setOut(out);
            }
            // Move property associations
            newPrototype.getOwnedPropertyAssociations().addAll(p.getOwnedPropertyAssociations());
            // Remove old prototype
            EcoreUtil.remove(p);
        });
    });
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentClassifier(org.osate.aadl2.ComponentClassifier) EClass(org.eclipse.emf.ecore.EClass) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) BusPrototype(org.osate.aadl2.BusPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ProcessorPrototype(org.osate.aadl2.ProcessorPrototype) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) EditablePrototype(org.osate.ge.aadl2.ui.internal.viewmodels.PrototypesModel.EditablePrototype) DataPrototype(org.osate.aadl2.DataPrototype) MemoryPrototype(org.osate.aadl2.MemoryPrototype) Prototype(org.osate.aadl2.Prototype) ThreadPrototype(org.osate.aadl2.ThreadPrototype) VirtualProcessorPrototype(org.osate.aadl2.VirtualProcessorPrototype) SystemPrototype(org.osate.aadl2.SystemPrototype) VirtualBusPrototype(org.osate.aadl2.VirtualBusPrototype) ProcessPrototype(org.osate.aadl2.ProcessPrototype) ThreadGroupPrototype(org.osate.aadl2.ThreadGroupPrototype) SubprogramGroupPrototype(org.osate.aadl2.SubprogramGroupPrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) DevicePrototype(org.osate.aadl2.DevicePrototype) AbstractPrototype(org.osate.aadl2.AbstractPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 77 with Prototype

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

the class SubcomponentPrototypeBindingsModel method flush.

@Override
public void flush() {
    // Get any subcomponent. Will be used to resolve selected classifier
    final Subcomponent currentSc = getBusinessObjectSelection().boStream(Subcomponent.class).findFirst().orElse(null);
    if (currentSc == null) {
        throw new RuntimeException("Unable to retrieve subcomponent");
    }
    // Get the actual object.
    final NamedElementOrDescription classifier = getClassifier(null);
    EObject classifierValue = classifier == null ? null : classifier.getResolvedValue(getResourceSet());
    if (classifierValue != null && !(classifierValue instanceof SubcomponentType)) {
        throw new RuntimeException("Unexpected value: " + classifierValue);
    }
    final SubcomponentType newSubcomponentType = (SubcomponentType) classifierValue;
    getBusinessObjectSelection().modify(Subcomponent.class, sc -> {
        // Set subcomponent type
        AadlSubcomponentUtil.setClassifier(sc, newSubcomponentType);
        // Update prototype bindings
        sc.getOwnedPrototypeBindings().clear();
        createNewBindings(null, newSubcomponentType, sc, sc.getOwnedPrototypeBindings());
    });
}
Also used : Subcomponent(org.osate.aadl2.Subcomponent) EObject(org.eclipse.emf.ecore.EObject) SubcomponentType(org.osate.aadl2.SubcomponentType)

Example 78 with Prototype

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

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

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

the class ClassifierPrototypeBindingsModel method getReferenceablePrototypes.

@Override
protected Stream<Prototype> getReferenceablePrototypes() {
    // Get prototypes for the select classifier
    final List<Classifier> classifiers = getBusinessObjectSelection().boStream(Classifier.class).collect(Collectors.toList());
    if (classifiers.isEmpty()) {
        return null;
    }
    final Classifier c = classifiers.iterator().next();
    return AadlPrototypeUtil.getAllPrototypes(c);
}
Also used : Classifier(org.osate.aadl2.Classifier)

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