Search in sources :

Example 1 with AnalysisErrorReporterManager

use of org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager 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 2 with AnalysisErrorReporterManager

use of org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager 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 3 with AnalysisErrorReporterManager

use of org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager in project AGREE by loonwerks.

the class VerifyHandler method getSysInstance.

protected SystemInstance getSysInstance(ComponentImplementation ci, EphemeralImplementationUtil implUtil) {
    try {
        AnalysisErrorReporterManager errorManager = new AnalysisErrorReporterManager(QueuingAnalysisErrorReporter.factory);
        SystemInstance result = implUtil.generateEphemeralCompInstanceFromImplementation(ci);
        QueuingAnalysisErrorReporter errorReporter = (QueuingAnalysisErrorReporter) errorManager.getReporter(result.eResource());
        StringBuilder stringBuilder = new StringBuilder();
        List<Message> instantiationMarkers = errorReporter.getErrors();
        if (!instantiationMarkers.isEmpty()) {
            instantiationMarkers.stream().forEach(marker -> {
                stringBuilder.append(marker.message);
            });
            throw new AgreeException(stringBuilder.toString());
        }
        return result;
    } catch (Exception e) {
        Dialog.showError("Model Instantiate", "Error while re-instantiating the model: " + e.getMessage());
        throw new AgreeException("Error Instantiating model");
    }
}
Also used : Message(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter.Message) SystemInstance(org.osate.aadl2.instance.SystemInstance) QueuingAnalysisErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingAnalysisErrorReporter) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) PartInitException(org.eclipse.ui.PartInitException) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) JKindException(jkind.JKindException)

Example 4 with AnalysisErrorReporterManager

use of org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager in project osate2 by osate.

the class AnnexParserAgent method processAnnexSection.

/**
 * Common functionality for processing either a {@link DefaultAnnexLibrary} or a {@link DefaultAnnexSubclause}.
 * Processing involves parsing the text, attaching the resulting {@link AnnexLibrary} or {@link AnnexSubclause} to
 * the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}, setting the modes for the resulting
 * {@link AnnexSubclause}, and either running the resolver or the linking service, depending upon which one if
 * available. If the resolver produces errors, then the {@link AnnexLibrary} or {@link AnnexSubclause} will be
 * detached from the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}. All error, warning, and info
 * messages that are produced from the parser, resolver, or linker will be passed along to
 * {@code diagnosticsConsumer}.
 *
 * @param <A> Type of the resulting annex section. Expected to be {@link AnnexLibrary} or {@link AnnexSubclause}.
 * @param <D> Type of the default annex section. Expected to be {@link DefaultAnnexLibrary} or
 *            {@link DefaultAnnexSubclause}.
 * @param defaultAnnexSection Either the {@link DefaultAnnexLibrary} or {@link DefaultAnnexSubclause}.
 * @param annexText Either the value of {@link DefaultAnnexLibrary#getSourceText()} or
 *                  {@link DefaultAnnexSubclause#getSourceText()}.
 * @param filename Name of the AADL file containing the annex section.
 * @param diagnosticsConsumer Used for handling error, warning, and info messages.
 * @param parserFunction Either
 *                       {@link AnnexParser#parseAnnexLibrary(String, String, String, int, int, ParseErrorReporter)}
 *                       or
 *                       {@link AnnexParser#parseAnnexSubclause(String, String, String, int, int, ParseErrorReporter)}.
 * @param setParsedAnnexSection Either {@link DefaultAnnexLibrary#setSourceText(String)} or
 *                              {@link DefaultAnnexSubclause#setSourceText(String)}.
 * @param copyModes Function for copying modes from the {@link DefaultAnnexSubclause} into the newly created
 *                  {@link AnnexSubclause}. When processing an annex library, {@code copyModes} is expected to be a
 *                  no-op {@link Consumer}.
 */
