Search in sources :

Example 1 with AadlPackage

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

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

the class VerifyHandler method getComponentImplementations.

private List<ComponentImplementation> getComponentImplementations(ComponentType ct) {
    List<ComponentImplementation> result = new ArrayList<>();
    AadlPackage pkg = AadlUtil.getContainingPackage(ct);
    for (ComponentImplementation ci : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
        if (ci.getType().equals(ct)) {
            result.add(ci);
        }
    }
    return result;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) AadlPackage(org.osate.aadl2.AadlPackage) ArrayList(java.util.ArrayList)

Example 3 with AadlPackage

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

the class AgreeAnnexContentAssist method getNestedDotIDCandidates.

private List<String> getNestedDotIDCandidates(SelectionExpr id) {
    NamedElement base = ((NamedElmExpr) id).getElm();
    NamedElement namedEl = null;
    if (base instanceof Arg) {
        Type type = ((Arg) base).getType();
        DoubleDotRef elID = ((DoubleDotRef) type);
        namedEl = elID.getElm();
    // =======
    // DoubleDotRef elID = ((RecordType) type).getRecord();
    // namedEl = elID.getElm();
    // >>>>>>> origin/develop
    } else if (base instanceof DataPort) {
        namedEl = ((DataPort) base).getDataFeatureClassifier();
    } else if (base instanceof EventDataPort) {
        namedEl = ((EventDataPort) base).getDataFeatureClassifier();
    } else if (base instanceof AadlPackage) {
        return getNestedDotIDCandidates((AadlPackage) base);
    } else {
        return new ArrayList<>();
    }
    return getNestedDotIDCandidates(namedEl);
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) Type(com.rockwellcollins.atc.agree.agree.Type) AadlPackage(org.osate.aadl2.AadlPackage) Arg(com.rockwellcollins.atc.agree.agree.Arg) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Example 4 with AadlPackage

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

the class AgreeValidator method getEnumValueDefLocation.

private String getEnumValueDefLocation(NamedID id) {
    EObject container = id.eContainer();
    EnumStatement enumStatement = (EnumStatement) container;
    String enumName = enumStatement.getName();
    while (!(container instanceof AadlPackage) && !(container instanceof ComponentClassifier)) {
        container = container.eContainer();
    }
    return ((NamedElement) container).getQualifiedName() + "::" + enumName;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) EnumStatement(com.rockwellcollins.atc.agree.agree.EnumStatement) NamedElement(org.osate.aadl2.NamedElement)

Example 5 with AadlPackage

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

the class AgreeValidator method checkNamedElement.

@Check(CheckType.FAST)
public void checkNamedElement(NamedElement namedEl) {
    // check for namespace collision in component types of component
    // implementations
    // and for collisions between subcomponent and feature names
    EObject container = namedEl.eContainer();
    if (container == null) {
        return;
    }
    if (container instanceof RecordDef || container instanceof NodeDef) {
        // TODO: perhaps we can ignore all arguments?
        return;
    }
    while (!(container instanceof AadlPackage || container instanceof ComponentImplementation || container instanceof ComponentType)) {
        container = container.eContainer();
    }
    ComponentImplementation compImpl = null;
    ComponentType type = null;
    if (container instanceof ComponentImplementation) {
        compImpl = (ComponentImplementation) container;
        type = compImpl.getType();
        checkDupNames(namedEl, type, compImpl);
    } else if (container instanceof ComponentType) {
        type = (ComponentType) container;
    }
    if (type != null && (namedEl.getName() != null)) {
        for (Feature feat : type.getAllFeatures()) {
            if (namedEl.getName().equals(feat.getName())) {
                error(feat, "Element of the same name ('" + namedEl.getName() + "') in AGREE Annex in '" + (compImpl == null ? type.getName() : compImpl.getName()) + "'");
                error(namedEl, "Feature of the same name ('" + namedEl.getName() + "') in component type");
            }
        }
    }
// check name space collision with enumerated types
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) AadlPackage(org.osate.aadl2.AadlPackage) EObject(org.eclipse.emf.ecore.EObject) Feature(org.osate.aadl2.Feature) RecordDef(com.rockwellcollins.atc.agree.agree.RecordDef) Check(org.eclipse.xtext.validation.Check)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)100 EObject (org.eclipse.emf.ecore.EObject)43 Classifier (org.osate.aadl2.Classifier)37 NamedElement (org.osate.aadl2.NamedElement)25 ArrayList (java.util.ArrayList)21 ComponentImplementation (org.osate.aadl2.ComponentImplementation)19 PackageSection (org.osate.aadl2.PackageSection)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 Element (org.osate.aadl2.Element)15 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)12 Optional (java.util.Optional)11 Test (org.junit.Test)11 Subcomponent (org.osate.aadl2.Subcomponent)10 SystemInstance (org.osate.aadl2.instance.SystemInstance)10 Inject (com.google.inject.Inject)9 List (java.util.List)9 IFile (org.eclipse.core.resources.IFile)9 URI (org.eclipse.emf.common.util.URI)9