Search in sources :

Example 1 with ErrorItem

use of de.prob.animator.domainobjects.ErrorItem in project prob2 by bendisposto.

the class AnimatorImpl method execute.

@SuppressWarnings("unused")
@Override
public synchronized void execute(final AbstractCommand command) {
    if (cli == null) {
        logger.error("Probcli is missing. Try \"upgrade\".");
        throw new CliError("no cli found");
    }
    if (DEBUG && !command.getSubcommands().isEmpty()) {
        List<AbstractCommand> cmds = command.getSubcommands();
        for (AbstractCommand abstractCommand : cmds) {
            execute(abstractCommand);
        }
    }
    if (command.blockAnimator()) {
        logger.trace("Blocking animator");
        startTransaction();
    }
    logger.trace("Starting execution of {}", command);
    do {
        IPrologResult result = processor.sendCommand(command);
        final List<ErrorItem> errorItems = getErrorItems();
        if (result instanceof YesResult && errorItems.isEmpty()) {
            logger.trace("Execution successful, processing result");
            try {
                command.processResult(((YesResult) result).getBindings());
            } catch (RuntimeException e) {
                this.kill();
                throw new CliError("Exception while processing command result", e);
            }
        } else {
            logger.trace("Execution unsuccessful, processing error");
            command.processErrorResult(result, errorItems);
        }
        logger.trace("Executed {} (completed: {}, interrupted: {})", command, command.isCompleted(), command.isInterrupted());
        if (!command.isCompleted() && Thread.currentThread().isInterrupted()) {
            logger.info("Stopping execution of {} because this thread was interrupted", command);
            break;
        }
    } while (!command.isCompleted());
    logger.trace("Done executing {}", command);
    if (command.blockAnimator()) {
        endTransaction();
        logger.trace("Unblocked animator");
    }
}
Also used : CliError(de.prob.exception.CliError) AbstractCommand(de.prob.animator.command.AbstractCommand) ErrorItem(de.prob.animator.domainobjects.ErrorItem)

Example 2 with ErrorItem

use of de.prob.animator.domainobjects.ErrorItem in project prob2 by bendisposto.

the class ProBError method convertParserExceptionToErrorItems.

private static List<ErrorItem> convertParserExceptionToErrorItems(BCompoundException e) {
    List<ErrorItem> errorItems = new ArrayList<>();
    for (BException bException : e.getBExceptions()) {
        List<ErrorItem.Location> errorItemlocations = new ArrayList<>();
        if (bException.getFilename() != null && bException.getCause() != null) {
            List<BException.Location> parserlocations = bException.getLocations();
            for (BException.Location location : parserlocations) {
                ErrorItem.Location loc = new ErrorItem.Location(bException.getFilename(), location.getStartLine(), location.getStartColumn(), location.getEndLine(), location.getEndColumn());
                errorItemlocations.add(loc);
            }
        }
        ErrorItem item = new ErrorItem(bException.getMessage(), ErrorItem.Type.ERROR, errorItemlocations);
        errorItems.add(item);
    }
    return errorItems;
}
Also used : ArrayList(java.util.ArrayList) ErrorItem(de.prob.animator.domainobjects.ErrorItem) BException(de.be4.classicalb.core.parser.exceptions.BException)

Example 3 with ErrorItem

use of de.prob.animator.domainobjects.ErrorItem in project prob2 by bendisposto.

the class ProBError method formatMessageAndErrors.

private static String formatMessageAndErrors(final String message, final List<ErrorItem> errors) {
    final StringBuilder out = new StringBuilder();
    if (message != null && !message.isEmpty()) {
        out.append(message);
        if (errors != null) {
            out.append('\n');
        }
    }
    if (errors != null) {
        if (errors.isEmpty()) {
            out.append("ProB returned no error messages.");
        } else {
            out.append("ProB returned error messages:");
            for (final ErrorItem err : errors) {
                out.append('\n');
                out.append(err);
            }
        }
    }
    return out.toString();
}
Also used : ErrorItem(de.prob.animator.domainobjects.ErrorItem)

Aggregations

ErrorItem (de.prob.animator.domainobjects.ErrorItem)3 BException (de.be4.classicalb.core.parser.exceptions.BException)1 AbstractCommand (de.prob.animator.command.AbstractCommand)1 CliError (de.prob.exception.CliError)1 ArrayList (java.util.ArrayList)1