Search in sources :

Example 11 with SystemImplementation

use of org.osate.aadl2.SystemImplementation in project osate-plugin by sireum.

the class SireumTest method getSystemInstance.

protected SystemInstance getSystemInstance(AadlSystem system) {
    try {
        ResourceSet rset = createResourceSet(system.projects);
        Resource sysImplResource = null;
        String candURI = "platform:/resource/" + system.systemFileContainer.get().proj.projectName + "/" + system.systemFileContainer.get().projectRelativePath;
        for (Resource rs : rset.getResources()) {
            if (rs.getURI().toString().equals(candURI)) {
                sysImplResource = rs;
                break;
            }
        }
        if (sysImplResource != null) {
            final AadlPackage pkg = (AadlPackage) (sysImplResource.getContents().isEmpty() ? null : sysImplResource.getContents().get(0));
            SystemImplementation sysImpl = (SystemImplementation) AadlProjectUtil.getResourceByName(system.systemImplementationName, pkg.getOwnedPublicSection().getOwnedClassifiers());
            return InstantiateModel.instantiate(sysImpl);
        } else {
            throw new RuntimeException("Couldn't find resource " + system.systemFileContainer.get().systemImplementationFile);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.exit(1);
    return null;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) SystemImplementation(org.osate.aadl2.SystemImplementation) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException)

Example 12 with SystemImplementation

use of org.osate.aadl2.SystemImplementation in project osate-plugin by sireum.

the class AbstractSireumHandler method getSystemInstance.

protected SystemInstance getSystemInstance(Element e) {
    if (e != null) {
        if (e instanceof SystemInstance) {
            return (SystemInstance) e;
        }
        if (e instanceof SystemImplementation) {
            try {
                SystemImplementation si = (SystemImplementation) e;
                writeToConsole("Generating System Instance ...");
                return InstantiateModel.buildInstanceModelFile(si);
            } catch (Exception ex) {
                Dialog.showError(getToolName(), "Could not instantiate model");
                ex.printStackTrace();
            }
        }
    }
    return null;
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) SystemImplementation(org.osate.aadl2.SystemImplementation) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 13 with SystemImplementation

use of org.osate.aadl2.SystemImplementation in project osate-plugin by sireum.

the class AbstractSireumHandler method getElement.

private Element getElement(ExecutionEvent e) {
    Element root = AadlUtil.getElement(getCurrentSelection(e));
    if (root == null) {
        root = SelectionHelper.getSelectedSystemImplementation();
    }
    if (root == null) {
        ISelection selection = SelectionHelper.getSelection();
        if (selection instanceof TreeSelection) {
            TreeSelection ts = (TreeSelection) selection;
            List<SystemImplementation> candidates = new ArrayList<>();
            for (Object o : ts.toList()) {
                if (o instanceof EObjectNode) {
                    EObjectNode eon = (EObjectNode) o;
                    EObject eo = SelectionHelper.getXtextEditor().getDocument().readOnly(resource -> {
                        return eon.getEObject(resource);
                    });
                    if (eo instanceof SystemImplementation) {
                        candidates.add((SystemImplementation) eo);
                    }
                }
            }
            if (candidates.size() == 1) {
                // selected items in outline view only include a single system implementation
                // so use that
                root = candidates.get(0);
            }
        } else if (selection instanceof TextSelection) {
            TextSelection ts = (TextSelection) selection;
            EObject selectedObject = SelectionHelper.getEObjectFromSelection(selection);
            if (selectedObject instanceof SystemType) {
                // cursor is probably in the xx part of 'system implementation xx.yy ...'
                SystemType st = (SystemType) selectedObject;
                // find all system implementations of st and see if the cursor
                // is in one of them
                AadlPackage ap = AadlUtil.getContainingPackage(st);
                for (SystemImplementation si : EcoreUtil2.getAllContentsOfType(ap, SystemImplementation.class)) {
                    if (si.getType().equals(st)) {
                        INode node = NodeModelUtils.findActualNodeFor(si);
                        if (// 
                        node != null && (// 
                        node.getStartLine() <= ts.getStartLine() + 1 && ts.getEndLine() + 1 <= node.getEndLine())) {
                            root = si;
                        }
                    }
                }
            }
        }
    }
    return root;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) AadlPackage(org.osate.aadl2.AadlPackage) TextSelection(org.eclipse.jface.text.TextSelection) Element(org.osate.aadl2.Element) ArrayList(java.util.ArrayList) SystemType(org.osate.aadl2.SystemType) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode) TreeSelection(org.eclipse.jface.viewers.TreeSelection) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) ISelection(org.eclipse.jface.viewers.ISelection) EObject(org.eclipse.emf.ecore.EObject)

