Search in sources :

Example 6 with PackageRename

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

the class SafetyScopeProvider method scope_NamedElement.

IScope scope_NamedElement(AgreeContract ctx, EReference ref) {
    EObject container = getAadlContainer(ctx);
    AadlPackage pkg = getContainingPackage(container);
    List<NamedElement> elems = new ArrayList<>();
    for (PackageRename rename : EcoreUtil2.getAllContentsOfType(pkg, PackageRename.class)) {
        if (rename.isRenameAll()) {
            AadlPackage renamedPackage = rename.getRenamedPackage();
            elems.addAll(getNamedElements(renamedPackage));
        }
    }
    System.out.println("Here in agree.");
    elems.addAll(getNamedElements(container));
    return Scopes.scopeFor(elems, getScope(ctx.eContainer().eContainer(), ref));
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageRename(org.osate.aadl2.PackageRename) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) NamedElement(org.osate.aadl2.NamedElement)

Example 7 with PackageRename

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

the class SafetyLinkingService 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 (com.rockwellcollins.atc.agree.agree.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 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) 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) ConstStatement(com.rockwellcollins.atc.agree.agree.ConstStatement) 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 PackageRename

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

the class SafetyScopeProvider method scope_NamedElement.

IScope scope_NamedElement(SafetyContract ctx, EReference ref) {
    EObject container = getAadlContainer(ctx);
    AadlPackage pkg = getContainingPackage(container);
    List<NamedElement> elems = new ArrayList<>();
    for (PackageRename rename : EcoreUtil2.getAllContentsOfType(pkg, PackageRename.class)) {
        if (rename.isRenameAll()) {
            AadlPackage renamedPackage = rename.getRenamedPackage();
            elems.addAll(getNamedElements(renamedPackage));
        }
    }
    // System.out.println("Here in safety.");
    elems.addAll(getNamedElements(container));
    elems.addAll(getNamedElementsFromSafetySpecs(ctx.getSpecs()));
    return Scopes.scopeFor(elems, getScope(ctx.eContainer().eContainer(), ref));
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageRename(org.osate.aadl2.PackageRename) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) NamedElement(org.osate.aadl2.NamedElement)

Example 9 with PackageRename

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

the class AgreeScopeProvider method scope_NamedElement.

IScope scope_NamedElement(AgreeContract ctx, EReference ref) {
    EObject container = getAadlContainer(ctx);
    AadlPackage pkg = getContainingPackage(ctx);
    Map<String, NamedElement> elems = new HashMap<>();
    for (PackageRename rename : EcoreUtil2.getAllContentsOfType(pkg, PackageRename.class)) {
        if (rename.isRenameAll()) {
            AadlPackage renamedPackage = rename.getRenamedPackage();
            elems.putAll(getNamedElements(renamedPackage));
        }
    }
    elems.putAll(getNamedElements(container));
    return Scopes.scopeFor(elems.values(), getScope(ctx.eContainer().eContainer(), ref));
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) HashMap(java.util.HashMap) PackageRename(org.osate.aadl2.PackageRename) EObject(org.eclipse.emf.ecore.EObject) NamedElement(org.osate.aadl2.NamedElement)

Example 10 with PackageRename

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

the class EphemeralImplementationUtil method createComponentImplementationInternal.

/**
 * Internal method to actually create the ephemeral component implementation and containing resource.
 * <p>
 * This method is intended to by invoked only from the command stack so that editing permissions are managed
 * through the transactional editing domain.
 *
 * @param ct The {@link ComponentType} for which to create an ephemeral implementation.
 * @param aadlResource The {@link Resource} in which to place the ephemeral implementation and it containing
 *     {@link AadlPackage}.
 * @return A {@link ComponentImplementation} matching the given component type.
 * @throws InterruptedException
 */
