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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations