Search in sources :

Example 96 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class CreateEndToEndFlowsSwitch method getModeInstances.

// -------------------------------------------------------------------------
// Mode utilities
// -------------------------------------------------------------------------
/**
 * build mode instance list from mode list relative to the component
 * instance ci
 *
 * @param ci Component Instance
 * @param mlist mode list
 * @return list of mode instances
 */
protected EList<ModeInstance> getModeInstances(ComponentInstance ci, ModalElement e) {
    EList<ModeInstance> mis = new BasicEList<ModeInstance>();
    List<Mode> mlist = e.getAllInModes();
    if (!mlist.isEmpty()) {
        for (Mode m : mlist) {
            ModeInstance mi = ci.findModeInstance(m);
            if (mi != null) {
                mis.add(mi);
            }
        }
    } else {
        // get modes form containment hierarchy
        while (!(ci instanceof SystemInstance)) {
            if (ci.getInModes().isEmpty()) {
                ci = ci.getContainingComponentInstance();
            } else {
                mis = ci.getInModes();
                break;
            }
        }
    }
    return mis;
}
Also used : ModeInstance(org.osate.aadl2.instance.ModeInstance) SystemInstance(org.osate.aadl2.instance.SystemInstance) BasicEList(org.eclipse.emf.common.util.BasicEList) Mode(org.osate.aadl2.Mode) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode)

Example 97 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class InstantiateModel method populateComponentInstance.

// --------------------------------------------------------------------------------------------
// Methods for instantiating the component hierarchy
// --------------------------------------------------------------------------------------------
/*
	 * Fill in modes, transitions, subcomponent instances, features, flow specs.
	 */
