Search in sources :

Example 1 with SUBPROGRAM

use of org.osate.aadl2.ComponentCategory.SUBPROGRAM in project osate2 by osate.

the class DefaultSelectSubprogramDialogModel method getSubprograms.

@Override
public List<Object> getSubprograms(final Object context) {
    // Build a list of subprograms
    final List<Object> subprograms = new ArrayList<Object>();
    // Data/Subprogram Group/Abstract Type
    if (context instanceof IEObjectDescription) {
        final IEObjectDescription desc = (IEObjectDescription) context;
        final Classifier contextClassifier = (Classifier) (desc.getEObjectOrProxy().eIsProxy() ? (Classifier) EcoreUtil.resolve(desc.getEObjectOrProxy(), bi.eResource()) : desc.getEObjectOrProxy());
        if (!contextClassifier.eIsProxy()) {
            for (final Feature tmpFeature : contextClassifier.getAllFeatures()) {
                if (tmpFeature instanceof SubprogramAccess) {
                    // Provides Subprogram Access
                    if (((SubprogramAccess) tmpFeature).getKind() == AccessType.PROVIDES) {
                        subprograms.add(tmpFeature);
                    }
                }
            }
        }
    } else if (context instanceof SubprogramGroupAccess) {
        // Requires Subprogram Group Access
        // Only subprogram group accesses with kind = Requires and which has a subprogram group classifier should be in the context list
        // Provides Subprogram Access
        final SubprogramGroupClassifier spgClassifier = (SubprogramGroupClassifier) ((SubprogramGroupAccess) context).getAllClassifier();
        addProvidesSubprogramAccessesForComponentClassifier(spgClassifier, subprograms);
    } else if (context instanceof FeatureGroup) {
        // Feature Group
        final FeatureGroup fg = (FeatureGroup) context;
        // Requires subprogram Access if not inverse and Provides subprogram access if is inverse
        final boolean inverted = fg.isInverse();
        for (final Feature tmpFeature : AadlFeatureUtil.getAllFeatures(fg.getAllFeatureGroupType())) {
            if (tmpFeature instanceof SubprogramAccess) {
                final AccessType accessKind = ((SubprogramAccess) tmpFeature).getKind();
                if ((!inverted && accessKind == AccessType.REQUIRES) || (inverted && accessKind == AccessType.PROVIDES)) {
                    subprograms.add(tmpFeature);
                }
            }
        }
    } else if (context instanceof SubprogramGroupSubcomponent) {
        // Subprogram Group Subcomponent
        // Provides Subprogram
        addProvidesSubprogramAccessesForComponentClassifier(((SubprogramGroupSubcomponent) context).getAllClassifier(), subprograms);
    } else if (context == processorContext) {
        // Subprogram Proxy
        for (final ProcessorFeature processorFeature : AgeAadlUtil.getAllProcessorFeatures(bi)) {
            if (processorFeature instanceof SubprogramProxy) {
                subprograms.add(processorFeature);
            }
        }
    } else if (context == nullContext) {
        // Null Context
        // Subprogram classifier reference
        final Aadl2Package aadl2Package = Aadl2Package.eINSTANCE;
        for (final IEObjectDescription desc : AadlModelAccessUtil.getAllEObjectsByType(bi.eResource(), aadl2Package.getComponentClassifier())) {
            // Add objects that have care either types or implementations of the same category as the classifier type
            final EClass classifierEClass = desc.getEClass();
            if (aadl2Package.getSubprogramClassifier().isSuperTypeOf(classifierEClass)) {
                subprograms.add(desc);
            }
        }
        // Requires Subprogram Access
        for (final Feature tmpFeature : bi.getAllFeatures()) {
            if (tmpFeature instanceof SubprogramAccess && ((SubprogramAccess) tmpFeature).getKind() == AccessType.REQUIRES) {
                subprograms.add(tmpFeature);
            }
        }
        // Subprogram Subcomponent
        for (final Subcomponent tmpSc : bi.getAllSubcomponents()) {
            if (tmpSc instanceof SubprogramSubcomponent) {
                subprograms.add(tmpSc);
            }
        }
        // Subprogram Prototype
        for (final Prototype prototype : bi.getAllPrototypes()) {
            if (prototype instanceof SubprogramPrototype) {
                subprograms.add(prototype);
            }
        }
    }
    return Collections.unmodifiableList(subprograms);
}
Also used : FeatureGroup(org.osate.aadl2.FeatureGroup) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) Prototype(org.osate.aadl2.Prototype) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) ArrayList(java.util.ArrayList) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramGroupClassifier(org.osate.aadl2.SubprogramGroupClassifier) Feature(org.osate.aadl2.Feature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) EClass(org.eclipse.emf.ecore.EClass) SubprogramProxy(org.osate.aadl2.SubprogramProxy) SubprogramAccess(org.osate.aadl2.SubprogramAccess) Aadl2Package(org.osate.aadl2.Aadl2Package) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) ProcessorFeature(org.osate.aadl2.ProcessorFeature) SubprogramPrototype(org.osate.aadl2.SubprogramPrototype) AccessType(org.osate.aadl2.AccessType)

