use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class SimulationLaunchShortcut method getComponentImplementation.
private ComponentImplementation getComponentImplementation(final ISelection selection) {
ComponentImplementation componentImplementation = null;
// Determine a component implementation based on the current selection
if (selection instanceof IStructuredSelection) {
final Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
if (selectedObject instanceof IFile) {
final IFile iFile = (IFile) selectedObject;
final ResourceSet resourceSet = new ResourceSetImpl();
final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(iFile.getFullPath().toString(), true), true);
if (resource != null) {
if (resource.getContents().size() > 0) {
final SystemInstance systemInstance = (SystemInstance) resource.getContents().get(0);
componentImplementation = systemInstance.getComponentImplementation();
}
}
} else if (selectedObject instanceof EObjectNode) {
final EObject selectedEObject = selectionHelper.getEObject((EObjectNode) selectedObject);
if (selectedEObject instanceof ComponentImplementation) {
componentImplementation = (ComponentImplementation) selectedEObject;
}
} else {
componentImplementation = graphicalEditorSelectionHelper.getComponentImplementationByApplicableObject(selectedObject);
}
}
return componentImplementation;
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class AgreeUtils method getInstanceImplementation.
public static ComponentImplementation getInstanceImplementation(ComponentInstance compInst) {
if (compInst instanceof SystemInstance) {
ComponentImplementation ci;
ci = ((SystemInstance) compInst).getComponentImplementation();
return ci;
}
try {
return (ComponentImplementation) compInst.getComponentClassifier();
} catch (ClassCastException e) {
return null;
}
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromImplementation.
/**
* Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
* <p>
* Ephemerally generated system instances are placed it in an ephemeral {@link Resource}. The ephemeral
* resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
*
* @param ct The component type for which to create an ephemeral implementation.
* @return A system instance for the given component type.
* @throws Exception
* @since 2.8
*/
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromImplementation(ComponentImplementation ci) throws Exception {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(ci));
ephemeralResources.add(instanceAadlResource);
List<SystemInstance> instanceResultList;
SystemInstance instanceResult;
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command instanceCmd = new RecordingCommand(domain) {
public SystemInstance systemInstance;
@Override
protected void doExecute() {
try {
final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
systemInstance = instantiateModel.createSystemInstance(ci, instanceAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
}
}
@Override
public List<SystemInstance> getResult() {
return Collections.singletonList(systemInstance);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
monitor.subTask("Saving instance model");
instanceAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
instanceResult = instanceResultList.get(0);
return instanceResult;
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class EphemeralImplementationUtil method generateEphemeralCompInstanceFromType.
/**
* Generate an ephemeral {@link SystemInstance} matching the subtype of the given {@link ComponentType}.
* <p>
* Ephemerally generated system instances are placed it in an ephemeral {@link Resource}. The ephemeral
* resources are intended to have short lifecycles and deleted by the {@link cleanup} method.
*
* @param ct The component type for which to create an ephemeral implementation.
* @return A system instance for the given component type.
* @throws Exception
* @since 2.8
*/
@SuppressWarnings("unchecked")
public SystemInstance generateEphemeralCompInstanceFromType(ComponentType ct) throws Exception {
Resource implementationAadlResource = getResource(getEphemeralImplURI(ct));
ephemeralResources.add(implementationAadlResource);
List<ComponentImplementation> implementationResultList;
ComponentImplementation implementationResult;
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
Command implementationCmd = new RecordingCommand(domain) {
public ComponentImplementation implementation;
@Override
protected void doExecute() {
try {
implementation = createComponentImplementationInternal(ct, implementationAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
}
}
@Override
public List<ComponentImplementation> getResult() {
return Collections.singletonList(implementation);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(implementationCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
// We don't respond to a cancel at this point
monitor.subTask("Saving implementation model");
implementationAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
implementationResultList = (List<ComponentImplementation>) implementationCmd.getResult();
implementationResult = implementationResultList.get(0);
Resource instanceAadlResource = getResource(InstantiateModel.getInstanceModelURI(implementationResult));
ephemeralResources.add(instanceAadlResource);
List<SystemInstance> instanceResultList;
SystemInstance instanceResult;
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command instanceCmd = new RecordingCommand(domain) {
public SystemInstance systemInstance;
@Override
protected void doExecute() {
try {
final InstantiateModel instantiateModel = new InstantiateModel(monitor, new AnalysisErrorReporterManager(new MarkerAnalysisErrorReporter.Factory(AadlConstants.INSTANTIATION_OBJECT_MARKER)));
systemInstance = instantiateModel.createSystemInstance(implementationResult, instanceAadlResource);
} catch (InterruptedException e) {
// Do nothing. Will be thrown after execute.
} catch (Exception e) {
e.printStackTrace();
errorMessage = e.getMessage();
e.getMessage();
}
}
@Override
public List<SystemInstance> getResult() {
return Collections.singletonList(systemInstance);
}
};
((TransactionalCommandStack) domain.getCommandStack()).execute(instanceCmd, null);
if (monitor.isCanceled()) {
throw new InterruptedException();
}
try {
// We're done: Save the model.
monitor.subTask("Saving instance model");
instanceAadlResource.save(null);
} catch (IOException e) {
e.printStackTrace();
setErrorMessage(e.getMessage());
return null;
}
instanceResultList = (List<SystemInstance>) instanceCmd.getResult();
instanceResult = instanceResultList.get(0);
return instanceResult;
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class VerifyHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
// this flag is set by the rerun handler to prevent clearing the advice map
if (!calledFromRerun) {
rerunAdviceMap.clear();
}
calledFromRerun = false;
disableRerunHandler();
handlerService = getWindow().getService(IHandlerService.class);
try {
// Make sure the user selected a component implementation
ComponentImplementation ci = getComponentImplementation(root, implUtil);
SystemInstance si = getSysInstance(ci, implUtil);
AnalysisResult result;
CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
if (isRecursive()) {
if (AgreeUtils.usingKind2()) {
throw new AgreeException("Kind2 only supports monolithic verification");
}
result = buildAnalysisResult(ci.getName(), si);
wrapper.addChild(result);
result = wrapper;
} else if (isRealizability()) {
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
result = wrapper;
} else {
CompositeAnalysisResult wrapperTop = new CompositeAnalysisResult("Verification for " + ci.getName());
wrapVerificationResult(si, wrapperTop);
wrapper.addChild(wrapperTop);
result = wrapper;
}
showView(result, linker);
return doAnalysis(ci, monitor);
} catch (Throwable e) {
String messages = getNestedMessages(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
implUtil.cleanup();
}
}
Aggregations