Search in sources :

Example 16 with ComponentClassifier

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

the class FeatureInstanceTooltipContributor method addTooltipContents.

@Override
public void addTooltipContents(final TooltipContributorContext ctx) {
    ctx.getBusinessObjectContext().getBusinessObject(FeatureInstance.class).ifPresent(featureInstance -> {
        final Feature feature = featureInstance.getFeature();
        if (feature instanceof Feature || feature instanceof InternalFeature || feature instanceof ProcessorFeature) {
            // Determine the feature classifier
            final Classifier featureClassifier;
            if (feature instanceof EventDataSource) {
                final EventDataSource aadlFeature = (EventDataSource) feature;
                featureClassifier = aadlFeature.getDataClassifier();
            } else if (feature instanceof PortProxy) {
                final PortProxy aadlFeature = (PortProxy) feature;
                featureClassifier = aadlFeature.getDataClassifier();
            } else if (feature instanceof SubprogramProxy) {
                final SubprogramProxy aadlFeature = (SubprogramProxy) feature;
                featureClassifier = aadlFeature.getSubprogramClassifier();
            } else if (feature instanceof Feature) {
                final Feature aadlFeature = (Feature) feature;
                featureClassifier = aadlFeature.getAllClassifier();
            } else {
                featureClassifier = null;
            }
            // Build the text to contribute to the tooltip
            final StringBuffer tooltipContents = new StringBuffer();
            if (featureClassifier instanceof ComponentClassifier) {
                tooltipContents.append(((ComponentClassifier) featureClassifier).getCategory() + " " + featureClassifier.getQualifiedName());
            } else if (featureClassifier instanceof FeatureGroupType) {
                tooltipContents.append("feature group " + featureClassifier.getQualifiedName());
            } else if (featureClassifier == null) {
                tooltipContents.append("No Classifier");
            } else {
                tooltipContents.append(featureClassifier.getQualifiedName());
            }
            // Create the styled text describing the feature
            final Label lbl = new Label(ctx.getTooltip(), SWT.NONE);
            lbl.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            lbl.setText(tooltipContents.toString());
        }
    });
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) SubprogramProxy(org.osate.aadl2.SubprogramProxy) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) PortProxy(org.osate.aadl2.PortProxy) InternalFeature(org.osate.aadl2.InternalFeature) FeatureGroupType(org.osate.aadl2.FeatureGroupType) Label(org.eclipse.swt.widgets.Label) ProcessorFeature(org.osate.aadl2.ProcessorFeature) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) InternalFeature(org.osate.aadl2.InternalFeature) EventDataSource(org.osate.aadl2.EventDataSource)

Example 17 with ComponentClassifier

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

the class FeatureReferenceBindingType method createNewBindings.

/**
 * Creates new prototype binding business objects based on the state of the model. Bindings which are not valid are ignored.
 * @param parent is the parent node for binding. Used to retrieve child binding nodes.
 * @param classifier is the classifier which to use to retrieve prototypes
 * @param boBeingModified is the top level business object which is being modified. Used to add imports to appropriate package.
 * @param newBindings is the list to which to add created bindings.
 */
