Search in sources :

Example 1 with AgreeContractLibrary

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

the class AGREESimulationState method buildPackageToConstantsMap.

private static Map<String, Map<String, ConstStatement>> buildPackageToConstantsMap(final IProject[] projects) {
    // Build a mapping between lower case package names and a map between constant names to constant statements
    final Map<String, Map<String, ConstStatement>> packageToConstantsMap = new HashMap<>();
    try {
        final Set<IFile> aadlFiles = new HashSet<>();
        getAadlFiles(projects, aadlFiles);
        for (final IFile aadlFile : aadlFiles) {
            // final Resource aadlRes = OsateResourceUtil.getResource(aadlFile);
            final Resource aadlRes = getResource(URI.createPlatformResourceURI(aadlFile.getFullPath().toString(), false));
            if (aadlRes != null && !aadlRes.getContents().isEmpty()) {
                final EObject content = aadlRes.getContents().get(0);
                if (content instanceof AadlPackage) {
                    // Find all AGREE Libraries
                    final AadlPackage pkg = (AadlPackage) content;
                    if (pkg.getPublicSection() != null && pkg.getName() != null) {
                        final Map<String, ConstStatement> constants = new HashMap<>();
                        packageToConstantsMap.put(pkg.getQualifiedName().toLowerCase(), constants);
                        for (final AnnexLibrary lib : pkg.getPublicSection().getOwnedAnnexLibraries()) {
                            // Look for AGREE annex libraries
                            if (lib instanceof DefaultAnnexLibrary && "agree".equalsIgnoreCase(lib.getName())) {
                                final AnnexLibrary parsedLib = ((DefaultAnnexLibrary) lib).getParsedAnnexLibrary();
                                if (parsedLib instanceof AgreeContractLibrary) {
                                    final AgreeContractLibrary agreeContractLib = (AgreeContractLibrary) parsedLib;
                                    if (agreeContractLib.getContract() instanceof AgreeContract) {
                                        final AgreeContract agreeContract = (AgreeContract) agreeContractLib.getContract();
                                        for (final SpecStatement spec : agreeContract.getSpecs()) {
                                            if (spec instanceof ConstStatement) {
                                                final ConstStatement constStatement = (ConstStatement) spec;
                                                // Check that the statement is of a supported type
                                                if (getType(constStatement) != null) {
                                                    constants.put(constStatement.getName().toLowerCase(), constStatement);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (CoreException e) {
        throw new AGREESimulatorException(null, e, "Unable to build constants map");
    }
    return packageToConstantsMap;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) HashMap(java.util.HashMap) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) CoreException(org.eclipse.core.runtime.CoreException) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) Map(java.util.Map) HashMap(java.util.HashMap) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) HashSet(java.util.HashSet) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 2 with AgreeContractLibrary

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

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

the class AgreeAnnexContentAssist 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 4 with AgreeContractLibrary

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

the class AgreeHandlerUtil method getOrCreateAgreeContract.

public static AgreeContract getOrCreateAgreeContract(final Object element) {
    // Subclauses
    final AgreeContractSubclause agreeSubclause;
    if (element instanceof Classifier) {
        agreeSubclause = getOrCreateAgreeSubclause((Classifier) element);
    } else if (element instanceof AgreeContractSubclause) {
        agreeSubclause = (AgreeContractSubclause) element;
    } else {
        agreeSubclause = null;
    }
    final AgreeContract contract;
    if (agreeSubclause == null) {
        // Libraries
        final AgreeContractLibrary agreeLibrary;
        if (element instanceof AadlPackage) {
            agreeLibrary = getOrCreateAgreeLibrary((AadlPackage) element);
        } else if (element instanceof AgreeContractLibrary) {
            agreeLibrary = (AgreeContractLibrary) element;
        } else {
            throw new RuntimeException("Specified business object is not a classifier or a subclause: " + element);
        }
        if (agreeLibrary.getContract() == null) {
            agreeLibrary.setContract(AgreeFactory.eINSTANCE.createAgreeContract());
        }
        if (!(agreeLibrary.getContract() instanceof AgreeContract)) {
            throw new RuntimeException("Contract is not an AGREE contract");
        }
        contract = (AgreeContract) agreeLibrary.getContract();
    } else {
        if (agreeSubclause.getContract() == null) {
            agreeSubclause.setContract(AgreeFactory.eINSTANCE.createAgreeContract());
        }
        if (!(agreeSubclause.getContract() instanceof AgreeContract)) {
            throw new RuntimeException("Contract is not an AGREE contract");
        }
        contract = (AgreeContract) agreeSubclause.getContract();
    }
    return contract;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) AadlPackage(org.osate.aadl2.AadlPackage) AgreeContractLibrary(com.rockwellcollins.atc.agree.agree.AgreeContractLibrary) Classifier(org.osate.aadl2.Classifier) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)

Aggregations

AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)4 AgreeContractLibrary (com.rockwellcollins.atc.agree.agree.AgreeContractLibrary)4 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)3 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)3 AnnexLibrary (org.osate.aadl2.AnnexLibrary)3 DefaultAnnexLibrary (org.osate.aadl2.DefaultAnnexLibrary)3 AgreeLibrary (com.rockwellcollins.atc.agree.agree.AgreeLibrary)2 ArrayList (java.util.ArrayList)2 AadlPackage (org.osate.aadl2.AadlPackage)2 AgreeContractSubclause (com.rockwellcollins.atc.agree.agree.AgreeContractSubclause)1 AGREESimulatorException (edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 EObject (org.eclipse.emf.ecore.EObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Classifier (org.osate.aadl2.Classifier)1