Search in sources :

Example 31 with PackageSection

use of org.osate.aadl2.PackageSection in project osate2 by osate.

the class PropertiesValidator method checkClassifierReferenceInWith.

public void checkClassifierReferenceInWith(Classifier cl, Element context) {
    if (Aadl2Util.isNull(cl)) {
        return;
    }
    Namespace contextNS = AadlUtil.getContainingTopLevelNamespace(context);
    PackageSection referenceNS = (PackageSection) AadlUtil.getContainingTopLevelNamespace(cl);
    if (contextNS != referenceNS) {
        AadlPackage referencePackage = AadlUtil.getContainingPackage(referenceNS);
        if (!AadlUtil.isImportedPackage(referencePackage, contextNS)) {
            error("The referenced package '" + referencePackage.getName() + "' of classifier '" + cl.getName() + "' is not listed in a with clause.", context, null, MISSING_WITH, referencePackage.getName(), EcoreUtil.getURI(referencePackage).toString(), EcoreUtil.getURI(contextNS).toString());
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) Namespace(org.osate.aadl2.Namespace)

Example 32 with PackageSection

use of org.osate.aadl2.PackageSection in project osate2 by osate.

the class OrganizeWithHandler method findMissingWiths.

private List<ModelUnit> findMissingWiths(PackageSection pkgSection) {
    List<ModelUnit> currentWiths = pkgSection.getImportedUnits();
    List<ModelUnit> missingWiths = new ArrayList<ModelUnit>();
    TreeIterator<EObject> packageContents = pkgSection.eAllContents();
    while (packageContents.hasNext()) {
        EObject nextObject = packageContents.next();
        EList<EObject> crossReferences = nextObject.eCrossReferences();
        for (EObject crossReference : crossReferences) {
            EObject container = crossReference.eContainer();
            while (container != null) {
                if ((container instanceof PropertySet || container instanceof AadlPackage) && (!AadlUtil.isPredeclaredPropertySet(((ModelUnit) container).getName())) && (!((ModelUnit) container).equals(pkgSection.eContainer()))) {
                    if (!currentWiths.contains(container) && !missingWiths.contains(container)) {
                        missingWiths.add((ModelUnit) container);
                    }
                }
                container = container.eContainer();
            }
        }
    }
    return missingWiths;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) ModelUnit(org.osate.aadl2.ModelUnit) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) PropertySet(org.osate.aadl2.PropertySet)

Example 33 with PackageSection

use of org.osate.aadl2.PackageSection in project osate2 by osate.

the class OrganizeWithHandler method organizeWithClauses.

private void organizeWithClauses(PackageSection pkgSection) {
    List<ModelUnit> workingImportedUnits = new ArrayList<ModelUnit>();
    for (ModelUnit nextImportedUnit : pkgSection.getImportedUnits()) {
        workingImportedUnits.add(nextImportedUnit);
    }
    List<ModelUnit> unusedImportedUnits = getUnusedWiths(pkgSection);
    workingImportedUnits.removeAll(unusedImportedUnits);
    List<ModelUnit> missingWiths = findMissingWiths(pkgSection);
    workingImportedUnits.addAll(missingWiths);
    Collections.sort(workingImportedUnits, new Comparator<ModelUnit>() {

        @Override
        public int compare(ModelUnit obj1, ModelUnit obj2) {
            return obj1.getName().toLowerCase().compareTo(obj2.getName().toLowerCase());
        }
    });
    pkgSection.getImportedUnits().removeAll(pkgSection.getImportedUnits());
    pkgSection.getImportedUnits().addAll(workingImportedUnits);
}
Also used : ModelUnit(org.osate.aadl2.ModelUnit) ArrayList(java.util.ArrayList)

Example 34 with PackageSection

use of org.osate.aadl2.PackageSection in project osate2 by osate.

the class SetFeatureClassifierPropertySection method setFeatureClassifier.

private static void setFeatureClassifier(final NamedElement feature, final Object classifier) {
    if (classifier != null) {
        // Import its package if necessary
        final AadlPackage pkg = (AadlPackage) feature.getElementRoot();
        if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
            final PackageSection section = pkg.getPublicSection();
            final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
            if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
                AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
            }
        }
        // If the feature is an abstract feature, need to reset the feature prototype. Only a prototype or a classifier may be set.
        if (feature instanceof AbstractFeature) {
            ((AbstractFeature) feature).setFeaturePrototype(null);
        }
    }
    final FeatureClassifierMetadata setterInfo = featureTypeToMetadataMap.get(feature.eClass());
    try {
        final Method method = feature.getClass().getMethod(setterInfo.setterName, setterInfo.classifierClass);
        method.invoke(feature, classifier);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) AbstractFeature(org.osate.aadl2.AbstractFeature) AbstractFeatureClassifier(org.osate.aadl2.AbstractFeatureClassifier) Classifier(org.osate.aadl2.Classifier) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) BusFeatureClassifier(org.osate.aadl2.BusFeatureClassifier) FeatureClassifier(org.osate.aadl2.FeatureClassifier) DataClassifier(org.osate.aadl2.DataClassifier) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 35 with PackageSection