protected final void createNewBindings(final PrototypeBindingsModelNode parent, final Object classifier, final Element boBeingModified, final List<PrototypeBinding> newBindings) {
    final Aadl2Factory f = AgeAadlUtil.getAadl2Factory();
    // Check for a binding for each prototype of the specified classifier
    AadlPrototypeUtil.getAllPrototypes(classifier).forEachOrdered(p -> {
        final PrototypeBindingsModelNode child = new PrototypeBindingsModelNode(parent, p);
        final PrototypeBindingsModelNodeData cd = data(child);
        final EObject childClassifier = cd.classifier == null ? null : cd.classifier.getResolvedValue(getResourceSet());
        if (p instanceof ComponentPrototype) {
            // Ignore classifiers which are not of the appropriate type. They could be carry overs from children which no longer exist
            if (childClassifier instanceof SubcomponentType) {
                final ComponentPrototypeBinding b = f.createComponentPrototypeBinding();
                b.setFormal(p);
                final ComponentPrototypeActual a = b.createActual();
                // Set subcomponent type and create child bindings
                a.setSubcomponentType((SubcomponentType) childClassifier);
                AadlImportsUtil.ensurePackageIsImportedForClassifier(boBeingModified, childClassifier);
                createNewBindings(child, childClassifier, boBeingModified, a.getBindings());
                // Determine and set the component category
                final ComponentCategory category;
                if (childClassifier instanceof ComponentClassifier) {
                    category = ((ComponentClassifier) childClassifier).getCategory();
                } else if (childClassifier instanceof ComponentPrototype) {
                    category = ((ComponentPrototype) childClassifier).getCategory();
                } else {
                    category = null;
                }
                if (category == null) {
                    throw new RuntimeException("Unable to determine component category for " + childClassifier);
                }
                a.setCategory(category);
                // Add the binding to the specified list
                newBindings.add(b);
            }
        } else if (p instanceof FeatureGroupPrototype) {
            if (childClassifier instanceof FeatureType) {
                // Create the binding and the actual
                final FeatureGroupPrototypeBinding b = f.createFeatureGroupPrototypeBinding();
                b.setFormal(p);
                final FeatureGroupPrototypeActual a = b.createActual();
                // Set feature type and create child bindings
                a.setFeatureType((FeatureType) childClassifier);
                AadlImportsUtil.ensurePackageIsImportedForClassifier(boBeingModified, childClassifier);
                createNewBindings(child, childClassifier, boBeingModified, a.getBindings());
                // Add the binding to the specified list
                newBindings.add(b);
            }
        } else if (p instanceof FeaturePrototype) {
            // Ignore any bindings for which a type is not set
            if (cd.type != null) {
                final FeaturePrototypeBinding b = f.createFeaturePrototypeBinding();
                b.setFormal(p);
                if (cd.type instanceof AccessSpecificationBindingType) {
                    if (cd.direction instanceof AccessType) {
                        final AccessSpecificationBindingType type = (AccessSpecificationBindingType) cd.type;
                        final AccessSpecification actual = (AccessSpecification) b.createActual(Aadl2Package.eINSTANCE.getAccessSpecification());
                        // Configure the category and kind of the access specification
                        actual.setCategory(type.getCategory());
                        actual.setKind((AccessType) cd.direction);
                        // Set optional classifier
                        if (childClassifier instanceof ComponentClassifier) {
                            actual.setClassifier((ComponentClassifier) childClassifier);
                            AadlImportsUtil.ensurePackageIsImportedForClassifier(boBeingModified, childClassifier);
                        }
                    }
                } else if (cd.type instanceof PortSpecificationBindingType) {
                    if (cd.direction instanceof DirectionType) {
                        final PortSpecificationBindingType type = (PortSpecificationBindingType) cd.type;
                        final PortSpecification actual = (PortSpecification) b.createActual(Aadl2Package.eINSTANCE.getPortSpecification());
                        actual.setCategory(type.getCategory());
                        // Set the direction
                        final DirectionType direction = (DirectionType) cd.direction;
                        switch(direction) {
                            case IN:
                                actual.setIn(true);
                                actual.setOut(false);
                                break;
                            case OUT:
                                actual.setIn(false);
                                actual.setOut(true);
                                break;
                            case IN_OUT:
                                actual.setIn(true);
                                actual.setOut(true);
                                break;
                        }
                        // Set optional classifier
                        if (childClassifier instanceof ComponentClassifier) {
                            AadlImportsUtil.ensurePackageIsImportedForClassifier(boBeingModified, childClassifier);
                            actual.setClassifier((ComponentClassifier) childClassifier);
                        }
                    }
                } else if (cd.type instanceof FeatureReferenceBindingType) {
                    // Classifier is required
                    if (childClassifier instanceof FeaturePrototype) {
                        final FeaturePrototypeReference actual = (FeaturePrototypeReference) b.createActual(Aadl2Package.eINSTANCE.getFeaturePrototypeReference());
                        // Direction is optional. Ignore IN_OUT as it is not a valid option
                        if (cd.direction instanceof DirectionType) {
                            final DirectionType direction = (DirectionType) cd.direction;
                            switch(direction) {
                                case IN:
                                    actual.setIn(true);
                                    actual.setOut(false);
                                    break;
                                case OUT:
                                    actual.setIn(false);
                                    actual.setOut(true);
                                    break;
                                default:
                                    break;
                            }
                        }
                        actual.setPrototype((FeaturePrototype) childClassifier);
                    }
                } else {
                    throw new RuntimeException("Unexpected type: " + cd.type);
                }
                // Don't add the binding if it wasn't completely created
                if (b.getActual() != null) {
                    // Add the binding to the specified list
                    newBindings.add(b);
                }
            }
        } else {
            throw new RuntimeException("Unexpected prototype class: " + p);
        }
    });
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) FeatureType(org.osate.aadl2.FeatureType) SubcomponentType(org.osate.aadl2.SubcomponentType) FeatureGroupPrototypeActual(org.osate.aadl2.FeatureGroupPrototypeActual) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) ComponentCategory(org.osate.aadl2.ComponentCategory) ComponentPrototype(org.osate.aadl2.ComponentPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) EObject(org.eclipse.emf.ecore.EObject) FeaturePrototypeReference(org.osate.aadl2.FeaturePrototypeReference) AccessType(org.osate.aadl2.AccessType) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) Aadl2Factory(org.osate.aadl2.Aadl2Factory) DirectionType(org.osate.aadl2.DirectionType) PortSpecification(org.osate.aadl2.PortSpecification) FeaturePrototype(org.osate.aadl2.FeaturePrototype) AccessSpecification(org.osate.aadl2.AccessSpecification)

