Search in sources :

Example 1 with PackageSection

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();
    });
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) FeatureGroupType(org.osate.aadl2.FeatureGroupType) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Classifier(org.osate.aadl2.Classifier) AbstractType(org.osate.aadl2.AbstractType) GroupExtension(org.osate.aadl2.GroupExtension) AbstractImplementation(org.osate.aadl2.AbstractImplementation)

Example 2 with PackageSection

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);
        }
    }
}
Also used : DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) NamedElement(org.osate.aadl2.NamedElement)

Example 3 with PackageSection

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;
}
Also used : ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) PublicPackageSection(org.osate.aadl2.PublicPackageSection) Classifier(org.osate.aadl2.Classifier)

Example 4 with PackageSection

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);
}
Also used : ComponentTypeRename(org.osate.aadl2.ComponentTypeRename)

Example 5 with PackageSection

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);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ModelUnit(org.osate.aadl2.ModelUnit) PropertySet(org.osate.aadl2.PropertySet) PropertyType(org.osate.aadl2.PropertyType) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property)

Aggregations

PackageSection (org.osate.aadl2.PackageSection)23 AadlPackage (org.osate.aadl2.AadlPackage)18 Classifier (org.osate.aadl2.Classifier)13 PropertySet (org.osate.aadl2.PropertySet)9 EObject (org.eclipse.emf.ecore.EObject)8 NamedElement (org.osate.aadl2.NamedElement)8 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 ModelUnit (org.osate.aadl2.ModelUnit)6 ClassifierFeature (org.osate.aadl2.ClassifierFeature)4 ComponentType (org.osate.aadl2.ComponentType)4 PrivatePackageSection (org.osate.aadl2.PrivatePackageSection)4 Property (org.osate.aadl2.Property)4 ArrayList (java.util.ArrayList)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 AnnexLibrary (org.osate.aadl2.AnnexLibrary)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 PropertyType (org.osate.aadl2.PropertyType)3 PublicPackageSection (org.osate.aadl2.PublicPackageSection)3 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)3 Stream (java.util.stream.Stream)2