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);
}
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();
});
}));
}
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);
}
}
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);
}
}
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);
}
Aggregations