public String formatKind(JCDiagnostic d, Locale l) { switch (d.getType()) { case FRAGMENT: return ""; case NOTE: return localize(l, "compiler.note.note"); case WARNING: return localize(l, "compiler.warn.warning"); case ERROR: return localize(l, "compiler.err.error"); default: throw new AssertionError("Unknown diagnostic type: " + d.getType()); } }
/** * Format the arguments of a given diagnostic. * * @param d diagnostic whose arguments are to be formatted * @param l locale object to be used for i18n * @return a Collection whose elements are the formatted arguments of the diagnostic */ protected Collection<String> formatArguments(JCDiagnostic d, Locale l) { ListBuffer<String> buf = new ListBuffer<String>(); for (Object o : d.getArgs()) { buf.append(formatArgument(d, o, l)); } return buf.toList(); }
public String formatSource(JCDiagnostic d, boolean fullname, Locale l) { JavaFileObject fo = d.getSource(); if (fo == null) throw new IllegalArgumentException(); // d should have source set if (fullname) return fo.getName(); else if (fo instanceof BaseFileObject) return ((BaseFileObject) fo).getShortName(); else return BaseFileObject.getSimpleName(fo); }
// where private long getPosition(JCDiagnostic d, PositionKind pk) { switch (pk) { case START: return d.getIntStartPosition(); case END: return d.getIntEndPosition(); case LINE: return d.getLineNumber(); case COLUMN: return d.getColumnNumber(); case OFFSET: return d.getIntPosition(); default: throw new AssertionError("Unknown diagnostic position: " + pk); } }
/** * Format the faulty source code line and point to the error. * * @param d The diagnostic for which the error line should be printed */ protected String formatSourceLine(JCDiagnostic d, int nSpaces) { StringBuilder buf = new StringBuilder(); DiagnosticSource source = d.getDiagnosticSource(); int pos = d.getIntPosition(); if (d.getIntPosition() == Position.NOPOS) throw new AssertionError(); String line = (source == null ? null : source.getLine(pos)); if (line == null) return ""; buf.append(indent(line, nSpaces)); int col = source.getColumnNumber(pos, false); if (config.isCaretEnabled()) { buf.append("\n"); for (int i = 0; i < col - 1; i++) { buf.append((line.charAt(i) == '\t') ? "\t" : " "); } buf.append(indent("^", nSpaces)); } return buf.toString(); }
/** * Format all the subdiagnostics attached to a given diagnostic. * * @param d diagnostic whose subdiagnostics are to be formatted * @param l locale object to be used for i18n * @return list of all string representations of the subdiagnostics */ protected List<String> formatSubdiagnostics(JCDiagnostic d, Locale l) { List<String> subdiagnostics = List.nil(); int maxDepth = config.getMultilineLimit(MultilineLimit.DEPTH); if (maxDepth == -1 || depth < maxDepth) { depth++; try { int maxCount = config.getMultilineLimit(MultilineLimit.LENGTH); int count = 0; for (JCDiagnostic d2 : d.getSubdiagnostics()) { if (maxCount == -1 || count < maxCount) { subdiagnostics = subdiagnostics.append(formatSubdiagnostic(d, d2, l)); count++; } else break; } } finally { depth--; } } return subdiagnostics; }
public boolean displaySource(JCDiagnostic d) { return config.getVisible().contains(DiagnosticPart.SOURCE) && d.getType() != FRAGMENT && d.getIntPosition() != Position.NOPOS; }
protected String formatLintCategory(JCDiagnostic d, Locale l) { LintCategory lc = d.getLintCategory(); if (lc == null) return ""; return localize(l, "compiler.warn.lintOption", lc.option); }
public String formatPosition(JCDiagnostic d, PositionKind pk, Locale l) { Assert.check(d.getPosition() != Position.NOPOS); return String.valueOf(getPosition(d, pk)); }