use of org.osate.aadl2.PackageSection in project osate2 by osate.

the class PasteAction method ensureBusinessObjectHasUniqueName.

/**
 * If the element is renameable and the name can be validated, then generate a name that passes validation.
 * Otherwise, do not change the element's name. Contains special handling for component implementations.
 * @param bo
 * @param boHandler
 */
private static void ensureBusinessObjectHasUniqueName(final EObject bo, final BusinessObjectHandler boHandler) {
    if (supportsRenaming(bo, boHandler) && boHandler.canRename(new CanRenameContext(bo))) {
        // Determine the current name of the business object.
        final String originalName = boHandler.getNameForRenaming(new GetNameContext(bo));
        // contain the component type / component type alias appropriate for the destination package.
        if (bo instanceof ComponentImplementation) {
            final ComponentImplementation ci = (ComponentImplementation) bo;
            final ComponentType ct = ci.getType();
            final ClassifierCreationHelper classifierCreationHelper = new ClassifierCreationHelper(ci.eResource().getResourceSet());
            final String ciTypeName;
            if (ct == null) {
                ciTypeName = ci.getTypeName();
            } else {
                if (!AadlNameUtil.namesAreEqual(ci.getNamespace(), ct.getNamespace())) {
                    if (!(ci.getNamespace() instanceof PackageSection)) {
                        throw new RuntimeException("New component implementation is not contained in a package section");
                    }
                    final PackageSection section = (PackageSection) ci.getNamespace();
                    // Import the package if necessary
                    final AadlPackage typePkg = (AadlPackage) ct.getNamespace().getOwner();
                    AadlImportsUtil.addImportIfNeeded(section, typePkg);
                    // Create an alias for the component type
                    final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, typePkg, ct.getName());
                    if (!aliasDetails.exists) {
                        final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
                        ctr.setName(aliasDetails.aliasName);
                        ctr.setCategory(ct.getCategory());
                        ctr.setRenamedComponentType(ct);
                    }
                    ciTypeName = aliasDetails.aliasName;
                } else {
                    ciTypeName = ct.getName();
                }
            }
            setName(bo, boHandler, ciTypeName + ".osate_ge_temporary_name_00001");
        } else {
            // Set name to dummy name so that validate name will work as expected. Many implementations
            // of validate name check if the name has changed.
            setName(bo, boHandler, "");
        }
        // Determine a new name for the business object
        final String baseName = originalName;
        String newName = originalName;
        int count = 1;
        while (true) {
            final String result = RenameUtil.checkNewNameValidity(bo, boHandler, newName);
            if (result == null) {
                break;
            }
            newName = baseName + "_copy" + (count == 1 ? "" : Integer.toString(count));
            count++;
        }
        // specified value does not include the type name.
        if (bo instanceof ComponentImplementation) {
            newName = ((ComponentImplementation) bo).getTypeName() + "." + newName;
        }
        // Update the business object's name
        setName(bo, boHandler, newName);
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) GetNameContext(org.osate.ge.businessobjecthandling.GetNameContext) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename) CanRenameContext(org.osate.ge.businessobjecthandling.CanRenameContext) Point(org.osate.ge.graphics.Point)

Aggregations

PackageSection (org.osate.aadl2.PackageSection)24 AadlPackage (org.osate.aadl2.AadlPackage)19 Classifier (org.osate.aadl2.Classifier)14 NamedElement (org.osate.aadl2.NamedElement)9 PropertySet (org.osate.aadl2.PropertySet)9 EObject (org.eclipse.emf.ecore.EObject)8 ModelUnit (org.osate.aadl2.ModelUnit)7 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 ComponentImplementation (org.osate.aadl2.ComponentImplementation)5 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 PropertyType (org.osate.aadl2.PropertyType)3 PublicPackageSection (org.osate.aadl2.PublicPackageSection)3 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)3 List (java.util.List)2