Example 18 with ComponentClassifier

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

the class AnalysisModel method impact.

public boolean impact(PropagationPathEnd src, PropagationPathEnd dst) {
    for (PropagationPathRecord ppr : propagationPaths) {
        if ((ppr.getPathSrc().getComponentInstance() == src.getComponentInstance()) && (ppr.getPathSrc().getErrorPropagation() == src.getErrorPropagation()) && (ppr.getPathDst().getComponentInstance() == dst.getComponentInstance()) && (ppr.getPathDst().getErrorPropagation() == dst.getErrorPropagation())) {
            return true;
        }
        if ((ppr.getPathSrc().getComponentInstance() == src.getComponentInstance()) && (ppr.getPathSrc().getErrorPropagation() == src.getErrorPropagation())) {
            ComponentInstance dstCI = ppr.getDstCI();
            List<ErrorPropagation> eps = new ArrayList<ErrorPropagation>();
            ComponentClassifier classifier = dstCI.getComponentClassifier();
            eps.addAll(EMV2Util.getAllOutgoingErrorPropagations(classifier));
            for (ErrorPropagation ep : eps) {
                if (impact(new PropagationPathEnd(dstCI, ep), dst)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ArrayList(java.util.ArrayList) ErrorPropagation(org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation)

Example 19 with ComponentClassifier

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

the class SubcomponentImpl method getPropertyValueInternal.

// TODO-lw: Why don't we return immediately if a pa was found?
public final void getPropertyValueInternal(final Property prop, final PropertyAcc pas, final boolean fromInstanceSlaveCall, final boolean all) throws InvalidModelException {
    final ComponentImplementation owner = (ComponentImplementation) getContainingClassifier();
    // local contained value
    if (!fromInstanceSlaveCall) {
        pas.addLocalContained(this, owner);
    }
    // get local value
    pas.addLocal(this);
    // collect values from refined subcomponents
    Subcomponent refined = getRefined();
    while (refined != null) {
        if (!fromInstanceSlaveCall) {
            pas.addLocalContained(refined, refined.getContainingClassifier());
        }
        pas.addLocal(refined);
        refined = refined.getRefined();
    }
    // get values from classifier
    final ComponentClassifier cc = getClassifier();
    if (cc != null) {
        cc.getPropertyValueInternal(prop, pas, fromInstanceSlaveCall, all);
    }
    // get values from container
    if (!fromInstanceSlaveCall && prop.isInherit()) {
        owner.getPropertyValueInternal(prop, pas, fromInstanceSlaveCall, all);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Subcomponent(org.osate.aadl2.Subcomponent)

Example 20 with ComponentClassifier

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

the class InstanceUtil method resolveComponentPrototype.

/**
 * Find the binding for a given component 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 component prototype actual that the prototype resolves to.
 */
public static ComponentPrototypeActual resolveComponentPrototype(Prototype proto, InstanceObject context, HashMap<InstanceObject, InstantiatedClassifier> classifierCache) {
    ComponentPrototypeActual cpa = null;
    ComponentPrototypeBinding cpb = (ComponentPrototypeBinding) resolvePrototype(proto, context, classifierCache);
    if (cpb == null) {
        // cannot resolve
        return null;
    }
    EList<ComponentPrototypeActual> actuals = cpb.getActuals();
    if (actuals != null && actuals.size() > 0) {
        ComponentPrototypeActual actual = actuals.get(0);
        if (actual.getSubcomponentType() instanceof ComponentClassifier) {
            cpa = actual;
        } else {
            // resolve recursively
            cpa = resolveComponentPrototype((ComponentPrototype) actual.getSubcomponentType(), context.getContainingComponentInstance(), classifierCache);
        }
    }
    return cpa;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ComponentPrototypeActual(org.osate.aadl2.ComponentPrototypeActual) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Aggregations

ComponentClassifier (org.osate.aadl2.ComponentClassifier)76 Subcomponent (org.osate.aadl2.Subcomponent)26 Classifier (org.osate.aadl2.Classifier)22 EObject (org.eclipse.emf.ecore.EObject)19 NamedElement (org.osate.aadl2.NamedElement)19 ComponentImplementation (org.osate.aadl2.ComponentImplementation)16 ArrayList (java.util.ArrayList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)14 AadlPackage (org.osate.aadl2.AadlPackage)13 FeatureGroupType (org.osate.aadl2.FeatureGroupType)12 List (java.util.List)11 ComponentPrototype (org.osate.aadl2.ComponentPrototype)11 Element (org.osate.aadl2.Element)11 ComponentType (org.osate.aadl2.ComponentType)10 Feature (org.osate.aadl2.Feature)9 Mode (org.osate.aadl2.Mode)8 BusinessObjectContext (org.osate.ge.BusinessObjectContext)8 Collectors (java.util.stream.Collectors)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 ComponentCategory (org.osate.aadl2.ComponentCategory)7