Search in sources :

Example 6 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 7 with AadlPackage

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

the class AgreeLinkingService method getElm.

private Element getElm(EObject context, EReference reference, String name) {
    String[] segments = name.split("::");
    if (segments.length >= 2) {
        String pkgName = String.join("::", Arrays.copyOf(segments, segments.length - 1));
        String statementName = segments[segments.length - 1];
        Namespace namespace = AadlUtil.getContainingTopLevelNamespace(context);
        PropertySet propSet = AadlUtil.findImportedPropertySet(pkgName, namespace);
        if (propSet != null) {
            Element elm = propSet.findNamedElement(statementName);
            return elm;
        }
        AadlPackage aadlPackage = AadlUtil.findImportedPackage(pkgName, namespace);
        if (aadlPackage == null) {
            for (PackageRename rename : EcoreUtil2.getAllContentsOfType(namespace.getElementRoot(), PackageRename.class)) {
                if (rename.getName() != null && pkgName.equals(rename.getName())) {
                    aadlPackage = rename.getRenamedPackage();
                }
            }
        }
        if (aadlPackage != null) {
            for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
                AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
                for (SpecStatement spec : contract.getSpecs()) {
                    if (spec instanceof RecordDef) {
                        if (((RecordDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof FnDef) {
                        if (((FnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LibraryFnDef) {
                        if (((LibraryFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof UninterpretedFnDef) {
                        if (((UninterpretedFnDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof NodeDef) {
                        if (((NodeDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof LinearizationDef) {
                        if (((LinearizationDef) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof ConstStatement) {
                        if (((ConstStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                    } else if (spec instanceof EnumStatement) {
                        if (((EnumStatement) spec).getName().equals(statementName)) {
                            return (spec);
                        }
                        EList<NamedID> enums = ((EnumStatement) spec).getEnums();
                        for (NamedID nid : enums) {
                            if (nid.getName().contentEquals(statementName)) {
                                return nid;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) Element(org.osate.aadl2.Element) LinearizationDef(com.rockwellcollins.atc.agree.agree.LinearizationDef) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) Namespace(org.osate.aadl2.Namespace) NamedID(com.rockwellcollins.atc.agree.agree.NamedID) FnDef(com.rockwellcollins.atc.agree.agree.FnDef) LibraryFnDef(com.rockwellcollins.atc.agree.agree.LibraryFnDef) UninterpretedFnDef(com.rockwellcollins.atc.agree.agree.UninterpretedFnDef) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) EList(org.eclipse.emf.common.util.EList) PackageRename(org.osate.aadl2.PackageRename) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef)

Example 8 with AadlPackage

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

the class AgreeScopeProvider method getNamedElements.

private Map<String, NamedElement> getNamedElements(EObject ctx) {
    Map<String, NamedElement> components = new HashMap<>();
    if (ctx instanceof AadlPackage) {
        components.put(((AadlPackage) ctx).getName(), (AadlPackage) ctx);
        PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
        for (Element el : pubSec.getOwnedElements()) {
            if (el instanceof DataImplementation || el instanceof DataType) {
                components.put(((NamedElement) el).getName(), (NamedElement) el);
            }
        }
        for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
            AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
            components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
        }
    } else {
        components.putAll(getNamedElementsFromClassifier((Classifier) ctx, false));
    }
    return components;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) PublicPackageSection(org.osate.aadl2.PublicPackageSection) HashMap(java.util.HashMap) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) DataImplementation(org.osate.aadl2.DataImplementation) DataType(org.osate.aadl2.DataType) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AnnexLibrary(org.osate.aadl2.AnnexLibrary) NamedElement(org.osate.aadl2.NamedElement)

Example 9 with AadlPackage

use of org.osate.aadl2.AadlPackage in project AMASE by loonwerks.

the class SafetyAnnexContentAssist method getNestedDotIDCandidates.

private List<String> getNestedDotIDCandidates(AadlPackage aadlPackage) {
    AgreeContract contract = null;
    List<String> results = new ArrayList<>();
    for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(aadlPackage, AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
        if (annex instanceof AgreeLibrary) {
            contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
        }
    }
    if (contract != null) {
        for (SpecStatement spec : contract.getSpecs()) {
            if (spec instanceof ConstStatement) {
                results.add(((ConstStatement) spec).getName());
            }
        }
    }
    return results;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) AgreeLibrary(com.rockwellcollins.atc.agree.agree.AgreeLibrary) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) ArrayList(java.util.ArrayList) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary)

Example 10 with AadlPackage

use of org.osate.aadl2.AadlPackage in project AMASE by loonwerks.

the class FaultsVerifyAllHandler method getClassifiers.

private List<Classifier> getClassifiers() {
    XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor();
    if (xtextEditor == null) {
        return null;
    }
    EObject original = xtextEditor.getDocument().readOnly(resource -> resource.getContents().get(0));
    AadlPackage aadlPackage = null;
    if (original instanceof AadlPackage) {
        aadlPackage = (AadlPackage) original;
    }
    if (aadlPackage == null) {
        return null;
    }
    return aadlPackage.getOwnedPublicSection().getOwnedClassifiers();
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)106 EObject (org.eclipse.emf.ecore.EObject)45 Classifier (org.osate.aadl2.Classifier)39 NamedElement (org.osate.aadl2.NamedElement)26 ArrayList (java.util.ArrayList)22 ComponentImplementation (org.osate.aadl2.ComponentImplementation)20 PackageSection (org.osate.aadl2.PackageSection)18 Element (org.osate.aadl2.Element)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)13 Optional (java.util.Optional)11 Test (org.junit.Test)11 SystemInstance (org.osate.aadl2.instance.SystemInstance)11 List (java.util.List)10 URI (org.eclipse.emf.common.util.URI)10 Subcomponent (org.osate.aadl2.Subcomponent)10 Inject (com.google.inject.Inject)9 IFile (org.eclipse.core.resources.IFile)9