Search in sources :

Example 6 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeUtils method containsTransitiveAgreeAnnex.

public static boolean containsTransitiveAgreeAnnex(ComponentInstance compInst, boolean isMonolithic) {
    Subcomponent subComp = compInst.getSubcomponent();
    if (!isMonolithic) {
        return liftedTypeContainsAgreeAnnex(subComp.getComponentImplementation()) || typeContainsAgreeAnnex(subComp);
    }
    if (containsAgreeAnnex(subComp)) {
        return true;
    }
    EList<ComponentInstance> transitiveSubs = compInst.getAllComponentInstances();
    for (ComponentInstance transInst : transitiveSubs) {
        if (AgreeUtils.containsAgreeAnnex(transInst.getSubcomponent())) {
            return true;
        }
    }
    return false;
}
Also used : Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance)

Example 7 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeValidator method getArgNames.

private List<NamedElement> getArgNames(DoubleDotRef recType) {
    NamedElement rec = recType.getElm();
    // =======
    // private List<NamedElement> getArgNames(DoubleDotRef recId) {
    // 
    // NamedElement rec = recId.getElm();
    // >>>>>>> origin/develop
    List<NamedElement> names = new ArrayList<>();
    if (rec instanceof RecordDef) {
        RecordDef recDef = (RecordDef) rec;
        for (Arg arg : recDef.getArgs()) {
            names.add(arg);
        }
    } else if (rec instanceof DataImplementation) {
        DataImplementation dataImpl = (DataImplementation) rec;
        for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
            names.add(sub);
        }
    } else {
        error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
    }
    return names;
}
Also used : Arg(com.rockwellcollins.atc.agree.agree.Arg) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ArrayList(java.util.ArrayList) DataImplementation(org.osate.aadl2.DataImplementation) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 8 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeValidator method checkNamedElement.

@Check(CheckType.FAST)
public void checkNamedElement(NamedElement namedEl) {
    // check for namespace collision in component types of component
    // implementations
    // and for collisions between subcomponent and feature names
    EObject container = namedEl.eContainer();
    if (container == null) {
        return;
    }
    if (container instanceof RecordDef || container instanceof NodeDef) {
        // TODO: perhaps we can ignore all arguments?
        return;
    }
    while (!(container instanceof AadlPackage || container instanceof ComponentImplementation || container instanceof ComponentType)) {
        container = container.eContainer();
    }
    ComponentImplementation compImpl = null;
    ComponentType type = null;
    if (container instanceof ComponentImplementation) {
        compImpl = (ComponentImplementation) container;
        type = compImpl.getType();
        checkDupNames(namedEl, type, compImpl);
    } else if (container instanceof ComponentType) {
        type = (ComponentType) container;
    }
    if (type != null && (namedEl.getName() != null)) {
        for (Feature feat : type.getAllFeatures()) {
            if (namedEl.getName().equals(feat.getName())) {
                error(feat, "Element of the same name ('" + namedEl.getName() + "') in AGREE Annex in '" + (compImpl == null ? type.getName() : compImpl.getName()) + "'");
                error(namedEl, "Feature of the same name ('" + namedEl.getName() + "') in component type");
            }
        }
    }
// check name space collision with enumerated types
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) Feature(org.osate.aadl2.Feature) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Example 9 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeValidator method checkOrderStatement.