Example 2 with SUBPROGRAM

use of org.osate.aadl2.ComponentCategory.SUBPROGRAM in project osate2 by osate.

the class CreateSubprogramCallSequencePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    final BusinessObjectContext targetBoc = ctx.getTarget();
    final Object targetBo = targetBoc.getBusinessObject();
    if (!getClassifierOpBuilder().canBuildOperation(targetBo)) {
        return Optional.empty();
    }
    // Used to pass arguments between steps
    class CreateArgs {

        final BehavioredImplementation bi;

        final CallContext callContext;

        final CalledSubprogram calledSubprogram;

        public CreateArgs(final BehavioredImplementation bi, final CallContext callContext, final CalledSubprogram calledSubprogram) {
            this.bi = bi;
            this.callContext = callContext;
            this.calledSubprogram = calledSubprogram;
        }
    }
    return Optional.of(Operation.createWithBuilder(createOp -> {
        getClassifierOpBuilder().buildOperation(createOp, targetBo).map(ci -> {
            final BehavioredImplementation bi = (BehavioredImplementation) ci;
            final DefaultSelectSubprogramDialogModel subprogramSelectionModel = new DefaultSelectSubprogramDialogModel(bi);
            final SelectSubprogramDialog dlg = new SelectSubprogramDialog(Display.getCurrent().getActiveShell(), subprogramSelectionModel);
            if (dlg.open() == Window.CANCEL) {
                return StepResult.abort();
            }
            // Get the CallContext and Called Subprogram
            final CallContext callContext = subprogramSelectionModel.getCallContext(dlg.getSelectedContext());
            final CalledSubprogram calledSubprogram = subprogramSelectionModel.getCalledSubprogram(dlg.getSelectedSubprogram());
            return StepResult.forValue(new CreateArgs(bi, callContext, calledSubprogram));
        }).modifyModel(null, (tag, createArgs) -> createArgs.bi, (tag, bi, createArgs) -> {
            final String newScsName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call_sequence");
            final String initialSubprogramCallName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call");
            final SubprogramCallSequence newScs = bi.createOwnedSubprogramCallSequence();
            newScs.setName(newScsName);
            // Create an initial call. Needed because call sequences must have at least one call
            final SubprogramCall initialSubprogramCall = newScs.createOwnedSubprogramCall();
            initialSubprogramCall.setName(initialSubprogramCallName);
            initialSubprogramCall.setContext(createArgs.callContext);
            initialSubprogramCall.setCalledSubprogram(createArgs.calledSubprogram);
            AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.callContext);
            AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.calledSubprogram);
            return StepResultBuilder.create().showNewBusinessObject(targetBoc, newScs).build();
        });
    }));
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) AadlOperationBuilder(org.osate.ge.aadl2.ui.AadlOperationBuilder) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) ComponentImplementation(org.osate.aadl2.ComponentImplementation) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Display(org.eclipse.swt.widgets.Display) CalledSubprogram(org.osate.aadl2.CalledSubprogram) Window(org.eclipse.jface.window.Window) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) AadlCategories(org.osate.ge.aadl2.AadlCategories) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) CallContext(org.osate.aadl2.CallContext) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCall(org.osate.aadl2.SubprogramCall) Aadl2Package(org.osate.aadl2.Aadl2Package) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) DefaultSelectSubprogramDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultSelectSubprogramDialogModel) BehavioredImplementation(org.osate.aadl2.BehavioredImplementation) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) BusinessObjectContext(org.osate.ge.BusinessObjectContext) CallContext(org.osate.aadl2.CallContext) CalledSubprogram(org.osate.aadl2.CalledSubprogram) SubprogramCall(org.osate.aadl2.SubprogramCall) SelectSubprogramDialog(org.osate.ge.aadl2.ui.internal.dialogs.SelectSubprogramDialog)

Example 3 with SUBPROGRAM

use of org.osate.aadl2.ComponentCategory.SUBPROGRAM in project osate2 by osate.

the class AadlClassifierUtil method getComponentImplementationEClass.