private <A extends NamedElement, D extends A> void processAnnexSection(D defaultAnnexSection, String annexText, String filename, IDiagnosticConsumer diagnosticsConsumer, ParserFunction<A> parserFunction, Consumer<A> setParsedAnnexSection, Consumer<A> copyModes) {
    INode node = NodeModelUtils.findActualNodeFor(defaultAnnexSection);
    int line = node.getStartLine() + computeLineOffset(node);
    int offset = AnnexUtil.getAnnexOffset(defaultAnnexSection);
    // look for plug-in parser
    String annexName = defaultAnnexSection.getName();
    if (annexText != null && annexText.length() > 6 && annexName != null) {
        // strip {** **} from annex text
        if (annexText.startsWith("{**")) {
            annexText = annexText.substring(3, annexText.length() - 3);
        }
        annexName = AnnexModel.filterDisabledAnnexes(defaultAnnexSection, annexName);
        AnnexParser ap = PARSER_REGISTRY.getAnnexParser(annexName);
        try {
            QueuingParseErrorReporter parseErrReporter = new QueuingParseErrorReporter();
            parseErrReporter.setContextResource(defaultAnnexSection.eResource());
            if (defaultAnnexSection instanceof AnnexSubclause) {
                AnnexUtil.setCurrentAnnexSubclause((AnnexSubclause) defaultAnnexSection);
            }
            A annexSection = parserFunction.parse(ap, annexName, annexText, filename, line, offset, parseErrReporter);
            if (defaultAnnexSection instanceof AnnexSubclause) {
                AnnexUtil.setCurrentAnnexSubclause(null);
            }
            if (ParseResultHolder.Factory.INSTANCE.adapt(defaultAnnexSection).getParseResult() == null) {
                // Only consume messages for non-Xtext annexes
                consumeMessages(parseErrReporter, diagnosticsConsumer, annexText, line, offset);
            }
            if (annexSection != null) {
                annexSection.setName(annexName);
                setParsedAnnexSection.accept(annexSection);
                // copy in modes list
                copyModes.accept(annexSection);
                // now resolve reference so we get messages if we have references to undefined items
                AnnexResolver resolver = RESOLVER_REGISTRY.getAnnexResolver(annexName);
                AnnexLinkingService linkingService = LINKING_SERVICE_REGISTRY.getAnnexLinkingService(annexName);
                if (resolver != null && parseErrReporter.getNumErrors() == 0) {
                    // Don't resolve any annex with parsing errors.
                    QueuingParseErrorReporter resolveErrReporter = new QueuingParseErrorReporter();
                    AnalysisErrorReporterManager resolveErrManager = new AnalysisErrorReporterManager(new AnalysisToParseErrorReporterAdapter.Factory(aadlRsrc -> resolveErrReporter));
                    resolver.resolveAnnex(annexName, Collections.singletonList(annexSection), resolveErrManager);
                    consumeMessages(resolveErrReporter, diagnosticsConsumer, annexText, line, offset);
                    if (resolveErrReporter.getNumErrors() != 0) {
                        AnnexValidator.setNoValidation(defaultAnnexSection, annexName);
                    }
                } else if (linkingService != null) {
                    try {
                        XtextResource res = (XtextResource) defaultAnnexSection.eResource();
                        ILinker linker = res.getLinker();
                        linker.linkModel(annexSection, diagnosticsConsumer);
                    } catch (Exception e) {
                        String message = "Linking Service error in " + filename + " at line " + line;
                        IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, e);
                        Activator.getDefault().getLog().log(status);
                    }
                }
            }
            if (parseErrReporter.getNumErrors() > 0) {
                AnnexValidator.setNoValidation(defaultAnnexSection, annexName);
            }
        } catch (RecognitionException e) {
            String message = "Major parsing error in " + filename + " at line " + line;
            IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message, e);
            Activator.getDefault().getLog().log(status);
        }
    }
}
Also used : AnnexParserRegistry(org.osate.annexsupport.AnnexParserRegistry) AnnexUtil(org.osate.annexsupport.AnnexUtil) StringUtils(org.apache.commons.lang.StringUtils) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) ParseErrorReporter(org.osate.aadl2.modelsupport.errorreporting.ParseErrorReporter) AnnexLinkingServiceRegistry(org.osate.annexsupport.AnnexLinkingServiceRegistry) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) NodeModelUtils(org.eclipse.xtext.nodemodel.util.NodeModelUtils) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) IStatus(org.eclipse.core.runtime.IStatus) RecognitionException(antlr.RecognitionException) AnnexLinkingService(org.osate.annexsupport.AnnexLinkingService) INode(org.eclipse.xtext.nodemodel.INode) AnnexRegistry(org.osate.annexsupport.AnnexRegistry) Message(org.osate.aadl2.modelsupport.errorreporting.QueuingParseErrorReporter.Message) XtextResource(org.eclipse.xtext.resource.XtextResource) AnnexParser(org.osate.annexsupport.AnnexParser) AnnexResolverRegistry(org.osate.annexsupport.AnnexResolverRegistry) Severity(org.eclipse.xtext.diagnostics.Severity) AnnexValidator(org.osate.annexsupport.AnnexValidator) Status(org.eclipse.core.runtime.Status) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) AnalysisToParseErrorReporterAdapter(org.osate.aadl2.modelsupport.errorreporting.AnalysisToParseErrorReporterAdapter) IDiagnosticConsumer(org.eclipse.xtext.diagnostics.IDiagnosticConsumer) ParseResultHolder(org.osate.annexsupport.ParseResultHolder) Consumer(java.util.function.Consumer) List(java.util.List) AnnexResolver(org.osate.annexsupport.AnnexResolver) AnnexModel(org.osate.annexsupport.AnnexModel) AnnexSubclause(org.osate.aadl2.AnnexSubclause) ILinker(org.eclipse.xtext.linking.ILinker) NamedElement(org.osate.aadl2.NamedElement) Activator(org.osate.xtext.aadl2.Activator) Collections(java.util.Collections) LazyLinker(org.eclipse.xtext.linking.lazy.LazyLinker) AnnexLibrary(org.osate.aadl2.AnnexLibrary) QueuingParseErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingParseErrorReporter) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) INode(org.eclipse.xtext.nodemodel.INode) ILinker(org.eclipse.xtext.linking.ILinker) IStatus(org.eclipse.core.runtime.IStatus) AnnexParser(org.osate.annexsupport.AnnexParser) XtextResource(org.eclipse.xtext.resource.XtextResource) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) RecognitionException(antlr.RecognitionException) AnalysisToParseErrorReporterAdapter(org.osate.aadl2.modelsupport.errorreporting.AnalysisToParseErrorReporterAdapter) AnnexLinkingService(org.osate.annexsupport.AnnexLinkingService) AnnexResolver(org.osate.annexsupport.AnnexResolver) QueuingParseErrorReporter(org.osate.aadl2.modelsupport.errorreporting.QueuingParseErrorReporter) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) RecognitionException(antlr.RecognitionException)