@Check(CheckType.FAST)
public void checkOrderStatement(OrderStatement order) {
    Classifier container = order.getContainingClassifier();
    if (container instanceof ComponentImplementation) {
        ComponentImplementation compImpl = (ComponentImplementation) container;
        for (int index = 0; index < order.getComps().size(); ++index) {
            NamedElement comp = order.getComps().get(index);
            if (!(comp instanceof Subcomponent) || !((Subcomponent) comp).getContainingComponentImpl().equals(container)) {
                error("Element '" + comp.getName() + "' is not a subcomponent of '" + container.getName() + "'", order, AgreePackage.Literals.ORDER_STATEMENT__COMPS, index);
            }
        }
        List<NamedElement> notPresent = new ArrayList<>();
        for (Subcomponent subcomp : compImpl.getAllSubcomponents()) {
            boolean found = false;
            for (NamedElement el : order.getComps()) {
                if (el.equals(subcomp)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                notPresent.add(subcomp);
            }
        }
        if (notPresent.size() != 0) {
            String delim = "";
            StringBuilder errorStr = new StringBuilder("The following subcomponents are not present in the ordering: ");
            for (NamedElement subcomp : notPresent) {
                errorStr.append(delim);
                errorStr.append(subcomp.getName());
                delim = ", ";
            }
            error(order, errorStr.toString());
        }
    } else {
        error(order, "Ordering statements can appear only in component implementations");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ArrayList(java.util.ArrayList) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) NamedElement(org.osate.aadl2.NamedElement) Check(org.eclipse.xtext.validation.Check)

Example 10 with Subcomponent

use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.

the class AgreeValidator method checkLiftContract.

@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
    Classifier comp = lcst.getContainingClassifier();
    if (comp instanceof ComponentImplementation) {
        ComponentType ct = ((ComponentImplementation) comp).getType();
        List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (agreeAnnexes.size() > 0) {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
        }
        List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
        if (subcomps.size() == 1) {
            Subcomponent subcomp = subcomps.get(0);
            Classifier subCls = subcomp.getClassifier();
            ComponentType subCt = null;
            if (subCls instanceof ComponentImplementation) {
                subCt = ((ComponentImplementation) subCls).getType();
            } else if (subCls instanceof ComponentType) {
                subCt = (ComponentType) subCls;
            } else {
                throw new RuntimeException();
            }
            {
                Set<String> usedParentInPorts = new HashSet<>();
                Set<String> usedParentOutPorts = new HashSet<>();
                Set<String> usedChildInPorts = new HashSet<>();
                Set<String> usedChildOutPorts = new HashSet<>();
                EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
                EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
                for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
                    {
                        NamedElement sourceNe = conn.getSource().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedChildOutPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
                            }
                            usedChildOutPorts.add(sourceNe.getName());
                        }
                        if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedParentInPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
                            }
                            usedParentInPorts.add(sourceNe.getName());
                        }
                    }
                    {
                        NamedElement destNe = conn.getDestination().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedChildInPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
                            }
                            usedChildInPorts.add(destNe.getName());
                        }
                        if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedParentOutPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
                            }
                            usedParentOutPorts.add(destNe.getName());
                        }
                    }
                }
                for (Feature feat : comp.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedParentInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedParentOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
                        }
                    }
                }
                for (Feature feat : subCt.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedChildInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedChildOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
                        }
                    }
                }
            }
        } else {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
        }
    } else {
        error(lcst, "'lift contract;' statement is not allowed in component interface.");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Set(java.util.Set) HashSet(java.util.HashSet) Connection(org.osate.aadl2.Connection) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EList(org.eclipse.emf.common.util.EList) EventPort(org.osate.aadl2.EventPort) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause) Check(org.eclipse.xtext.validation.Check)

Aggregations

Subcomponent (org.osate.aadl2.Subcomponent)118 ComponentClassifier (org.osate.aadl2.ComponentClassifier)53 Classifier (org.osate.aadl2.Classifier)46 ComponentImplementation (org.osate.aadl2.ComponentImplementation)40 NamedElement (org.osate.aadl2.NamedElement)40 Feature (org.osate.aadl2.Feature)37 DataSubcomponent (org.osate.aadl2.DataSubcomponent)33 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)33 ArrayList (java.util.ArrayList)31 EObject (org.eclipse.emf.ecore.EObject)25 Connection (org.osate.aadl2.Connection)24 FeatureGroup (org.osate.aadl2.FeatureGroup)21 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)21 Property (org.osate.aadl2.Property)20 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)19 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)17 FeatureGroupType (org.osate.aadl2.FeatureGroupType)17 Element (org.osate.aadl2.Element)16 List (java.util.List)15 AadlPackage (org.osate.aadl2.AadlPackage)15