Example 14 with SystemImplementation

use of org.osate.aadl2.SystemImplementation in project osate-plugin by sireum.

the class SelectionHelper method getSelectedSystemImplementation.

// Returns the SystemImplementation that is currently selected. If the
// current selection is an object inside a SystemImplementation, such as a
// PropertyAssociation, the SystemImplementaiton
// is returned. If the selection is not inside a SystemImplementation, then
// null is returned
public static SystemImplementation getSelectedSystemImplementation(ISelection selection) {
    EObject selectedObject = getEObjectFromSelection(selection);
    // Return the object if it is a system implementation
    if (selectedObject instanceof SystemImplementation) {
        return (SystemImplementation) selectedObject;
    }
    // etc
    if (selectedObject instanceof Element) {
        Element aadlObject = (Element) selectedObject;
        Classifier containingClassifier = aadlObject.getContainingClassifier();
        if (containingClassifier instanceof SystemImplementation) {
            return (SystemImplementation) containingClassifier;
        }
    }
    return null;
}
Also used : SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Element(org.osate.aadl2.Element) Classifier(org.osate.aadl2.Classifier)

Example 15 with SystemImplementation

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

the class VerdictJavaValidator method checkStatement.

/**
 * Check that cyber relations/requirements have unique, non-empty IDs
 * and they are only located in subsystems/top-level systems, respectively.
 *
 * @param statement
 */
