Search in sources :

Example 6 with AnnexSubclause

use of org.osate.aadl2.AnnexSubclause in project VERDICT by ge-high-assurance.

the class Aadl2Vdm method translateAbstractTypeObjects.

// End of translateDeviceTypeObjects
/**
 * Analyzing each abstractType:
 * 1. Determine if it is a lower-level system or higher-level system
 * 2. If lower-level, add to componentType list attribute of Model
 * 	2.1 Populate the port, contract, cyberRel, safetyRel, event, id, compCategory
 *      fields of componentType of the Model object
 * 3. If higher-level, assign to Model
 * 	3.1 Populate the safetyReq
 *      cyberReq, mission fields of Model object
 * @param abstractTypes
 * @param m1
 * @return
 */
public Model translateAbstractTypeObjects(List<AbstractType> abstractTypes, Model m1, HashSet<String> dataTypeDecl) {
    for (AbstractType absType : abstractTypes) {
        // variables for unpacking absType
        List<Event> events = new ArrayList<>();
        List<CyberMission> missionReqs = new ArrayList<>();
        List<CyberRel> cyberRels = new ArrayList<>();
        List<SafetyRel> safetyRels = new ArrayList<>();
        List<CyberReq> cyberReqs = new ArrayList<>();
        List<SafetyReq> safetyReqs = new ArrayList<>();
        // a flag to check if a higher -level component has already been found
        boolean higher_flag = false;
        // unpacking absType
        for (AnnexSubclause annex : absType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("verdict")) {
                Verdict verdictAnnex = VerdictUtil.getVerdict(annex);
                for (Statement statement : verdictAnnex.getElements()) {
                    if (statement instanceof Event) {
                        events.add((Event) statement);
                    } else if (statement instanceof CyberMission) {
                        missionReqs.add((CyberMission) statement);
                    } else if (statement instanceof CyberReq) {
                        cyberReqs.add((CyberReq) statement);
                    } else if (statement instanceof CyberRel) {
                        cyberRels.add((CyberRel) statement);
                    } else if (statement instanceof SafetyReq) {
                        safetyReqs.add((SafetyReq) statement);
                    } else if (statement instanceof SafetyRel) {
                        safetyRels.add((SafetyRel) statement);
                    }
                }
            }
        }
        /**
         *  For every AbstractType,
         *  populate the id, name, compCateg, port, event,
         *  cyberRel, and safetyRel fields of componentType
         *  and add it to the list of componentType
         *  of the Model object
         */
        if (true) {
            // No Filter-- do for all System Types
            // to pack the memType as a VDM component
            verdict.vdm.vdm_model.ComponentType packComponent = new verdict.vdm.vdm_model.ComponentType();
            // Note: Not populating "contract" for now
            // ISSUE: There is no getId() function for memoryType
            packComponent.setId(absType.getQualifiedName());
            // populating "name"
            packComponent.setName(absType.getName());
            // populating "compCateg"
            packComponent.setCompCateg(absType.getCategory().getName());
            // get all bus accesses and store them as ports
            List<BusAccess> busAccesses = absType.getOwnedBusAccesses();
            // checking each busAccess's details and adding it to the port list
            for (BusAccess busAccess : busAccesses) {
                String portName = busAccess.getName();
                String modeString = "in";
                if (busAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesBusAccess";
                } else if (busAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresBusAccess";
                }
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, busAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each busAccess
            // get all data accesses and store them as ports
            List<DataAccess> dataAccesses = absType.getOwnedDataAccesses();
            // checking each dataAccess's details and adding it to the port list
            for (DataAccess dataAccess : dataAccesses) {
                String portName = dataAccess.getName();
                String modeString = "in";
                if (dataAccess.getKind() == AccessType.PROVIDES) {
                    modeString = "providesDataAccess";
                } else if (dataAccess.getKind() == AccessType.REQUIRES) {
                    modeString = "requiresDataAccess";
                }
                verdict.vdm.vdm_model.Port newPort = createVdmPort(portName, modeString, dataAccess.getQualifiedName());
                // Note: Not populating "type" for now
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each dataAccess
            // get all ports
            List<DataPort> dataPorts = absType.getOwnedDataPorts();
            // checking each port's mode and name and adding it to the port list
            for (DataPort dataPort : dataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(dataPort, m1, dataTypeDecl);
                // ISSUE: "probe", "event", and "id" not found in DataPort class or superclass
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // End of checking each port
            // get all event data ports
            List<EventDataPort> eventDataPorts = absType.getOwnedEventDataPorts();
            for (EventDataPort eventDataPort : eventDataPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmPort(eventDataPort, m1, dataTypeDecl);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // get all event ports
            List<EventPort> eventPorts = absType.getOwnedEventPorts();
            for (EventPort eventPort : eventPorts) {
                verdict.vdm.vdm_model.Port newPort = createVdmEventPort(eventPort);
                // add to port list of component
                packComponent.getPort().add(newPort);
            }
            // packing all events and adding to component
            for (Event anEvent : events) {
                // To pack the event as a VDM event
                verdict.vdm.vdm_model.Event packEvent = createVdmEvent(anEvent);
                // adding to the list of component's events
                packComponent.getEvent().add(packEvent);
            }
            // packing all cyberRels and adding to component
            for (CyberRel aCyberRel : cyberRels) {
                // To pack the cyberRel as a VDM event
                verdict.vdm.vdm_model.CyberRel packCyberRel = createVdmCyberRel(aCyberRel);
                // adding to the list of component's Cyber relations
                packComponent.getCyberRel().add(packCyberRel);
            }
            // packing all safetyRels and adding to component
            for (SafetyRel aSafetyRel : safetyRels) {
                // To pack the safetyRel as a VDM event
                verdict.vdm.vdm_model.SafetyRel packSafetyRel = createVdmSafetyRel(aSafetyRel);
                // adding to the list of component's Safety relations
                packComponent.getSafetyRel().add(packSafetyRel);
            }
            // End of packing all safetyRels
            // adding to the list of componenmemTypes of the Model object
            m1.getComponentType().add(packComponent);
        }
        /**
         * If a high-level system
         *  populate the name, safetyReq, cyberReq, and mission
         *  for the model object
         */
        if (!cyberReqs.isEmpty() || !safetyReqs.isEmpty() || !missionReqs.isEmpty()) {
            // checking if a high-level system has already been found
            if (higher_flag == false) {
                higher_flag = true;
            } else {
                System.out.println("Warning: Multiple high-level systems detected!");
            }
            // populating name
            m1.setName(absType.getName());
            // packing all safetyReqs and adding to model
            for (SafetyReq aSafetyReq : safetyReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.SafetyReq packSafetyReq = createVdmSafetyReq(aSafetyReq, absType.getFullName());
                // adding to the list of model's Safety requirements
                m1.getSafetyReq().add(packSafetyReq);
            }
            // packing all cyberReqs and adding to model
            for (CyberReq aCyberReq : cyberReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.CyberReq packCyberReq = createVdmCyberReq(aCyberReq, absType.getFullName());
                // adding to the list of model's Cyber requirements
                m1.getCyberReq().add(packCyberReq);
            }
            // packing all missionReqs and adding to model
            for (CyberMission aMission : missionReqs) {
                // To pack the safettReq as a VDM event
                verdict.vdm.vdm_model.Mission packMission = createVdmMission(aMission);
                // adding to the list of model's Mission
                m1.getMission().add(packMission);
            }
        // End of packing all missionReqs
        }
    // End of if a higher-level system
    }
    // returning the populated Model
    return m1;
}
Also used : ArrayList(java.util.ArrayList) Port(verdict.vdm.vdm_model.Port) DataAccess(org.osate.aadl2.DataAccess) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EventPort(org.osate.aadl2.EventPort) EventDataPort(org.osate.aadl2.EventDataPort) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) BusAccess(org.osate.aadl2.BusAccess) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) AbstractType(org.osate.aadl2.AbstractType) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 7 with AnnexSubclause

use of org.osate.aadl2.AnnexSubclause in project VERDICT by ge-high-assurance.

the class Agree2Vdm method translateAgreeAnnex.

private Model translateAgreeAnnex(List<SystemType> systemTypes, List<SystemImplementation> systemImpls, Model model, HashSet<String> dataTypeDecl, HashSet<String> nodeDecl) {
    LustreProgram lustreProgram = new LustreProgram();
    // Initializing the lustre program in the VDM
    model.setDataflowCode(lustreProgram);
    // System.out.println("Processing "+systemTypes.size()+" SystemTypes for agree annexes");
    for (SystemType sysType : systemTypes) {
        // unpacking sysType
        for (AnnexSubclause annex : sysType.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("agree")) {
                // annex is of type DefaultAnnexSubclause
                DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
                // AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
                AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
                // populating agree contracts in the vdm component type -- SHOULD ADD THIS CODE TO AADL2VDM
                verdict.vdm.vdm_lustre.ContractSpec contractSpec = new verdict.vdm.vdm_lustre.ContractSpec();
                EList<EObject> annexContents = agreeAnnex.eContents();
                if (annexContents.isEmpty()) {
                    System.out.println("Empty Agree Annex.");
                }
                for (EObject clause : annexContents) {
                    // mapping to AgreeContractclause
                    AgreeContract agreeContract = (AgreeContract) clause;
                    // getting specStatements
                    EList<SpecStatement> specStatements = agreeContract.getSpecs();
                    for (SpecStatement specStatement : specStatements) {
                        if (specStatement instanceof EqStatement) {
                            EqStatement eqStmt = (EqStatement) specStatement;
                            // translate EqStatement in Agree to SymbolDefinition in vdm
                            SymbolDefinition symbDef = translateEqStatement(eqStmt, model, dataTypeDecl, nodeDecl);
                            // Add agree variable/symbol definition to the contractSpec in vdm
                            contractSpec.getSymbol().add(symbDef);
                        } else if (specStatement instanceof GuaranteeStatement) {
                            GuaranteeStatement guaranteeStmt = (GuaranteeStatement) specStatement;
                            ContractItem contractItem = translateGuaranteeStatement(guaranteeStmt, dataTypeDecl, nodeDecl, model);
                            contractSpec.getGuarantee().add(contractItem);
                        } else if (specStatement instanceof AssumeStatement) {
                            AssumeStatement assumeStmt = (AssumeStatement) specStatement;
                            ContractItem contractItem = translateAssumeStatement(assumeStmt, dataTypeDecl, nodeDecl, model);
                            contractSpec.getAssume().add(contractItem);
                        } else {
                            if (!(specStatement instanceof ConstStatementImpl)) {
                                System.out.println("Element not recognizable" + clause.eContents().toString());
                            }
                        }
                    }
                }
                if (contractSpec != null) {
                    List<ComponentType> vdmComponentTypes = model.getComponentType();
                    for (ComponentType vdmComponentType : vdmComponentTypes) {
                        // populating agree contract details in the corresponding componentType instance in vdm
                        if (vdmComponentType.getName().equalsIgnoreCase(sysType.getName())) {
                            vdmComponentType.setContract(contractSpec);
                        }
                    }
                // populating agree contract details in the componentType instance in vdm
                // packComponent.setContract(contractSpec);
                }
            }
        }
    // End of unpacking sysType
    }
    for (SystemImplementation sysImpl : systemImpls) {
        // unpacking sysType
        for (AnnexSubclause annex : sysImpl.getOwnedAnnexSubclauses()) {
            if (annex.getName().equalsIgnoreCase("agree")) {
                // annex is of type DefaultAnnexSubclause
                DefaultAnnexSubclause ddASC = (DefaultAnnexSubclause) annex;
                // AnnexSubclause aSC = ddASC.getParsedAnnexSubclause();
                AgreeContractSubclause agreeAnnex = (AgreeContractSubclause) ddASC.getParsedAnnexSubclause();
                // populating agree contracts in the vdm node body for component implementation type
                verdict.vdm.vdm_lustre.NodeBody nodeBody = new verdict.vdm.vdm_lustre.NodeBody();
                ;
                EList<EObject> annexContents = agreeAnnex.eContents();
                if (annexContents.isEmpty()) {
                    System.out.println("Empty Agree Annex.");
                }
                for (EObject clause : annexContents) {
                    // mapping to AgreeContractclause
                    AgreeContract agreeContract = (AgreeContract) clause;
                    // getting specStatements
                    EList<SpecStatement> specStatements = agreeContract.getSpecs();
                    for (SpecStatement specStatement : specStatements) {
                        if (specStatement instanceof ConstStatementImpl) {
                            ConstStatementImpl constStmtImpl = (ConstStatementImpl) specStatement;
                            ConstantDeclaration constDecl = translateConstStatementImpl(constStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getConstantDeclaration().add(constDecl);
                        } else if (specStatement instanceof EqStatementImpl) {
                            EqStatementImpl eqStmtImpl = (EqStatementImpl) specStatement;
                            nodeBody = translateEqStatementImpl(eqStmtImpl, dataTypeDecl, nodeDecl, model, nodeBody);
                        } else if (specStatement instanceof AssignStatementImpl) {
                            AssignStatementImpl assignStmtImpl = (AssignStatementImpl) specStatement;
                            NodeEquation nodeEquation = translateAssignStatementImpl(assignStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getEquation().add(nodeEquation);
                        } else if (specStatement instanceof AssertStatementImpl) {
                            AssertStatementImpl assertStmtImpl = (AssertStatementImpl) specStatement;
                            Expression assertion = translateAssertStatementImpl(assertStmtImpl, dataTypeDecl, nodeDecl, model);
                            nodeBody.getAssertion().add(assertion);
                        } else {
                            System.out.println("Element not recognizable" + clause.eContents().toString());
                        }
                    }
                }
                List<ComponentImpl> vdmComponentImpls = model.getComponentImpl();
                for (ComponentImpl vdmComponentImpl : vdmComponentImpls) {
                    // populating agree contract details in the corresponding componentImplType instance in vdm
                    if (vdmComponentImpl.getName().equalsIgnoreCase(sysImpl.getName())) {
                        vdmComponentImpl.setDataflowImpl(nodeBody);
                    }
                }
            }
        }
    }
    return model;
}
Also used : ConstStatementImpl(com.rockwellcollins.atc.agree.agree.impl.ConstStatementImpl) ConstantDeclaration(verdict.vdm.vdm_lustre.ConstantDeclaration) SystemType(org.osate.aadl2.SystemType) ComponentImpl(verdict.vdm.vdm_model.ComponentImpl) ContractItem(verdict.vdm.vdm_lustre.ContractItem) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AssertStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssertStatementImpl) SymbolDefinition(verdict.vdm.vdm_lustre.SymbolDefinition) NodeBody(verdict.vdm.vdm_lustre.NodeBody) AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) EqStatementImpl(com.rockwellcollins.atc.agree.agree.impl.EqStatementImpl) GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) ComponentType(verdict.vdm.vdm_model.ComponentType) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) NodeBody(verdict.vdm.vdm_lustre.NodeBody) SpecStatement(com.rockwellcollins.atc.agree.agree.SpecStatement) AgreeContractSubclause(com.rockwellcollins.atc.agree.agree.AgreeContractSubclause) NodeEquation(verdict.vdm.vdm_lustre.NodeEquation) PropertyExpression(org.osate.aadl2.PropertyExpression) Expression(verdict.vdm.vdm_lustre.Expression) LustreProgram(verdict.vdm.vdm_lustre.LustreProgram) SystemImplementation(org.osate.aadl2.SystemImplementation) EqStatement(com.rockwellcollins.atc.agree.agree.EqStatement) AssignStatementImpl(com.rockwellcollins.atc.agree.agree.impl.AssignStatementImpl) AnnexSubclause(org.osate.aadl2.AnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause)

