Search in sources :

Example 6 with ProcessSubcomponent

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

the class InstantiateModel method instantiateSubcomponent.

protected void instantiateSubcomponent(final ComponentInstance parent, final ModalElement mm, final Subcomponent sub, Stack<Long> indexStack, int index) throws InterruptedException {
    final ComponentInstance newInstance = InstanceFactory.eINSTANCE.createComponentInstance();
    final ComponentClassifier cc;
    final InstantiatedClassifier ic;
    newInstance.setSubcomponent(sub);
    // Issue 961: Set the category for real later (below); set it here now in case something goes wrong
    newInstance.setCategory(sub.getCategory());
    newInstance.setName(sub.getName());
    newInstance.getIndices().addAll(indexStack);
    newInstance.getIndices().add(Long.valueOf(index));
    parent.getComponentInstances().add(newInstance);
    ic = getInstantiatedClassifier(newInstance);
    if (ic == null) {
        cc = null;
    } else {
        cc = (ComponentClassifier) ic.getClassifier();
    }
    if (cc == null) {
        errManager.warning(newInstance, "Instantiated subcomponent doesn't have a component classifier");
    } else {
        // if (cc instanceof ComponentType) {
        // if (sub instanceof SystemSubcomponent || sub instanceof ProcessSubcomponent
        // || sub instanceof ThreadGroupSubcomponent) {
        // errManager.warning(newInstance, "Instantiated subcomponent has a component type only");
        // }
        // }
        newInstance.setClassifier(cc);
        /*
			 * From Issue 961:
			 *
			 * I think the category can be determined as follows:
			 *
			 * If the classifier is not abstract then use its category (and maybe check that the subcomponent either has the same category or is abstract).
			 * If the classifier is abstract then use the category from the subcomponent.
			 *
			 * Only if both are abstract the component instance should be abstract.
			 * If both are not abstract then they must have the same category. If the categories are different, validation should already have reported an
			 * error, and we don't instantiate models with errors. It can't hurt if the instantiator checks again, though.
			 */
        final ComponentCategory classifierCategory = cc.getCategory();
        final ComponentCategory subcomponentCategory = sub.getCategory();
        if (classifierCategory != ComponentCategory.ABSTRACT) {
            newInstance.setCategory(cc.getCategory());
            if (subcomponentCategory != ComponentCategory.ABSTRACT && subcomponentCategory != classifierCategory) {
                errManager.warning(newInstance, "Subcomponent's category and its classifier's category do not match");
            }
        } else {
            newInstance.setCategory(subcomponentCategory);
        }
    }
    for (Mode mode : mm.getAllInModes()) {
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        ModeInstance mi = parent.findModeInstance(mode);
        if (mi != null) {
            newInstance.getInModes().add(mi);
        }
    }
    populateComponentInstance(newInstance, index);
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ModeInstance(org.osate.aadl2.instance.ModeInstance) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) ComponentCategory(org.osate.aadl2.ComponentCategory)

Aggregations

ProcessSubcomponent (org.osate.aadl2.ProcessSubcomponent)3 AadlPackage (org.osate.aadl2.AadlPackage)2 AbstractSubcomponent (org.osate.aadl2.AbstractSubcomponent)2 BusSubcomponent (org.osate.aadl2.BusSubcomponent)2 ComponentClassifier (org.osate.aadl2.ComponentClassifier)2 EOperation (org.eclipse.emf.ecore.EOperation)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 org.osate.aadl2 (org.osate.aadl2)1 AadlBoolean (org.osate.aadl2.AadlBoolean)1 AadlInteger (org.osate.aadl2.AadlInteger)1 AadlReal (org.osate.aadl2.AadlReal)1 AadlString (org.osate.aadl2.AadlString)1 AbstractFeature (org.osate.aadl2.AbstractFeature)1 AbstractImplementation (org.osate.aadl2.AbstractImplementation)1 AbstractPrototype (org.osate.aadl2.AbstractPrototype)1 AbstractSubcomponentType (org.osate.aadl2.AbstractSubcomponentType)1 AbstractType (org.osate.aadl2.AbstractType)1