@Check(CheckType.FAST)
public void checkStatement(Statement statement) {
    String statementType;
    boolean shouldBeSubcomponent;
    if (statement instanceof CyberRel) {
        statementType = "Cyber relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof CyberReq) {
        statementType = "Cyber requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof CyberMission) {
        statementType = "Mission";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyReq) {
        statementType = "Safety requirement";
        shouldBeSubcomponent = false;
    } else if (statement instanceof SafetyRel) {
        statementType = "Safety relation";
        shouldBeSubcomponent = true;
    } else if (statement instanceof Event) {
        statementType = "Event";
        shouldBeSubcomponent = true;
    } else {
        throw new RuntimeException("statement is not CyberRel, or CyberReq, or Mission, or SafetyReq, or SafetyRel, or Event!?");
    }
    if (statement.getId().length() == 0) {
        error(statementType + " must specify an ID", VerdictPackage.Literals.STATEMENT__ID);
        return;
    }
    // Find enclosing system
    EObject container = statement;
    while (container != null && !(container instanceof SystemType || container instanceof PublicPackageSection)) {
        container = container.eContainer();
    }
    /*
		 * Within the same component, we need to make sure that cyber relations, cyber requirements,
		 * safety relations, safety missions, events do not have naming conflicts respectively.
		 */
    Set<String> otherIds = new HashSet<>();
    if (container instanceof SystemType) {
        SystemType currentSystem = (SystemType) container;
        // Get enclosing file
        while (!(container instanceof PublicPackageSection)) {
            container = container.eContainer();
        }
        // Get all verdict annexes for this system
        for (AnnexSubclause annex : currentSystem.getOwnedAnnexSubclauses()) {
            if ("verdict".equals(annex.getName())) {
                Verdict subclause = VerdictUtil.getVerdict(annex);
                // We only check that within the same statement category, there should not be naming conflicts.
                for (Statement other : subclause.getElements()) {
                    // Don't double-count self
                    if (!statement.equals(other)) {
                        if ((statement instanceof CyberRel) && (other instanceof CyberRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberReq) && (other instanceof CyberReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof CyberMission) && (other instanceof CyberMission)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyReq) && (other instanceof SafetyReq)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof SafetyRel) && (other instanceof SafetyRel)) {
                            otherIds.add(other.getId());
                        } else if ((statement instanceof Event) && (other instanceof Event)) {
                            otherIds.add(other.getId());
                        }
                    }
                }
            }
        }
        /*
			 * A system is a top-level system if it is not a subcomponent
			 * of any other system (cyber/safety requirements are valid).
			 *
			 * If it is a subcomponent of another system, then it is a
			 * subcomponent (cyber/safety relations are valid).
			 */
        PublicPackageSection pack = (PublicPackageSection) container;
        // Find all system impls
        for (Classifier cls : pack.getOwnedClassifiers()) {
            if (cls instanceof SystemImplementation) {
                // Grab the dependency/subcomponent tree
                SystemImplementation systemImpl = (SystemImplementation) cls;
                for (Subcomponent sub : systemImpl.getAllSubcomponents()) {
                    if (sub.getComponentImplementation() != null) {
                        subcomponents.add(sub.getComponentImplementation().getType());
                    }
                    subcomponents.add(sub.getSubcomponentType());
                }
            }
        }
        boolean isSubcomponent = subcomponents.contains(currentSystem);
        if (isSubcomponent && !shouldBeSubcomponent) {
            warning(statementType + " not allowed in subcomponent system");
        } else if (!isSubcomponent && shouldBeSubcomponent) {
            warning(statementType + " not allowed in top-level system");
        }
        if (otherIds.contains(statement.getId())) {
            error("Duplicate ID " + statement.getId(), VerdictPackage.Literals.STATEMENT__ID);
        }
    }
    // Perform extra checks for missions
    if (statement instanceof CyberMission) {
        checkMission((CyberMission) statement);
    }
    // And cyber reqs
    if (statement instanceof CyberReq) {
        checkCyberReq((CyberReq) statement);
    }
}
Also used : CyberRel(com.ge.research.osate.verdict.dsl.verdict.CyberRel) CyberMission(com.ge.research.osate.verdict.dsl.verdict.CyberMission) CyberReq(com.ge.research.osate.verdict.dsl.verdict.CyberReq) ThreatStatement(com.ge.research.osate.verdict.dsl.verdict.ThreatStatement) Statement(com.ge.research.osate.verdict.dsl.verdict.Statement) SystemType(org.osate.aadl2.SystemType) Classifier(org.osate.aadl2.Classifier) PublicPackageSection(org.osate.aadl2.PublicPackageSection) SafetyRel(com.ge.research.osate.verdict.dsl.verdict.SafetyRel) SystemImplementation(org.osate.aadl2.SystemImplementation) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) Event(com.ge.research.osate.verdict.dsl.verdict.Event) SafetyReq(com.ge.research.osate.verdict.dsl.verdict.SafetyReq) AnnexSubclause(org.osate.aadl2.AnnexSubclause) HashSet(java.util.HashSet) Verdict(com.ge.research.osate.verdict.dsl.verdict.Verdict) Check(org.eclipse.xtext.validation.Check)

Aggregations

SystemImplementation (org.osate.aadl2.SystemImplementation)18 EObject (org.eclipse.emf.ecore.EObject)11 SystemType (org.osate.aadl2.SystemType)8 AadlPackage (org.osate.aadl2.AadlPackage)7 HashSet (java.util.HashSet)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 AbstractImplementation (org.osate.aadl2.AbstractImplementation)4 AbstractType (org.osate.aadl2.AbstractType)4 BusImplementation (org.osate.aadl2.BusImplementation)4 BusType (org.osate.aadl2.BusType)4 DeviceImplementation (org.osate.aadl2.DeviceImplementation)4 DeviceType (org.osate.aadl2.DeviceType)4 MemoryImplementation (org.osate.aadl2.MemoryImplementation)4 MemoryType (org.osate.aadl2.MemoryType)4 ProcessImplementation (org.osate.aadl2.ProcessImplementation)4 ProcessType (org.osate.aadl2.ProcessType)4 ProcessorImplementation (org.osate.aadl2.ProcessorImplementation)4 ProcessorType (org.osate.aadl2.ProcessorType)4 Property (org.osate.aadl2.Property)4