Search in sources :

Example 21 with PackageSection

use of org.osate.aadl2.PackageSection in project osate-plugin by sireum.

the class SmfVisitor method getAllPackages.

private HashSet<SecModelLibrary> getAllPackages(Element root) {
    HashSet<SecModelLibrary> secLibs = new HashSet<SecModelLibrary>();
    // no need of seen set as the circular imports are not allowed
    HashSet<ModelUnit> seens = new HashSet();
    PackageSection ps = AadlUtil.getContainingPackageSection(((SystemInstance) root).getComponentClassifier());
    EList<ComponentImplementation> ais = AadlUtil.getAllComponentImpl();
    Set<ModelUnit> aps = ais.stream().flatMap(it -> AadlUtil.getContainingPackage(it).getPublicSection().getImportedUnits().stream()).collect(Collectors.toSet());
    Set<ModelUnit> worklist = aps;
    try {
        for (ModelUnit head : worklist) {
            seens.add(head);
            if (head != null && head instanceof AadlPackage) {
                secLibs.addAll(AnnexUtil.getAllActualAnnexLibraries((AadlPackage) head, SecMFPackage.eINSTANCE.getSecModelLibrary()).stream().map(al -> (SecModelLibrary) al).collect(Collectors.toList()));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return secLibs;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SmfTypeDef(org.sireum.aadl.osate.securitymodel.secMF.SmfTypeDef) AnnexUtil(org.osate.annexsupport.AnnexUtil) Element(org.osate.aadl2.Element) SMFDeclassification(org.sireum.aadl.osate.securitymodel.secMF.SMFDeclassification) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Name(org.sireum.hamr.ir.Name) SecMFPackage(org.sireum.aadl.osate.securitymodel.secMF.SecMFPackage) HashSet(java.util.HashSet) AnnexLib(org.sireum.hamr.ir.AnnexLib) SmfDeclass(org.sireum.hamr.ir.SmfDeclass) Classifier(org.osate.aadl2.Classifier) Annex(org.sireum.hamr.ir.Annex) SmfClassification(org.sireum.hamr.ir.SmfClassification) SystemInstance(org.osate.aadl2.instance.SystemInstance) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) SecModelLibrary(org.sireum.aadl.osate.securitymodel.secMF.SecModelLibrary) SecModelSubclause(org.sireum.aadl.osate.securitymodel.secMF.SecModelSubclause) PackageSection(org.osate.aadl2.PackageSection) Set(java.util.Set) AadlPackage(org.osate.aadl2.AadlPackage) SMFClassification(org.sireum.aadl.osate.securitymodel.secMF.SMFClassification) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ModelUnit(org.osate.aadl2.ModelUnit) SmfType(org.sireum.hamr.ir.SmfType) AnnexSubclause(org.osate.aadl2.AnnexSubclause) NamedElement(org.osate.aadl2.NamedElement) AadlPackage(org.osate.aadl2.AadlPackage) SecModelLibrary(org.sireum.aadl.osate.securitymodel.secMF.SecModelLibrary) PackageSection(org.osate.aadl2.PackageSection) ModelUnit(org.osate.aadl2.ModelUnit) HashSet(java.util.HashSet)

Example 22 with PackageSection

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

the class Aadl2Visitors method findElementInPackage.

/**
 * Find an element in a package based on their name from the given point of
 * view (package section) or return {@code null}.
 *
 * @param elementName the element's name
 * @param packageName the package's name
 * @param context the given point of view
 * @return the element or {@code null}
 */
public static NamedElement findElementInPackage(String elementName, String packageName, PackageSection context) {
    NamedElement result = null;
    NamedElement rootContainer = context.getElementRoot();
    String currentNamespace = rootContainer.getName();
    PropertiesLinkingService pls = Aadl2Visitors.getPropertiesLinkingService(context);
    if (packageName == null || currentNamespace == null || currentNamespace.equalsIgnoreCase(packageName)) {
        // The element is declared into the current context.
        result = pls.findNamedElementInsideAadlPackage(elementName, context);
    } else // The element is defined into an imported package.
    {
        result = pls.findNamedElementInAadlPackage(packageName, elementName, context);
    }
    return result;
}
Also used : PropertiesLinkingService(org.osate.xtext.aadl2.properties.linking.PropertiesLinkingService) NamedElement(org.osate.aadl2.NamedElement)

Example 23 with PackageSection

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

the class AadlBaVisitors method getBaPackageSections.

/**
 * Return the package sections related to a given BehaviorAnnex. As
 * "Classifier declarations in public sections are accessible to other
 * packages, while classifiers in private sections can only be referenced
 * within the private section of the same package".<br><br>
 * table[0] always refers to public section.
 * If the given BehaviorAnnex is declared in a private section, table's
 * length equals to 2 and table[1] refers to the private section.
 *
 * @param ba The given BehaviorAnnex
 * @return the package sections related to the given BehaviorAnnex.
 */
public static PackageSection[] getBaPackageSections(BehaviorAnnex ba) {
    PackageSection[] result;
    PackageSection container = Aadl2Visitors.getContainingPackageSection(ba);
    // package's private section.
    if (container instanceof PrivatePackageSection) {
        result = new PackageSection[2];
        result[1] = container;
        result[0] = ((AadlPackage) container.eContainer()).getPublicSection();
    } else {
        result = new PackageSection[1];
        result[0] = container;
    }
    return result;
}
Also used : PackageSection(org.osate.aadl2.PackageSection) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection)

Example 24 with PackageSection

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

the class AadlBaNameResolver method propertyExpressionResolver.

/**
 * Resolves the property expressions used in behavior annex.
 * @param p
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean propertyExpressionResolver(BehaviorVariable bv, Property p, PropertyExpression pe) {
    QualifiedNamedElement qne = (QualifiedNamedElement) p;
    String propertyName = "";
    boolean hasNamespace = qne.getBaNamespace() != null;
    if (hasNamespace) {
        propertyName = qne.getBaNamespace().getId() + "::";
    }
    propertyName += qne.getBaName().getId();
    boolean result = true;
    if (pe instanceof DeclarativeListValue) {
        ListValue dlv = (DeclarativeListValue) pe;
        for (PropertyExpression peInList : dlv.getOwnedListElements()) {
            result &= propertyExpressionResolver(bv, p, peInList);
        }
    } else if (pe instanceof IntegerLiteral) {
        IntegerLiteral il = (IntegerLiteral) pe;
        if (il.getUnit() != null && il.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(il, bv, p);
        }
    } else if (pe instanceof RealLiteral) {
        RealLiteral rl = (RealLiteral) pe;
        if (rl.getUnit() != null && rl.getUnit() instanceof QualifiedNamedElement) {
            result &= unitResolver(rl, bv, p);
        }
    } else if (pe instanceof RecordValue) {
        RecordValue rv = (RecordValue) pe;
        for (BasicPropertyAssociation bpa : rv.getOwnedFieldValues()) {
            if (bpa instanceof DeclarativeBasicPropertyAssociation) {
                DeclarativeBasicPropertyAssociation dbpa = (DeclarativeBasicPropertyAssociation) bpa;
                String basicPropertyName = dbpa.getBasicPropertyName();
                BasicProperty basicProp = getBasicPropertyResolver(bv, p, basicPropertyName);
                if (basicProp == null) {
                    _errManager.error(bv, "Property field \'" + basicPropertyName + "\' of property " + propertyName + " is not found");
                    result = false;
                }
                dbpa.setProperty(basicProp);
            }
        }
    } else if (pe instanceof RangeValue) {
        RangeValue rv = (RangeValue) pe;
        result &= propertyExpressionResolver(bv, p, rv.getMaximum());
        result &= propertyExpressionResolver(bv, p, rv.getMinimum());
    } else if (pe instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) pe;
        Reference r = (Reference) (rv.getPath());
        ContainmentPathElement firstCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
        ContainmentPathElement prevCne = null;
        boolean first = true;
        Classifier context = _baParentContainer;
        for (Identifier subPath : r.getIds()) {
            ContainmentPathElement currentCne;
            if (!first) {
                currentCne = Aadl2Factory.eINSTANCE.createContainmentPathElement();
            } else {
                currentCne = firstCne;
            }
            first = false;
            NamedElement ne = Aadl2Visitors.findSubcomponentInComponent(context, subPath.getId());
            if (ne == null) {
                ne = Aadl2Visitors.findFeatureInComponent(context, subPath.getId());
            }
            if (ne == null) {
                _errManager.error(bv, "Element \'" + subPath.getId() + "\' is not found in " + context.getName() + "(property " + propertyName + ")");
                result = false;
            } else {
                currentCne.setNamedElement(ne);
                if (prevCne != null) {
                    prevCne.setPath(currentCne);
                }
                if (ne instanceof Subcomponent) {
                    Subcomponent sub = (Subcomponent) ne;
                    context = sub.getClassifier();
                } else if (ne instanceof Feature) {
                    Feature f = (Feature) ne;
                    context = f.getClassifier();
                }
            }
            prevCne = currentCne;
        }
        rv.setPath(firstCne);
    } else if (pe instanceof ClassifierValue) {
        ClassifierValue cv = (ClassifierValue) pe;
        QualifiedNamedElement classifierQne = (QualifiedNamedElement) cv.getClassifier();
        String qneClassPackageName = "";
        boolean qneClassHasNamespace = classifierQne.getBaNamespace() != null;
        if (qneClassHasNamespace) {
            qneClassPackageName = classifierQne.getBaNamespace().getId();
        }
        boolean resolved = false;
        for (PackageSection context : _contextsTab) {
            NamedElement ne = Aadl2Visitors.findElementInPackage(classifierQne.getBaName().getId(), qneClassPackageName, context);
            if (ne != null && ne instanceof Classifier) {
                cv.setClassifier((Classifier) ne);
                resolved = true;
                break;
            }
        }
        if (!resolved) {
            String cvQualifiedName = "";
            if (!qneClassPackageName.isEmpty()) {
                cvQualifiedName += qneClassPackageName + "::";
            }
            cvQualifiedName += classifierQne.getBaName().getId();
            _errManager.error(bv, "Classifier \'" + cvQualifiedName + "\' associated to property " + propertyName + " is not found");
            result = false;
        }
    }
    return result;
}
Also used : ClassifierValue(org.osate.aadl2.ClassifierValue) ReferenceValue(org.osate.aadl2.ReferenceValue) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) Reference(org.osate.ba.declarative.Reference) PackageSection(org.osate.aadl2.PackageSection) ListValue(org.osate.aadl2.ListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) DeclarativeListValue(org.osate.ba.declarative.DeclarativeListValue) RecordValue(org.osate.aadl2.RecordValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) RangeValue(org.osate.aadl2.RangeValue) RealLiteral(org.osate.aadl2.RealLiteral) BasicProperty(org.osate.aadl2.BasicProperty) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) Identifier(org.osate.ba.declarative.Identifier) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) Subcomponent(org.osate.aadl2.Subcomponent) PropertyExpression(org.osate.aadl2.PropertyExpression) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement) IntegerLiteral(org.osate.aadl2.IntegerLiteral) BehaviorIntegerLiteral(org.osate.ba.aadlba.BehaviorIntegerLiteral)

Example 25 with PackageSection

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

the class AadlUtil method getAllComponentImpl.

/**
 * Get all component implementation; in anon. name space and from all
 * packages
 *
 * @param o AadlPackage
 * @return EList of component impl
 */
public static EList<ComponentImplementation> getAllComponentImpl(AadlPackage o) {
    EList<ComponentImplementation> result = new BasicEList<ComponentImplementation>();
    PackageSection psec = o.getOwnedPublicSection();
    if (psec != null) {
        for (EObject oo : psec.getOwnedElements()) {
            if (oo instanceof ComponentImplementation) {
                result.add((ComponentImplementation) oo);
            }
        }
    }
    psec = o.getPrivateSection();
    if (psec != null) {
        for (EObject oo : psec.getOwnedElements()) {
            if (oo instanceof ComponentImplementation) {
                result.add((ComponentImplementation) oo);
            }
        }
    }
    return result;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) PackageSection(org.osate.aadl2.PackageSection) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection) BasicEList(org.eclipse.emf.common.util.BasicEList) EObject(org.eclipse.emf.ecore.EObject)

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