Example 8 with AnnexSubclause

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

the class MATLABFunctionHandler method runJob.

@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
    Classifier classifier = getOutermostClassifier(root);
    if (!(classifier instanceof ComponentType)) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
    }
    ComponentType ct = (ComponentType) classifier;
    ComponentImplementation ci = null;
    EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
    try {
        SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
        ComponentType sysType = AgreeUtils.getInstanceType(si);
        EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (annexSubClauses.size() == 0) {
            throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
        }
        // Get Agree program
        AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
        if (agreeProgram.containsRealTimePatterns) {
            throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
        }
        // Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
        // and variable declarations sorted so they are declared before use
        Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
        // Translate Lustre Node to MATLAB Function AST
        MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
        ModelInfo info = getModelInfo(ct);
        if (info == null) {
            // return;
            return Status.CANCEL_STATUS;
        }
        String dirStr = info.outputDirPath;
        if (dirStr == null || dirStr.isEmpty()) {
            // return;
            return Status.CANCEL_STATUS;
        }
        boolean exportContractsPressed = info.exportPressed;
        boolean genImplPressed = info.generatePressed;
        boolean genVerificationPressed = info.updatePressed;
        boolean verifySubsysPressed = info.verifyPressed;
        String matlabFuncScriptName = matlabFunction.name + ".m";
        if (genImplPressed) {
            // Write MATLAB script to generate subsystem in the selected
            // output folder
            String subsysName = "";
            if (info.subsystemName.equals("")) {
                subsysName = sysType.getName();
            } else {
                subsysName = info.subsystemName;
            }
            MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
            String implMdlScriptName = "generate_" + subsysName + ".m";
            // generate the script to create the impl model file into the path specified for the model
            File implMdlFile = new File(info.implMdlPath);
            String implMdlDir = implMdlFile.getParent();
            if (implMdlDir != null) {
                Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
                writeToFile(implMdlScriptPath, implMdlScript.toString());
            }
        }
        if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
            Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
            // Write MATLAB function code into the specified file in the
            // selected output folder
            writeToFile(matlabFuncScriptPath, matlabFunction.toString());
            if (genVerificationPressed || verifySubsysPressed) {
                // Create Simulink Model Update script into the output
                // folder
                MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
                String verifMdlScriptName = matlabFunction.name + "_Observer.m";
                Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
                writeToFile(verifMdlScriptPath, verifMdlScript.toString());
            }
        }
        // return;
        return Status.OK_STATUS;
    } catch (Throwable e) {
        String messages = getNestedMessages(e);
        e.printStackTrace();
        Dialog.showError("AGREE Error", e.toString());
        // return;
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
    } finally {
        if (ci != null) {
            ci.eResource().getContents().remove(ci);
        }
        implUtil.cleanup();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Path(java.nio.file.Path) ComponentType(org.osate.aadl2.ComponentType) Node(jkind.lustre.Node) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) Classifier(org.osate.aadl2.Classifier) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) File(java.io.File) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 9 with AnnexSubclause

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

