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