private ComponentImplementation createComponentImplementationInternal(ComponentType ct, Resource aadlResource) throws InterruptedException {
    // Create a package and public section to contain the created
    // component implementation
    AadlPackage aadlPackage = Aadl2Factory.eINSTANCE.createAadlPackage();
    aadlPackage.setName(aadlResource.getURI().trimFragment().trimFileExtension().lastSegment().toString());
    PublicPackageSection publicSection = aadlPackage.createOwnedPublicSection();
    // Add import for package containing ct
    AadlPackage ctPackage = (AadlPackage) AgreeUtils.getClosestContainerOfType(ct, AadlPackage.class);
    publicSection.getImportedUnits().add(ctPackage);
    // Add renames clause to make linking to ct easy
    PackageRename ctRename = publicSection.createOwnedPackageRename();
    ctRename.setName("");
    ctRename.setRenamedPackage(ctPackage);
    ctRename.setRenameAll(true);
    // Create the component implementation in the public section
    ComponentImplementation compImpl;
    if (ct instanceof ThreadType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadImplementation());
    } else if (ct instanceof ThreadGroupType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getThreadGroupImplementation());
    } else if (ct instanceof ProcessType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessImplementation());
    } else if (ct instanceof SubprogramType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSubprogramImplementation());
    } else if (ct instanceof ProcessorType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getProcessorImplementation());
    } else if (ct instanceof BusType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getBusImplementation());
    } else if (ct instanceof DeviceType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getDeviceImplementation());
    } else if (ct instanceof SystemType) {
        compImpl = (ComponentImplementation) publicSection.createOwnedClassifier(Aadl2Package.eINSTANCE.getSystemImplementation());
    } else {
        throw new AgreeException("Unhandled component type: " + ct.getClass().toString());
    }
    compImpl.setType(ct);
    compImpl.setName(ct.getName() + ".wrapper");
    // Add the package and its contents to the resource
    aadlResource.getContents().add(aadlPackage);
    // IResource as we build it.
    try {
        aadlResource.save(null);
    } catch (IOException e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        return null;
    } catch (NullPointerException npe) {
        npe.printStackTrace();
        setErrorMessage(npe.getMessage());
        npe.getMessage();
        return null;
    // } catch (InterruptedException e) {
    // throw e;
    } catch (Exception e) {
        e.printStackTrace();
        errorMessage = e.getMessage();
        e.getMessage();
        return null;
    }
    return compImpl;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ThreadGroupType(org.osate.aadl2.ThreadGroupType) AadlPackage(org.osate.aadl2.AadlPackage) BusType(org.osate.aadl2.BusType) ProcessorType(org.osate.aadl2.ProcessorType) SystemType(org.osate.aadl2.SystemType) IOException(java.io.IOException) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) DeviceType(org.osate.aadl2.DeviceType) ProcessType(org.osate.aadl2.ProcessType) PublicPackageSection(org.osate.aadl2.PublicPackageSection) ThreadType(org.osate.aadl2.ThreadType) PackageRename(org.osate.aadl2.PackageRename) SubprogramType(org.osate.aadl2.SubprogramType)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)8 PackageRename (org.osate.aadl2.PackageRename)8 EObject (org.eclipse.emf.ecore.EObject)3 PropertySet (org.osate.aadl2.PropertySet)3 PublicPackageSection (org.osate.aadl2.PublicPackageSection)3 AgreeContract (com.rockwellcollins.atc.agree.agree.AgreeContract)2 ConstStatement (com.rockwellcollins.atc.agree.agree.ConstStatement)2 EnumStatement (com.rockwellcollins.atc.agree.agree.EnumStatement)2 FnDef (com.rockwellcollins.atc.agree.agree.FnDef)2 LibraryFnDef (com.rockwellcollins.atc.agree.agree.LibraryFnDef)2 LinearizationDef (com.rockwellcollins.atc.agree.agree.LinearizationDef)2 NamedID (com.rockwellcollins.atc.agree.agree.NamedID)2 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)2 RecordDef (com.rockwellcollins.atc.agree.agree.RecordDef)2 ArrayList (java.util.ArrayList)2 AnnexLibrary (org.osate.aadl2.AnnexLibrary)2 NamedElement (org.osate.aadl2.NamedElement)2 PrivatePackageSection (org.osate.aadl2.PrivatePackageSection)2 SpecStatement (com.rockwellcollins.atc.agree.agree.SpecStatement)1 UninterpretedFnDef (com.rockwellcollins.atc.agree.agree.UninterpretedFnDef)1