the class AgreeValidator method checkLiftContract.

@Check(CheckType.FAST)
public void checkLiftContract(LiftContractStatement lcst) {
    Classifier comp = lcst.getContainingClassifier();
    if (comp instanceof ComponentImplementation) {
        ComponentType ct = ((ComponentImplementation) comp).getType();
        List<AnnexSubclause> agreeAnnexes = AnnexUtil.getAllAnnexSubclauses(ct, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (agreeAnnexes.size() > 0) {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whose type has an AGREE annex.");
        }
        List<Subcomponent> subcomps = ((ComponentImplementation) comp).getAllSubcomponents();
        if (subcomps.size() == 1) {
            Subcomponent subcomp = subcomps.get(0);
            Classifier subCls = subcomp.getClassifier();
            ComponentType subCt = null;
            if (subCls instanceof ComponentImplementation) {
                subCt = ((ComponentImplementation) subCls).getType();
            } else if (subCls instanceof ComponentType) {
                subCt = (ComponentType) subCls;
            } else {
                throw new RuntimeException();
            }
            {
                Set<String> usedParentInPorts = new HashSet<>();
                Set<String> usedParentOutPorts = new HashSet<>();
                Set<String> usedChildInPorts = new HashSet<>();
                Set<String> usedChildOutPorts = new HashSet<>();
                EList<Classifier> ctPlusAllExtended = ct.getSelfPlusAllExtended();
                EList<Classifier> subCtPlusAllExtended = subCt.getSelfPlusAllExtended();
                for (Connection conn : ((ComponentImplementation) comp).getAllConnections()) {
                    {
                        NamedElement sourceNe = conn.getSource().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedChildOutPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same output " + sourceNe.getQualifiedName() + ".");
                            }
                            usedChildOutPorts.add(sourceNe.getName());
                        }
                        if (ctPlusAllExtended.contains(sourceNe.getContainingClassifier())) {
                            if (usedParentInPorts.contains(sourceNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection out of same input " + sourceNe.getQualifiedName() + ".");
                            }
                            usedParentInPorts.add(sourceNe.getName());
                        }
                    }
                    {
                        NamedElement destNe = conn.getDestination().getConnectionEnd();
                        if (subCtPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedChildInPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same input " + destNe.getQualifiedName() + ".");
                            }
                            usedChildInPorts.add(destNe.getName());
                        }
                        if (ctPlusAllExtended.contains(destNe.getContainingClassifier())) {
                            if (usedParentOutPorts.contains(destNe.getName())) {
                                error(lcst, "'lift contract;' statement is not allowed in component implementation whith more than one connection into same output " + destNe.getQualifiedName() + ".");
                            }
                            usedParentOutPorts.add(destNe.getName());
                        }
                    }
                }
                for (Feature feat : comp.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedParentInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection from input " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedParentOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection to output " + feat.getQualifiedName() + ".");
                        }
                    }
                }
                for (Feature feat : subCt.getAllFeatures()) {
                    boolean isIn = false;
                    if (feat instanceof DataPort) {
                        isIn = ((DataPort) feat).isIn();
                    } else if (feat instanceof EventDataPort) {
                        isIn = ((EventDataPort) feat).isIn();
                    } else if (feat instanceof EventPort) {
                        isIn = ((EventPort) feat).isIn();
                    }
                    if (isIn) {
                        if (!usedChildInPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection into " + feat.getQualifiedName() + ".");
                        }
                    } else {
                        if (!usedChildOutPorts.contains(feat.getName())) {
                            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout connection out of " + feat.getQualifiedName() + ".");
                        }
                    }
                }
            }
        } else {
            error(lcst, "'lift contract;' statement is not allowed in component implementation whithout exactly one subcomponent.");
        }
    } else {
        error(lcst, "'lift contract;' statement is not allowed in component interface.");
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Set(java.util.Set) HashSet(java.util.HashSet) Connection(org.osate.aadl2.Connection) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) Feature(org.osate.aadl2.Feature) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) EList(org.eclipse.emf.common.util.EList) EventPort(org.osate.aadl2.EventPort) Subcomponent(org.osate.aadl2.Subcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) EventDataPort(org.osate.aadl2.EventDataPort) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause) Check(org.eclipse.xtext.validation.Check)

