use of org.osate.aadl2.Feature 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.Feature in project osate2 by osate.
the class CreateGeneralizationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
final Object readonlySubtype = ctx.getSource().getBusinessObject();
final Classifier supertype = ctx.getDestination().getBusinessObject(Classifier.class).orElse(null);
// Ensure they are valid and are not the same
if (readonlySubtype == null || supertype == null || readonlySubtype == supertype) {
return Optional.empty();
}
// Rules:
// Abstract types can be extended by any type.
// Types can be extended by other types in their category
// Implementations can extend other implementations with same category and abstract implementation in some cases.
// Feature Group Types can extend other feature group types
final boolean canCreate = (readonlySubtype instanceof ComponentType && (supertype instanceof AbstractType || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof ComponentImplementation && (supertype instanceof AbstractImplementation || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof FeatureGroupType && supertype instanceof FeatureGroupType);
if (!canCreate) {
return Optional.empty();
}
return Operation.createSimple(ctx.getSource(), Classifier.class, subtype -> {
// Import the package if necessary
if (subtype.getNamespace() instanceof PackageSection && subtype.getNamespace().getOwner() instanceof AadlPackage && supertype.getNamespace() instanceof PackageSection && supertype.getNamespace().getOwner() instanceof AadlPackage) {
final PackageSection subtypeSection = (PackageSection) subtype.getNamespace();
final AadlPackage supertypePackage = (AadlPackage) supertype.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(subtypeSection, supertypePackage);
}
// Create the generalization
final Object newBo;
if (subtype instanceof ComponentType) {
final ComponentType ct = (ComponentType) subtype;
final TypeExtension te = ct.createOwnedExtension();
te.setExtended((ComponentType) supertype);
newBo = te;
} else if (subtype instanceof ComponentImplementation) {
final ComponentImplementation ci = (ComponentImplementation) subtype;
final ImplementationExtension ie = ci.createOwnedExtension();
ie.setExtended((ComponentImplementation) supertype);
newBo = ie;
} else if (subtype instanceof FeatureGroupType) {
final FeatureGroupType fgt = (FeatureGroupType) subtype;
final GroupExtension ge = fgt.createOwnedExtension();
ge.setExtended((FeatureGroupType) supertype);
newBo = ge;
} else {
return StepResult.abort();
}
return StepResultBuilder.create().showNewBusinessObject(ctx.getSource(), newBo).build();
});
}
use of org.osate.aadl2.Feature in project osate2 by osate.
the class AadlGraphics method getFeatureGraphic.
public static FeatureGraphic getFeatureGraphic(final EClass featureClass, DirectionType direction) {
final FeatureGraphicBuilder builder = FeatureGraphicBuilder.create();
// Configure the feature type
final Aadl2Package aadl2Pkg = Aadl2Package.eINSTANCE;
if (featureClass == aadl2Pkg.getAbstractFeature()) {
builder.abstractFeature();
} else if (featureClass == aadl2Pkg.getEventPort()) {
builder.eventPort();
} else if (featureClass == aadl2Pkg.getDataPort() || featureClass == aadl2Pkg.getParameter()) {
builder.dataPort();
} else if (featureClass == aadl2Pkg.getEventDataPort()) {
builder.eventDataPort();
} else if (featureClass == aadl2Pkg.getSubprogramAccess()) {
builder.subprogramAccess();
} else if (featureClass == aadl2Pkg.getSubprogramGroupAccess()) {
builder.subprogramGroupAccess();
} else if (featureClass == aadl2Pkg.getDataAccess()) {
builder.dataAccess();
} else if (featureClass == aadl2Pkg.getBusAccess()) {
builder.busAccess();
} else if (featureClass == aadl2Pkg.getFeatureGroup()) {
builder.featureGroup();
} else if (featureClass == aadl2Pkg.getPortProxy()) {
builder.portProxy();
} else if (featureClass == aadl2Pkg.getEventSource()) {
builder.eventSource();
} else if (featureClass == aadl2Pkg.getEventDataSource()) {
builder.eventDataSource();
} else if (featureClass == aadl2Pkg.getSubprogramProxy()) {
builder.subprogramProxy();
}
switch(direction) {
case IN:
builder.input();
break;
case OUT:
builder.output();
break;
case IN_OUT:
builder.bidirectional();
break;
}
return builder.build();
}
use of org.osate.aadl2.Feature in project osate2 by osate.
the class FeatureHandler method getGraphicalConfiguration.
@Override
public Optional<GraphicalConfiguration> getGraphicalConfiguration(final GetGraphicalConfigurationContext ctx) {
final BusinessObjectContext featureBoc = ctx.getBusinessObjectContext();
final NamedElement feature = featureBoc.getBusinessObject(NamedElement.class).get();
final FeatureGraphic graphic = getGraphicalRepresentation(feature, featureBoc);
return Optional.of(GraphicalConfigurationBuilder.create().graphic(graphic).annotation(AadlGraphics.getFeatureAnnotation(feature.eClass())).style(StyleBuilder.create(AadlInheritanceUtil.isInherited(featureBoc) ? Styles.INHERITED_ELEMENT : Style.EMPTY).backgroundColor(AadlGraphics.getDefaultBackgroundColor(graphic.featureType)).labelsAboveTop().labelsLeft().build()).defaultDockingPosition(getDefaultDockingPosition(feature, featureBoc)).build());
}
use of org.osate.aadl2.Feature in project osate2 by osate.
the class AgeRenameParticipant method getDependentObjects.
private static Set<EObject> getDependentObjects(final EObject obj, final ResourceSet rs, final Map<URI, Set<URI>> externalReferencesMap) {
final Set<EObject> results = new HashSet<>();
final EObject objectOfInterest;
// is the only known way of getting types related to the renames.
if (obj instanceof ComponentTypeRename) {
final ComponentType renamedComponentType = ((ComponentTypeRename) obj).getRenamedComponentType();
objectOfInterest = renamedComponentType == null ? null : renamedComponentType;
} else {
objectOfInterest = obj;
}
if (objectOfInterest != null) {
getRelatedObjects(Collections.singleton(objectOfInterest), rs, results, externalReferencesMap, obj instanceof Feature);
}
return results;
}
Aggregations