use of org.eclipse.ceylon.compiler.typechecker.parser.RecognitionError in project ceylon by eclipse.
the class ErrorCollectingVisitor method printErrors.
public int printErrors(Writer out, DiagnosticListener diagnosticListener, boolean printWarnings, boolean printCount) throws IOException {
int warnings = 0;
int count = 0;
List<PositionedMessage> errors = (!recogErrors.isEmpty()) ? recogErrors : analErrors;
for (PositionedMessage pm : errors) {
Message err = pm.message;
if (err instanceof UsageWarning) {
if (!printWarnings || ((UsageWarning) err).isSuppressed()) {
continue;
}
}
Node node = TreeUtil.getIdentifyingNode(pm.node);
int line = err.getLine();
int position = -1;
if (err instanceof AnalysisMessage) {
if (node != null && node.getToken() != null)
position = node.getToken().getCharPositionInLine();
} else if (err instanceof RecognitionError) {
position = ((RecognitionError) err).getCharacterInLine();
}
String fileName = (node.getUnit() != null) ? node.getUnit().getFullPath() : "unknown";
out.write(OSUtil.color(fileName, OSUtil.Color.blue));
out.write(":");
out.write(String.format("%d", line));
out.write(": ");
if (err instanceof UsageWarning) {
out.write(OSUtil.color("warning", OSUtil.Color.yellow));
warnings++;
} else {
out.write(OSUtil.color("error", OSUtil.Color.red));
count++;
}
out.write(": ");
out.write(err.getMessage());
out.write(System.lineSeparator());
String ln = getErrorSourceLine(pm);
if (ln != null) {
out.write(ln);
out.write(System.lineSeparator());
out.write(getErrorMarkerLine(position));
out.write(System.lineSeparator());
}
if (diagnosticListener != null) {
File file = null;
boolean warning = err instanceof UsageWarning;
if (node.getUnit() != null && node.getUnit().getFullPath() != null)
file = new File(node.getUnit().getFullPath()).getAbsoluteFile();
if (position != -1)
// make it 1-based
position++;
if (warning)
diagnosticListener.warning(file, line, position, err.getMessage());
else
diagnosticListener.error(file, line, position, err.getMessage());
}
}
if (printCount) {
if (count > 0)
out.write(String.format("%d %s%n", count, count == 1 ? "error" : "errors"));
if (warnings > 0)
out.write(String.format("%d %s%n", warnings, warnings == 1 ? "warning" : "warnings"));
}
out.flush();
return count;
}
Aggregations