Example 10 with AnnexSubclause

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

the class AgreeScopeProvider method getNamedElementsFromClassifier.

private Map<String, NamedElement> getNamedElementsFromClassifier(Classifier ctx, boolean fromCompImpl) {
    Map<String, NamedElement> components = new HashMap<>();
    components.putAll(getNamedElements(getAadlContainer(ctx)));
    for (AnnexSubclause annex : AnnexUtil.getAllAnnexSubclauses(ctx, AgreePackage.eINSTANCE.getAgreeContractSubclause())) {
        AgreeContract contract = (AgreeContract) ((AgreeContractSubclause) annex).getContract();
        components.putAll(getNamedElementsFromSpecs(contract.getSpecs()));
    }
    Classifier extended = ctx.getExtended();
    if (extended != null) {
        components.putAll(getNamedElementsFromClassifier(extended, false));
    }
    if (ctx instanceof ComponentImplementation) {
        components.putAll(getNamedElementsFromClassifier(((ComponentImplementation) ctx).getType(), true));
        ArrayList<NamedElement> nes = new ArrayList<>();
        nes.addAll(((ComponentImplementation) ctx).getAllSubcomponents());
        nes.addAll(((ComponentImplementation) ctx).getAllConnections());
        components.putAll(toNamedElementMap(nes));
    } else if (ctx instanceof ComponentType) {
        if (fromCompImpl) {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((ComponentType) ctx).getAllFeatures());
            components.putAll(toNamedElementMap(nes));
        } else {
            ArrayList<NamedElement> nes = new ArrayList<>();
            nes.addAll(((ComponentType) ctx).getOwnedFeatures());
            components.putAll(toNamedElementMap(nes));
        }
    }
    return components;
}
Also used : AgreeContract(com.rockwellcollins.atc.agree.agree.AgreeContract) ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) NamedElement(org.osate.aadl2.NamedElement) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Aggregations

