Search in sources :

Example 1 with SystemInstance

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;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) SystemInstance(org.osate.aadl2.instance.SystemInstance) EObject(org.eclipse.emf.ecore.EObject) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EObjectNode(org.eclipse.xtext.ui.editor.outline.impl.EObjectNode)

Example 2 with SystemInstance

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;
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 3 with SystemInstance

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;
}
Also used : InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Resource(org.eclipse.emf.ecore.resource.Resource) Aadl2Factory(org.osate.aadl2.Aadl2Factory) WorkspaceEditingDomainFactory(org.eclipse.emf.workspace.WorkspaceEditingDomainFactory) IOException(java.io.IOException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) TransactionalCommandStack(org.eclipse.emf.transaction.TransactionalCommandStack) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 4 with SystemInstance

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;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) Resource(org.eclipse.emf.ecore.resource.Resource) Aadl2Factory(org.osate.aadl2.Aadl2Factory) WorkspaceEditingDomainFactory(org.eclipse.emf.workspace.WorkspaceEditingDomainFactory) IOException(java.io.IOException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) RollbackException(org.eclipse.emf.transaction.RollbackException) IOException(java.io.IOException) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) TransactionalCommandStack(org.eclipse.emf.transaction.TransactionalCommandStack) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) SystemInstance(org.osate.aadl2.instance.SystemInstance)

Example 5 with SystemInstance

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();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AnalysisResult(jkind.api.results.AnalysisResult) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) IHandlerService(org.eclipse.ui.handlers.IHandlerService) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Aggregations

SystemInstance (org.osate.aadl2.instance.SystemInstance)89 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)50 InstanceObject (org.osate.aadl2.instance.InstanceObject)24 ComponentImplementation (org.osate.aadl2.ComponentImplementation)23 Element (org.osate.aadl2.Element)22 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)20 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)16 Classifier (org.osate.aadl2.Classifier)15 NamedElement (org.osate.aadl2.NamedElement)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 EList (org.eclipse.emf.common.util.EList)12 IStatus (org.eclipse.core.runtime.IStatus)10 Status (org.eclipse.core.runtime.Status)10 AadlPackage (org.osate.aadl2.AadlPackage)10 ArrayList (java.util.ArrayList)9 Optional (java.util.Optional)9 Test (org.junit.Test)9 ModeInstance (org.osate.aadl2.instance.ModeInstance)9