use of org.osate.aadl2.ComponentType 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.ComponentType in project osate2 by osate.
the class TypeExtensionImpl method setExtended.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setExtended(ComponentType newExtended) {
ComponentType oldExtended = extended;
extended = newExtended;
if (eNotificationRequired()) {
eNotify(new ENotificationImpl(this, Notification.SET, Aadl2Package.TYPE_EXTENSION__EXTENDED, oldExtended, extended));
}
}
use of org.osate.aadl2.ComponentType in project osate2 by osate.
the class ModeImpl method getPropertyValueInternal.
// Cannot make this final because I need to override in SystemOperationMode
public void getPropertyValueInternal(final Property prop, final PropertyAcc pas, final boolean fromInstanceSlaveCall, final boolean all) throws InvalidModelException {
final Classifier owner = getContainingClassifier();
final boolean inType = (owner instanceof ComponentType);
// local contained value
if (!inType && !fromInstanceSlaveCall) {
// owner could be null if we are looking up a property on a SystemOperationMode, which does not have a containing classifier.
if (owner != null && pas.addLocalContained(this, owner)) {
if (!all) {
return;
}
}
}
// local value
if (pas.addLocal(this)) {
if (!all) {
return;
}
}
// not an implementation
if ((inType || !inType && !fromInstanceSlaveCall) && prop.isInherit()) {
if (owner != null) {
owner.getPropertyValueInternal(prop, pas, fromInstanceSlaveCall, all);
} else {
throw new InvalidModelException(this, "Mode is not contained in a component type or implementation");
}
}
}
use of org.osate.aadl2.ComponentType in project osate2 by osate.
the class AnnexHandler method getAnnexSubclauseIndex.
/**
* Returns a 0 based index for referencing an annex subclause in a list that contains only annex subclauses with the same type and owner
* @return
*/
public static int getAnnexSubclauseIndex(AnnexSubclause annexSubclause, final boolean useExtended) {
// Get the default annex library if a parsed annex subclause was specified. This is needed for the comparison later in the function.
if (!(annexSubclause instanceof DefaultAnnexSubclause)) {
if (annexSubclause.eContainer() instanceof DefaultAnnexSubclause) {
annexSubclause = (AnnexSubclause) annexSubclause.eContainer();
} else {
return -1;
}
}
final String annexName = annexSubclause.getName();
if (annexName == null) {
return -1;
}
final Classifier cl = annexSubclause.getContainingClassifier();
final List<Classifier> classifiers;
if (useExtended) {
classifiers = cl.getSelfPlusAllExtended();
// Get all related classifiers
if (cl instanceof ComponentImplementation) {
final ComponentType ct = ((ComponentImplementation) cl).getType();
if (ct != null) {
classifiers.addAll(ct.getSelfPlusAllExtended());
}
}
} else {
classifiers = Arrays.asList(cl);
}
int index = 0;
// Use reversed view of list so that base classifiers will be first. This is needed to ensure subclauses have unique indices
for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
for (final AnnexSubclause tmpSubclause : tmpClassifier.getOwnedAnnexSubclauses()) {
if (tmpSubclause == annexSubclause) {
return index;
} else if (annexName.equalsIgnoreCase(tmpSubclause.getName())) {
index++;
}
}
}
return -1;
}
use of org.osate.aadl2.ComponentType 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