Search in sources :

Example 11 with PackageSection

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

the class PropertiesLinkingService method resolvePackageRename.

/**
 * resolve package name by looking it up in PackageRename
 * @param name package name
 * @param context Package section with rename declarations
 * @return aadl package or null
 */
public AadlPackage resolvePackageRename(String name, PackageSection context) {
    AadlPackage searchResult = resolvePackageRename(name, context.getOwnedPackageRenames());
    if (searchResult == null && context instanceof PrivatePackageSection && ((AadlPackage) context.eContainer()).getPublicSection() != null) {
        PublicPackageSection pubsec = ((AadlPackage) context.eContainer()).getPublicSection();
        searchResult = resolvePackageRename(name, pubsec.getOwnedPackageRenames());
    }
    return searchResult;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PublicPackageSection(org.osate.aadl2.PublicPackageSection) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection)

Example 12 with PackageSection

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

the class AadlImportsUtil method ensurePackageIsImportedForClassifier.

/**
 * Ensure that an element's package has the necessary imports to reference a specified object.
 * Only supports classifiers as the referenced object at this time.
 * If the referenced element is not a classifier, then the method does not perform any changes.
 * @param pkgContext is the object that needs to reference the containing object
 * @param referencedObject is the object which needs to be referenced.
 */
public static void ensurePackageIsImportedForClassifier(final Element pkgContext, final Object referencedObject) {
    final AadlPackage referencingPkg = (AadlPackage) pkgContext.getElementRoot();
    if (referencingPkg == null) {
        return;
    }
    final PackageSection referencingSection = referencingPkg.getPublicSection();
    if (referencedObject instanceof Classifier) {
        Classifier referencedClassifier = (Classifier) referencedObject;
        if (referencedClassifier.eIsProxy()) {
            referencedClassifier = (Classifier) EcoreUtil.resolve(referencedClassifier, pkgContext.eResource());
        }
        if (referencedClassifier.getNamespace() != null && referencedClassifier.getNamespace().getOwner() instanceof AadlPackage) {
            final AadlPackage referencedPkg = (AadlPackage) referencedClassifier.getNamespace().getOwner();
            addImportIfNeeded(referencingSection, referencedPkg);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) Classifier(org.osate.aadl2.Classifier)

Example 13 with PackageSection

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

the class AadlImportsUtil method addImportIfNeeded.

/**
 * Adds an import for a package to section if it is not already imported.
 * @param section the package section which is importing the package
 * @param importedPkg the package to import
 */
public static void addImportIfNeeded(final PackageSection section, final AadlPackage importedPkg) {
    final String pkgQualifiedName = importedPkg.getQualifiedName();
    if (pkgQualifiedName == null) {
        return;
    }
    // Don't do anything if the package is the owner of the section
    if (section.getOwner() instanceof AadlPackage && pkgQualifiedName.equalsIgnoreCase(((AadlPackage) section.getOwner()).getQualifiedName())) {
        return;
    }
    // 
    boolean isImported = false;
    for (final ModelUnit mu : section.getImportedUnits()) {
        final String qn = mu.getQualifiedName();
        if (pkgQualifiedName.equalsIgnoreCase(qn)) {
            isImported = true;
            break;
        }
    }
    // Import the package if needed
    if (!isImported) {
        section.getImportedUnits().add(importedPkg);
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) ModelUnit(org.osate.aadl2.ModelUnit)

Example 14 with PackageSection

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

the class AadlBaNameResolver method qualifiedNamedElementResolver.

private boolean qualifiedNamedElementResolver(QualifiedNamedElement qne, boolean hasToReport) {
    String packageName = null;
    EObject ne;
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        packageName = qne.getBaNamespace().getId();
    }
    // Now check the type in each current package's sections.
    for (PackageSection context : _contextsTab) {
        NamedElement parent = (NamedElement) _ba.eContainer().eContainer();
        ne = Aadl2Visitors.findSubcomponentInComponent((Classifier) parent, qne.getBaName().getId());
        if (ne == null) {
            ne = Aadl2Visitors.findFeatureInComponent((Classifier) parent, qne.getBaName().getId());
        }
        if (ne == null) {
            ne = Aadl2Visitors.findElementInPackage(qne.getBaName().getId(), packageName, context);
        }
        if (ne == null) {
            ne = Aadl2Visitors.findElementInPropertySet(qne.getBaName().getId(), packageName, context);
        }
        // An element is found.
        if (ne != null && ne instanceof NamedElement) {
            // Links unique component classifier reference with named element found.
            qne.setOsateRef((Element) ne);
            qne.getBaName().setOsateRef((Element) ne);
            if (hasNamespace) {
                qne.getBaNamespace().setOsateRef(((NamedElement) ne).getNamespace());
            }
            return true;
        }
    }
    // The element is not found.
    if (hasToReport) {
        StringBuilder qualifiedName = new StringBuilder();
        if (hasNamespace) {
            qualifiedName.append(qne.getBaNamespace().getId());
            qualifiedName.append("::");
        }
        qualifiedName.append(qne.getBaName().getId());
        reportNameError(qne, qualifiedName.toString());
    }
    return false;
}
Also used : PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 15 with PackageSection

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

the class AadlBaNameResolver method timeUnitResolver.

// Checks behavior time's time unit according to property set Time_Units and
// binds if checking is successful.
private boolean timeUnitResolver(Identifier unitIdentifier) {
    PackageSection context = Aadl2Visitors.getContainingPackageSection(_ba);
    NamedElement pt = Aadl2Visitors.findElementInPropertySet(TIME_UNITS_PROPERTY_ID, TIME_UNITS_PROPERTY_SET, context);
    // Property set Time_Units is found.
    if (pt instanceof org.osate.aadl2.UnitsType) {
        org.osate.aadl2.UnitsType ut = (org.osate.aadl2.UnitsType) pt;
        // Find the given time unit in the enumeration.
        org.osate.aadl2.UnitLiteral ul = ut.findLiteral(unitIdentifier.getId());
        // The given time unit is found.
        if (ul != null) {
            unitIdentifier.setOsateRef(ul);
            return true;
        } else {
            _errManager.error(unitIdentifier, unitIdentifier.getId() + " is not a valid time unit according " + "to the property set Time_Units.");
            return false;
        }
    } else {
        _errManager.error(unitIdentifier, "Property set Time_Units is not found");
        return false;
    }
}
Also used : UnitLiteral(org.osate.aadl2.UnitLiteral) PackageSection(org.osate.aadl2.PackageSection) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

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