Search in sources :

Example 1 with NamedSpecStatement

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

the class AgreeValidator method checkNoDuplicateIdInSpec.

@Check(CheckType.NORMAL)
public void checkNoDuplicateIdInSpec(AadlPackage toppkg) {
    // namedSpecs associates an agree spec ID with all the agree specs that have that ID
    HashMultimap<String, NamedSpecStatement> namedSpecs = HashMultimap.create();
    // Get the set of packages referenced in model
    Set<AadlPackage> pkgs = new HashSet<>();
    getPackageDependencies(toppkg, pkgs);
    for (AadlPackage pkg : pkgs) {
        // Get the list of agree specs in each package
        List<NamedSpecStatement> specs = getNamedSpecStatements(pkg);
        for (NamedSpecStatement spec : specs) {
            String id = spec.getName();
            if (id != null) {
                namedSpecs.put(id, spec);
            }
        }
    }
    // Get the agree specs in the current package
    List<NamedSpecStatement> specs = getNamedSpecStatements(toppkg);
    Iterator<NamedSpecStatement> i = specs.iterator();
    while (i.hasNext()) {
        NamedSpecStatement spec = i.next();
        String id = spec.getName();
        // If the current spec name is associated with multiple agree specs, we've found a duplicate
        if (namedSpecs.get(id).size() > 1) {
            Iterator<NamedSpecStatement> ii = namedSpecs.get(id).iterator();
            while (ii.hasNext()) {
                String pkgName = AadlUtil.getContainingPackage(ii.next()).getName();
                // // If the specs are from the same package, the error will be generated from the
                // // NamedElement check.
                // if (!pkgName.contentEquals(AadlUtil.getContainingPackage(spec).getName())) {
                error("Duplicate AGREE property ID in package " + pkgName, spec, Aadl2Package.eINSTANCE.getNamedElement_Name());
            // }
            }
            namedSpecs.removeAll(id);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) NamedSpecStatement(com.rockwellcollins.atc.agree.agree.NamedSpecStatement) HashSet(java.util.HashSet) Check(org.eclipse.xtext.validation.Check)

Example 2 with NamedSpecStatement

use of com.rockwellcollins.atc.agree.agree.NamedSpecStatement 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 3 with NamedSpecStatement

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

NamedSpecStatement (com.rockwellcollins.atc.agree.agree.NamedSpecStatement)3 HashSet (java.util.HashSet)3 AgreeSubclause (com.rockwellcollins.atc.agree.agree.AgreeSubclause)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 Check (org.eclipse.xtext.validation.Check)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 AadlPackage (org.osate.aadl2.AadlPackage)1 ComponentImplementation (org.osate.aadl2.ComponentImplementation)1 ComponentType (org.osate.aadl2.ComponentType)1