AnnexSubclause (org.osate.aadl2.AnnexSubclause)54 ArrayList (java.util.ArrayList)23 DefaultAnnexSubclause (org.osate.aadl2.DefaultAnnexSubclause)21 EObject (org.eclipse.emf.ecore.EObject)19 Classifier (org.osate.aadl2.Classifier)17 CyberReq (com.ge.research.osate.verdict.dsl.verdict.CyberReq)15 Statement (com.ge.research.osate.verdict.dsl.verdict.Statement)15 Verdict (com.ge.research.osate.verdict.dsl.verdict.Verdict)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)15 SafetyReq (com.ge.research.osate.verdict.dsl.verdict.SafetyReq)14 NamedElement (org.osate.aadl2.NamedElement)14 CyberMission (com.ge.research.osate.verdict.dsl.verdict.CyberMission)13 CyberRel (com.ge.research.osate.verdict.dsl.verdict.CyberRel)13 Event (com.ge.research.osate.verdict.dsl.verdict.Event)13 SafetyRel (com.ge.research.osate.verdict.dsl.verdict.SafetyRel)13 ComponentImplementation (org.osate.aadl2.ComponentImplementation)13 EventDataPort (org.osate.aadl2.EventDataPort)13 EventPort (org.osate.aadl2.EventPort)13 ComponentType (org.osate.aadl2.ComponentType)12 DataPort (org.osate.aadl2.DataPort)12