Example 5 with AnalysisErrorReporterManager

use of org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager in project osate2 by osate.

the class AbstractAaxlHandler method actionBody.

protected final void actionBody(final IProgressMonitor monitor, final Element root) {
    final Resource resource = root.eResource();
    errManager = new AnalysisErrorReporterManager(getAnalysisErrorReporterFactory());
    summaryReport = new StringBuffer();
    // Root cannot be null (see above)
    // init the context object. It is used by the lookup methods for initializing property references
    context = root instanceof SystemInstance ? ((SystemInstance) root).getComponentImplementation() : root;
    // Init the properties
    notFound.clear();
    initPropertyReferences();
    initializeAction((NamedElement) root);
    if (suppressErrorMessages() || !reportPropertyLookupErrors()) {
        // Run the command (indirectly)
        processAaxlAction(monitor, resource, root);
    }
    finalizeAction();
}
Also used : SystemInstance(org.osate.aadl2.instance.SystemInstance) Resource(org.eclipse.emf.ecore.resource.Resource) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager)

Aggregations

AnalysisErrorReporterManager (org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager)10 SystemInstance (org.osate.aadl2.instance.SystemInstance)7 Resource (org.eclipse.emf.ecore.resource.Resource)6 NamedElement (org.osate.aadl2.NamedElement)5 InvalidModelException (org.osate.aadl2.properties.InvalidModelException)4 IResource (org.eclipse.core.resources.IResource)3 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 InstanceFactory (org.osate.aadl2.instance.InstanceFactory)3 AssignmentResult (EAnalysis.BinPacking.AssignmentResult)2 IOException (java.io.IOException)2 Command (org.eclipse.emf.common.command.Command)2 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 RollbackException (org.eclipse.emf.transaction.RollbackException)2 TransactionalCommandStack (org.eclipse.emf.transaction.TransactionalCommandStack)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 WorkspaceEditingDomainFactory (org.eclipse.emf.workspace.WorkspaceEditingDomainFactory)2 Aadl2Factory (org.osate.aadl2.Aadl2Factory)2