use of org.osate.aadl2.PackageSection 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.PackageSection in project osate2 by osate.
the class AadlBusinessObjectProvider method populateChildren.
private static void populateChildren(final PackageSection ps, final Set<Object> children, final ExtensionRegistryService extRegistryService) {
if (ps == null) {
return;
}
children.addAll(ps.getOwnedClassifiers());
for (final AnnexLibrary annexLibrary : ps.getOwnedAnnexLibraries()) {
final NamedElement parsedAnnexLibrary = getParsedAnnexLibrary(annexLibrary);
final boolean specializedHandling = parsedAnnexLibrary != null && extRegistryService.getApplicableBusinessObjectHandler(parsedAnnexLibrary) != null;
// Only contribute the annex object if a BOH for the annex does not exist. The annex plugin is expected to contribute the object as needed.
if (!specializedHandling) {
children.add(annexLibrary);
}
}
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class ClassifierCreationHelper method buildName.
public String buildName(final ClassifierOperationPartType primaryType, final Supplier<AadlPackage> primaryPkgSupplier, final String identifier, final ClassifierOperationPart basePart) {
final String newName;
if (primaryType == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
if (basePart == null) {
throw new RuntimeException("Base operation in invalid");
}
final AadlPackage primaryPkg = primaryPkgSupplier.get();
final PackageSection section = primaryPkg.getPublicSection();
// Determine details about the type specified by the base operation part.
final String baseTypeName;
final AadlPackage typePackage;
// Get the name of the type and the package in which it is contained.
if (ClassifierOperationPartType.isCreate(basePart.getType())) {
typePackage = getResolvedPackage(basePart.getSelectedPackage());
baseTypeName = basePart.getIdentifier();
} else if (basePart.getType() == ClassifierOperationPartType.EXISTING) {
final Classifier classifier = getResolvedClassifier(basePart.getSelectedClassifier());
final ComponentType ct = getResolvedComponentType(classifier);
if (ct == null) {
return null;
}
typePackage = getPackage(ct);
baseTypeName = ct.getName();
} else {
throw new RuntimeException("Invalid base operation part: " + basePart.getType());
}
// Handle type not being in same package as implementation
final boolean samePackage = AadlNameUtil.namesAreEqual(primaryPkg, typePackage);
final String localBaseTypeName = samePackage ? baseTypeName : getRenamedType(section, typePackage, baseTypeName).aliasName;
newName = localBaseTypeName + "." + identifier;
} else {
newName = identifier;
}
return newName;
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class ClassifierCreationHelper method getRenamedType.
// Gets the name to use to reference a type from a specified section in another package.
public RenamedTypeDetails getRenamedType(final PackageSection section, final AadlPackage typePackage, final String baseTypeName) {
final String qualifiedTypeName = typePackage.getQualifiedName() + "::" + baseTypeName;
// Look for an existing component type renames
for (final ComponentTypeRename ctr : section.getOwnedComponentTypeRenames()) {
if (AadlNameUtil.namesAreEqual(ctr.getRenamedComponentType().getQualifiedName(), qualifiedTypeName) && ctr.getName() != null) {
return new RenamedTypeDetails(ctr.getName(), true);
}
}
final String baseAlias = qualifiedTypeName.replace("::", "_");
return new RenamedTypeDetails(AadlNamingUtil.buildUniqueIdentifier(section, baseAlias), false);
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class PropertiesValidator method checkPropertySetElementReferenceForPackageProperties.
public void checkPropertySetElementReferenceForPackageProperties(NamedElement pse, Element context) {
if (Aadl2Util.isNull(pse)) {
return;
}
PropertySet referenceNS = (PropertySet) AadlUtil.getContainingTopLevelNamespace(pse);
PackageSection containingPackageSection = EcoreUtil2.getContainerOfType(context, PackageSection.class);
if (containingPackageSection == null) {
AadlPackage aadlPackage = EcoreUtil2.getContainerOfType(context, AadlPackage.class);
EList<ModelUnit> importedPropertySets = null;
PackageSection packageSection = aadlPackage.getPublicSection();
if (packageSection == null) {
packageSection = aadlPackage.getPrivateSection();
}
if (packageSection != null) {
importedPropertySets = packageSection.getImportedUnits();
for (ModelUnit importedPropertySet : importedPropertySets) {
if (importedPropertySet instanceof PropertySet && !importedPropertySet.eIsProxy() && (importedPropertySet == referenceNS || (referenceNS.getQualifiedName().equalsIgnoreCase(importedPropertySet.getQualifiedName())))) {
return;
}
}
}
if (packageSection != null) {
error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null, MISSING_WITH, referenceNS.getName(), EcoreUtil.getURI(referenceNS).toString(), EcoreUtil.getURI(packageSection).toString());
} else {
error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null);
}
}
}
Aggregations