Search in sources :

Example 1 with CalenStatement

use of com.rockwellcollins.atc.agree.agree.CalenStatement 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 CalenStatement

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

the class AgreeValidator method checkSynchStatement.

@Check(CheckType.FAST)
public void checkSynchStatement(SynchStatement sync) {
    Classifier container = sync.getContainingClassifier();
    if (!(container instanceof ComponentImplementation)) {
        error(sync, "Synchrony statements can appear only in component implementations");
    }
    if (sync instanceof CalenStatement || sync instanceof MNSynchStatement || sync instanceof AsynchStatement || sync instanceof LatchedStatement) {
        return;
    }
    // So this may be redundant
    if (Integer.valueOf(sync.getVal()) < 0) {
        error(sync, "The value of synchrony statments must be positive");
    }
    String val2 = sync.getVal2();
    if (val2 != null) {
        if (Integer.valueOf(val2) <= 0) {
            error(sync, "The second value of a synchrony statment must be greater than zero");
        }
        if (Integer.valueOf(sync.getVal()) <= Integer.valueOf(val2)) {
            error(sync, "The second value of a synchrony argument must be less than the first");
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) MNSynchStatement(com.rockwellcollins.atc.agree.agree.MNSynchStatement) LatchedStatement(com.rockwellcollins.atc.agree.agree.LatchedStatement) AsynchStatement(com.rockwellcollins.atc.agree.agree.AsynchStatement) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) CalenStatement(com.rockwellcollins.atc.agree.agree.CalenStatement) Check(org.eclipse.xtext.validation.Check)

Aggregations

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