protected void populateComponentInstance(ComponentInstance ci, int index) throws InterruptedException {
    ComponentImplementation impl = getComponentImplementation(ci);
    ComponentType type = getComponentType(ci);
    if (ci.getContainingComponentInstance() instanceof SystemInstance) {
        monitor.subTask("Creating instances in " + ci.getName());
    }
    /*
		 * Add modes. Must do this before adding subcomponents
		 * because we need to know what are the ModeInstances when processing
		 * modal subcomponents.
		 */
    if (impl != null) {
        fillModes(ci, impl.getAllModes());
    } else if (type != null) {
        fillModes(ci, type.getAllModes());
    }
    if (impl != null) {
        // Recursively add subcomponents
        instantiateSubcomponents(ci, impl);
    // TODO now add subprogram calls
    // EList callseqlist = compimpl.getXAllCallSequence();
    // for (Iterator it = callseqlist.iterator(); it.hasNext();) {
    // CallSequence cseq = (CallSequence) it.next();
    // 
    // EList calllist = cseq.getCall();
    // for (Iterator iit = calllist.iterator(); iit.hasNext();) {
    // final SubprogramSubcomponent call =
    // (SubprogramSubcomponent) iit.next();
    // instantiateSubcomponent(ci, cseq, call);
    // }
    // }
    }
    // do it only if subcomponent has type
    if (type != null) {
        instantiateFeatures(ci);
    }
    /*
		 * Add mode transitions. Must do this after adding subcomponents
		 * because we need reference subcomponent features as triggers.
		 */
    if (impl != null) {
        fillModeTransitions(ci, impl.getAllModeTransitions());
    } else if (type != null) {
        fillModeTransitions(ci, type.getAllModeTransitions());
    }
    if (type != null) {
        instantiateFlowSpecs(ci);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 98 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class InstantiateModel method getAllUsedPropertyDefinitions.

// --------------------------------------------------------------------------------------------
// Methods related to properties
// --------------------------------------------------------------------------------------------
/**
 * Get all property definitions that are used in the Aadl model. This
 * includes the predeclared properties and any property definitions in user
 * declared property sets.
 *
 * @param si System Implementation
 * @return property definitions
 */
public EList<Property> getAllUsedPropertyDefinitions(SystemInstance root) throws InterruptedException {
    if (monitor.isCanceled()) {
        throw new InterruptedException();
    }
    EList<Property> result = new UniqueEList<Property>();
    addUsedProperties(root, root.getComponentImplementation(), result);
    TreeIterator<Element> it = EcoreUtil.getAllContents(Collections.singleton(root));
    // collect topdown component impl. do it and its type to find PA
    while (it.hasNext()) {
        Element elem = it.next();
        if (elem instanceof ComponentInstance) {
            InstantiatedClassifier ic = getInstantiatedClassifier((ComponentInstance) elem);
            if (ic != null && ic.getClassifier() != null) {
                if (ic.getClassifier().equals(root.getComponentImplementation())) {
                    addUsedProperties(root, ic.getClassifier(), result, false);
                } else {
                    addUsedProperties(root, ic.getClassifier(), result);
                }
            }
        } else if (elem instanceof FeatureInstance) {
            FeatureInstance fi = (FeatureInstance) elem;
            if (fi.getFeature() instanceof FeatureGroup) {
                FeatureGroupType fgt = getFeatureGroupType(fi);
                addUsedProperties(root, fgt, result);
            } else {
                Classifier c = fi.getFeature().getClassifier();
                addUsedProperties(root, c, result);
            }
        } else if (elem instanceof ConnectionInstance) {
            ConnectionInstance ci = (ConnectionInstance) elem;
            addUsedPropertyDefinitions(ci.getContainingClassifier(), result);
            for (ConnectionReference cr : ci.getConnectionReferences()) {
                addUsedPropertyDefinitions(cr.getConnection(), result);
            }
        }
    }
    return result;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) FeatureGroup(org.osate.aadl2.FeatureGroup) UniqueEList(org.eclipse.emf.common.util.UniqueEList) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) ModalElement(org.osate.aadl2.ModalElement) Element(org.osate.aadl2.Element) FeatureGroupType(org.osate.aadl2.FeatureGroupType) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Property(org.osate.aadl2.Property)

Example 99 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class AbstractInstanceSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == Aadl2Package.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case Aadl2Package.ARRAY_RANGE:
                sequence_ArrayRange(context, (ArrayRange) semanticObject);
                return;
            case Aadl2Package.BASIC_PROPERTY_ASSOCIATION:
                sequence_FieldPropertyAssociation(context, (BasicPropertyAssociation) semanticObject);
                return;
            case Aadl2Package.BOOLEAN_LITERAL:
                sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
                return;
            case Aadl2Package.CLASSIFIER_VALUE:
                sequence_ComponentClassifierTerm(context, (ClassifierValue) semanticObject);
                return;
            case Aadl2Package.COMPUTED_VALUE:
                sequence_ComputedTerm(context, (ComputedValue) semanticObject);
                return;
            case Aadl2Package.CONTAINED_NAMED_ELEMENT:
                sequence_ContainmentPath(context, (ContainedNamedElement) semanticObject);
                return;
            case Aadl2Package.CONTAINMENT_PATH_ELEMENT:
                sequence_ContainmentPathElement(context, (ContainmentPathElement) semanticObject);
                return;
            case Aadl2Package.INTEGER_LITERAL:
                sequence_IntegerTerm(context, (IntegerLiteral) semanticObject);
                return;
            case Aadl2Package.LIST_VALUE:
                sequence_ListTerm(context, (ListValue) semanticObject);
                return;
            case Aadl2Package.MODAL_PROPERTY_VALUE:
                if (rule == grammarAccess.getModalPropertyValueRule()) {
                    sequence_ModalPropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getOptionalModalPropertyValueRule()) {
                    sequence_OptionalModalPropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyValueRule()) {
                    sequence_PropertyValue(context, (ModalPropertyValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.NAMED_VALUE:
                if (rule == grammarAccess.getConstantValueRule() || rule == grammarAccess.getNumAltRule()) {
                    sequence_ConstantValue(context, (NamedValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getLiteralorReferenceTermRule()) {
                    sequence_LiteralorReferenceTerm(context, (NamedValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.OPERATION:
                sequence_SignedConstant(context, (Operation) semanticObject);
                return;
            case Aadl2Package.PROPERTY_ASSOCIATION:
                if (rule == grammarAccess.getBasicPropertyAssociationRule()) {
                    sequence_BasicPropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPModelRule() || rule == grammarAccess.getContainedPropertyAssociationRule()) {
                    sequence_ContainedPropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyAssociationRule()) {
                    sequence_PropertyAssociation(context, (PropertyAssociation) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.RANGE_VALUE:
                sequence_NumericRangeTerm(context, (RangeValue) semanticObject);
                return;
            case Aadl2Package.REAL_LITERAL:
                sequence_RealTerm(context, (RealLiteral) semanticObject);
                return;
            case Aadl2Package.RECORD_VALUE:
                if (rule == grammarAccess.getOldRecordTermRule()) {
                    sequence_OldRecordTerm(context, (RecordValue) semanticObject);
                    return;
                } else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getRecordTermRule()) {
                    sequence_RecordTerm(context, (RecordValue) semanticObject);
                    return;
                } else
                    break;
            case Aadl2Package.REFERENCE_VALUE:
                sequence_ReferenceTerm(context, (ReferenceValue) semanticObject);
                return;
            case Aadl2Package.STRING_LITERAL:
                sequence_StringTerm(context, (StringLiteral) semanticObject);
                return;
        }
    else if (epackage == InstancePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case InstancePackage.COMPONENT_INSTANCE:
                sequence_ComponentInstance(context, (ComponentInstance) semanticObject);
                return;
            case InstancePackage.CONNECTION_INSTANCE:
                sequence_ConnectionInstance(context, (ConnectionInstance) semanticObject);
                return;
            case InstancePackage.CONNECTION_REFERENCE:
                sequence_ConnectionReference(context, (ConnectionReference) semanticObject);
                return;
            case InstancePackage.END_TO_END_FLOW_INSTANCE:
                sequence_EndToEndFlowInstance(context, (EndToEndFlowInstance) semanticObject);
                return;
            case InstancePackage.FEATURE_INSTANCE:
                sequence_FeatureInstance(context, (FeatureInstance) semanticObject);
                return;
            case InstancePackage.FLOW_SPECIFICATION_INSTANCE:
                sequence_FlowSpecificationInstance(context, (FlowSpecificationInstance) semanticObject);
                return;
            case InstancePackage.INSTANCE_REFERENCE_VALUE:
                sequence_InstanceReferenceValue(context, (InstanceReferenceValue) semanticObject);
                return;
            case InstancePackage.MODE_INSTANCE:
                sequence_ModeInstance(context, (ModeInstance) semanticObject);
                return;
            case InstancePackage.MODE_TRANSITION_INSTANCE:
                sequence_ModeTransitionInstance(context, (ModeTransitionInstance) semanticObject);
                return;
            case InstancePackage.PROPERTY_ASSOCIATION_INSTANCE:
                sequence_PropertyAssociationInstance(context, (PropertyAssociationInstance) semanticObject);
                return;
            case InstancePackage.SYSTEM_INSTANCE:
                sequence_SystemInstance(context, (SystemInstance) semanticObject);
                return;
            case InstancePackage.SYSTEM_OPERATION_MODE:
                sequence_SystemOperationMode(context, (SystemOperationMode) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) ComputedValue(org.osate.aadl2.ComputedValue) Action(org.eclipse.xtext.Action) ClassifierValue(org.osate.aadl2.ClassifierValue) ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) BooleanLiteral(org.osate.aadl2.BooleanLiteral) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) InstanceReferenceValue(org.osate.aadl2.instance.InstanceReferenceValue) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) RecordValue(org.osate.aadl2.RecordValue) ArrayRange(org.osate.aadl2.ArrayRange) NamedValue(org.osate.aadl2.NamedValue) Operation(org.osate.aadl2.Operation) RangeValue(org.osate.aadl2.RangeValue) EPackage(org.eclipse.emf.ecore.EPackage) RealLiteral(org.osate.aadl2.RealLiteral) StringLiteral(org.osate.aadl2.StringLiteral) Parameter(org.eclipse.xtext.Parameter) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 100 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.

the class GenerateTextualInstanceHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {
        new ProgressMonitorDialog(HandlerUtil.getActiveShell(event)).run(true, true, monitor -> {
            monitor.beginTask("Generating Text", 2);
            var sourceFile = (IFile) HandlerUtil.getCurrentStructuredSelection(event).getFirstElement();
            var sourceUri = URI.createPlatformResourceURI(sourceFile.getFullPath().toString(), false);
            var sourceResource = resourceSetProvider.get().getResource(sourceUri, true);
            var destUri = sourceUri.trimFileExtension().appendFileExtension(fileExtensionProvider.getPrimaryFileExtension());
            var destResource = resourceSetProvider.get().createResource(destUri);
            destResource.getContents().add(EcoreUtil.copy(sourceResource.getContents().get(0)));
            destResource.getAllContents().forEachRemaining(eObject -> {
                if (eObject instanceof ComponentInstance && !(eObject instanceof SystemInstance)) {
                    var component = (ComponentInstance) eObject;
                    if (component.getIndices().size() == 1 && component.getIndices().get(0) == 0L) {
                        component.getIndices().clear();
                    }
                }
            });
            try {
                destResource.save(null);
            } catch (IOException e) {
                throw new InvocationTargetException(e);
            }
            monitor.worked(1);
            if (!monitor.isCanceled()) {
                var destFile = sourceFile.getWorkspace().getRoot().getFile(new Path(destUri.toPlatformString(false)));
                HandlerUtil.getActiveShell(event).getDisplay().syncExec(() -> {
                    try {
                        IDE.openEditor(HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(), destFile);
                    } catch (PartInitException e) {
                        throw new RuntimeException(e);
                    }
                });
                monitor.worked(1);
            }
            monitor.done();
        });
    } catch (InvocationTargetException e) {
        var status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Problem generating textual instance: " + e.getMessage(), e);
        StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
    } catch (InterruptedException e) {
    // Do nothing.
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) SystemInstance(org.osate.aadl2.instance.SystemInstance) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) IOException(java.io.IOException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SystemInstance (org.osate.aadl2.instance.SystemInstance)89 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)50 InstanceObject (org.osate.aadl2.instance.InstanceObject)24 ComponentImplementation (org.osate.aadl2.ComponentImplementation)23 Element (org.osate.aadl2.Element)22 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)20 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)16 Classifier (org.osate.aadl2.Classifier)15 NamedElement (org.osate.aadl2.NamedElement)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 EList (org.eclipse.emf.common.util.EList)12 IStatus (org.eclipse.core.runtime.IStatus)10 Status (org.eclipse.core.runtime.Status)10 AadlPackage (org.osate.aadl2.AadlPackage)10 ArrayList (java.util.ArrayList)9 Optional (java.util.Optional)9 Test (org.junit.Test)9 ModeInstance (org.osate.aadl2.instance.ModeInstance)9