Search in sources :

Example 1 with AgreeSubclause

use of com.rockwellcollins.atc.agree.agree.AgreeSubclause in project AGREE by loonwerks.

the class AgreeValidator method checkNameOverlap.

@Check(CheckType.FAST)
public void checkNameOverlap(AgreeContract contract) {
    Set<SynchStatement> syncs = new HashSet<>();
    Set<InitialStatement> inits = new HashSet<>();
    List<ConnectionStatement> conns = new ArrayList<>();
    // check that there are zero or more synchrony statements
    for (SpecStatement spec : contract.getSpecs()) {
        if (spec instanceof SynchStatement) {
            syncs.add((SynchStatement) spec);
        } else if (spec instanceof CalenStatement) {
            syncs.add((CalenStatement) spec);
        } else if (spec instanceof InitialStatement) {
            inits.add((InitialStatement) spec);
        } else if (spec instanceof ConnectionStatement) {
            conns.add((ConnectionStatement) spec);
        }
    }
    if (syncs.size() > 1) {
        for (SynchStatement sync : syncs) {
            error(sync, "Multiple synchrony or calender statements in a single contract");
        }
    }
    if (inits.size() > 1) {
        for (InitialStatement init : inits) {
            error(init, "Multiple initially statements in a single contract");
        }
    }
    for (int i = 0; i < conns.size(); i++) {
        ConnectionStatement connStat0 = conns.get(i);
        NamedElement conn0 = connStat0.getConn();
        for (int j = i + 1; j < conns.size(); j++) {
            ConnectionStatement connStat1 = conns.get(j);
            NamedElement conn1 = connStat1.getConn();
            if (conn0 == null || conn1 == null) {
                break;
            }
            if (conn0.equals(conn1)) {
                error(connStat0, "Multiple connection overrides for connection: '" + conn0.getName() + "'");
                error(connStat1, "Multiple connection overrides for connection: '" + conn1.getName() + "'");
            }
        }
    }
    ComponentImplementation ci = EcoreUtil2.getContainerOfType(contract, ComponentImplementation.class);
    if (ci == null) {
        return;
    }
    Set<String> parentNames = getParentNames(ci);
    for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ci, AgreeSubclause.class)) {
        List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
        for (NamedElement e : es) {
            if (!(e.eContainer() instanceof NodeDef || e instanceof NamedSpecStatement)) {
                // ignore elements in node defs
                if (parentNames.contains(e.getName())) {
                    // =======
                    // if (!(e.eContainer() instanceof NodeDefExpr)) { // ignore elements in node defs
                    // if (e.getName() != null && parentNames.contains(e.getName())) {
                    // >>>>>>> origin/develop
                    error(e, e.getName() + " already defined in component type contract");
                }
            }
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) ConnectionStatement(com.rockwellcollins.atc.agree.agree.ConnectionStatement) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) InitialStatement(com.rockwellcollins.atc.agree.agree.InitialStatement) CalenStatement(com.rockwellcollins.atc.agree.agree.CalenStatement) MNSynchStatement(com.rockwellcollins.atc.agree.agree.MNSynchStatement) SynchStatement(com.rockwellcollins.atc.agree.agree.SynchStatement) NamedElement(org.osate.aadl2.NamedElement) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 2 with AgreeSubclause

use of com.rockwellcollins.atc.agree.agree.AgreeSubclause in project AGREE by loonwerks.

the class AgreeValidator method getParentNames.

private Set<String> getParentNames(ComponentImplementation ci) {
    Set<String> result = new HashSet<>();
    ComponentType ct = ci.getType();
    for (AgreeSubclause subclause : EcoreUtil2.getAllContentsOfType(ct, AgreeSubclause.class)) {
        List<NamedElement> es = EcoreUtil2.getAllContentsOfType(subclause, NamedElement.class);
        for (NamedElement e : es) {
            if (!(e.eContainer() instanceof NodeDef || e.eContainer() instanceof LinearizationDef || e.eContainer() instanceof RecordDef || e instanceof NamedSpecStatement)) {
                result.add(e.getName());
            }
        }
    }
    return result;
}
Also used : AgreeSubclause(com.rockwellcollins.atc.agree.agree.AgreeSubclause) ComponentType(org.osate.aadl2.ComponentType) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) NamedElement(org.osate.aadl2.NamedElement) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) HashSet(java.util.HashSet)

Aggregations

AgreeSubclause (com.rockwellcollins.atc.agree.agree.AgreeSubclause)2 NamedSpecStatement (com.rockwellcollins.atc.agree.agree.NamedSpecStatement)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 HashSet (java.util.HashSet)2 NamedElement (org.osate.aadl2.NamedElement)2 CalenStatement (com.rockwellcollins.atc.agree.agree.CalenStatement)1 ConnectionStatement (com.rockwellcollins.atc.agree.agree.ConnectionStatement)1 InitialStatement (com.rockwellcollins.atc.agree.agree.InitialStatement)1 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)1 MNSynchStatement (com.rockwellcollins.atc.agree.agree.MNSynchStatement)1 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)1 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)1 SynchStatement (com.rockwellcollins.atc.agree.agree.SynchStatement)1 ArrayList (java.util.ArrayList)1 Check (org.eclipse.xtext.validation.Check)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 ComponentType (org.osate.aadl2.ComponentType)1