public static EClass getComponentImplementationEClass(final ComponentCategory cc) {
    Objects.requireNonNull(cc, "cc must not be null");
    final Aadl2Package p = Aadl2Package.eINSTANCE;
    switch(cc) {
        case ABSTRACT:
            return p.getAbstractImplementation();
        case BUS:
            return p.getBusImplementation();
        case DATA:
            return p.getDataImplementation();
        case DEVICE:
            return p.getDeviceImplementation();
        case MEMORY:
            return p.getMemoryImplementation();
        case PROCESS:
            return p.getProcessImplementation();
        case PROCESSOR:
            return p.getProcessorImplementation();
        case SUBPROGRAM:
            return p.getSubprogramImplementation();
        case SUBPROGRAM_GROUP:
            return p.getSubprogramGroupImplementation();
        case SYSTEM:
            return p.getSystemImplementation();
        case THREAD:
            return p.getThreadImplementation();
        case THREAD_GROUP:
            return p.getThreadGroupImplementation();
        case VIRTUAL_BUS:
            return p.getVirtualBusImplementation();
        case VIRTUAL_PROCESSOR:
            return p.getVirtualProcessorImplementation();
        default:
            throw new RuntimeException("Unexpected category: " + cc);
    }
}
Also used : Aadl2Package(org.osate.aadl2.Aadl2Package)

Example 4 with SUBPROGRAM

use of org.osate.aadl2.ComponentCategory.SUBPROGRAM in project osate2 by osate.

the class AadlClassifierUtil method getComponentTypeEClass.

public static EClass getComponentTypeEClass(final ComponentCategory cc) {
    Objects.requireNonNull(cc, "cc must not be null");
    final Aadl2Package p = Aadl2Package.eINSTANCE;
    switch(cc) {
        case ABSTRACT:
            return p.getAbstractType();
        case BUS:
            return p.getBusType();
        case DATA:
            return p.getDataType();
        case DEVICE:
            return p.getDeviceType();
        case MEMORY:
            return p.getMemoryType();
        case PROCESS:
            return p.getProcessType();
        case PROCESSOR:
            return p.getProcessorType();
        case SUBPROGRAM:
            return p.getSubprogramType();
        case SUBPROGRAM_GROUP:
            return p.getSubprogramGroupType();
        case SYSTEM:
            return p.getSystemType();
        case THREAD:
            return p.getThreadType();
        case THREAD_GROUP:
            return p.getThreadGroupType();
        case VIRTUAL_BUS:
            return p.getVirtualBusType();
        case VIRTUAL_PROCESSOR:
            return p.getVirtualProcessorType();
        default:
            throw new RuntimeException("Unexpected category: " + cc);
    }
}
Also used : Aadl2Package(org.osate.aadl2.Aadl2Package)

Example 5 with SUBPROGRAM

use of org.osate.aadl2.ComponentCategory.SUBPROGRAM in project osate2 by osate.

the class InstanceModelUtil method getHardwareComponent.

/**
 * return the hardware component of the connection instance end.
 * If it is a hardware component or device return it.
 * If it is a software component, return the processor it is bound to.
 * If it is a component instance (BUS), return the bus
 * If it is a DATA, SUBPROGRAM, or SUBPROGRAM GROUP component instance, then return the memory it is bound to.
 * @param cie
 * @return hw component instance
 */
public static ComponentInstance getHardwareComponent(ConnectionInstanceEnd cie) {
    ComponentInstance swci = null;
    if (cie instanceof FeatureInstance) {
        FeatureInstance fi = (FeatureInstance) cie;
        swci = fi.getContainingComponentInstance();
    } else if (cie instanceof ComponentInstance) {
        swci = (ComponentInstance) cie;
    }
    if (isDevice(swci) || isProcessor(swci) || isBus(swci) || isMemory(swci)) {
        return swci;
    }
    return getBoundPhysicalProcessor(swci);
}
Also used : FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Aggregations

Classifier (org.osate.aadl2.Classifier)8 ComponentClassifier (org.osate.aadl2.ComponentClassifier)8 Feature (org.osate.aadl2.Feature)8 NamedElement (org.osate.aadl2.NamedElement)7 Subcomponent (org.osate.aadl2.Subcomponent)7 DataClassifier (org.osate.aadl2.DataClassifier)6 FeatureGroup (org.osate.aadl2.FeatureGroup)6 SubprogramCall (org.osate.aadl2.SubprogramCall)6 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)6 ArrayList (java.util.ArrayList)5 Aadl2Package (org.osate.aadl2.Aadl2Package)5 ComponentCategory (org.osate.aadl2.ComponentCategory)5 ComponentImplementation (org.osate.aadl2.ComponentImplementation)5 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)5 List (java.util.List)4 Connection (org.osate.aadl2.Connection)4 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)4 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)4 Collectors (java.util.stream.Collectors)3 EObject (org.eclipse.emf.ecore.EObject)3