private static String formatMessage( String checkName, JavaFileObject file, DiagnosticPosition pos, Throwable cause) { DiagnosticSource source = new DiagnosticSource(file, /*log=*/ null); int column = source.getColumnNumber(pos.getStartPosition(), /*expandTabs=*/ true); int line = source.getLineNumber(pos.getStartPosition()); String snippet = source.getLine(pos.getStartPosition()); StringBuilder sb = new StringBuilder(); sb.append( String.format( "\n%s:%d: %s: An exception was thrown by Error Prone: %s\n", source.getFile().getName(), line, checkName, cause.getMessage())); sb.append(snippet).append('\n'); if (column > 0) { sb.append(Strings.repeat(" ", column - 1)); } sb.append("^\n"); return sb.toString(); }
PossibleFix(Tree tree) { this.tree = tree; DiagnosticPosition position = (DiagnosticPosition) tree; this.startPosition = position.getStartPosition(); this.endPosition = position.getEndPosition(compilationUnit.endPositions); this.trace = new RuntimeException(); }
int startPos = pos.getStartPosition(); int preferredPos = pos.getPreferredPosition(); int endPos = pos.getEndPosition(endPosTable);
void translate() { make.at(pos.getStartPosition()); JCClassDecl owner = classDef((ClassSymbol)mapVar.owner);
void translate() { make.at(pos.getStartPosition()); JCClassDecl owner = classDef((ClassSymbol)mapVar.owner);
void translate() { make.at(pos.getStartPosition()); JCClassDecl owner = classDef((ClassSymbol)mapVar.owner);
void translate() { make.at(pos.getStartPosition()); JCClassDecl owner = classDef((ClassSymbol)mapVar.owner);
String key, Object... args) { if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) throw new IllegalArgumentException(); this.args = args; int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); if (n == Position.NOPOS || source == null) line = column = -1;
String key, Object ... args) { if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) throw new IllegalArgumentException(); this.args = args; int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); if (n == Position.NOPOS || source == null) line = column = -1;
public void analyzeTree(Env<?> env, JCTree tree) { try { startPos = tree.pos().getStartPosition();
String key, Object ... args) { if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) throw new IllegalArgumentException(); this.args = args; int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); if (n == Position.NOPOS || source == null) line = column = -1;
/** * Create a diagnostic object. * @param formatter the formatter to use for the diagnostic * @param dt the type of diagnostic * @param lc the lint category for the diagnostic * @param source the name of the source file, or null if none. * @param pos the character offset within the source file, if given. * @param key a resource key to identify the text of the diagnostic * @param args arguments to be included in the text of the diagnostic */ protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter, DiagnosticType dt, LintCategory lc, Set<DiagnosticFlag> flags, DiagnosticSource source, DiagnosticPosition pos, String key, Object... args) { if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS) throw new IllegalArgumentException(); this.defaultFormatter = formatter; this.type = dt; this.lintCategory = lc; this.flags = flags; this.source = source; this.position = pos; this.key = key; this.args = args; }
public void analyzeTree(Env<?> env, JCTree tree) { try { startPos = tree.pos().getStartPosition();
public void report(ReportingPolicy reportingPolicy, DiagnosticPosition pos, String key, Object... params) { if (reportingPolicy == ReportingPolicy.ERROR) { if (registeredResourceBundle) { log.error(pos.getPreferredPosition(), key, params); } else { MessageFormat format = new MessageFormat(messages.getFormat(DeptectiveMessages.ERROR_PREFIX, key)); log.rawError(pos.getPreferredPosition(), format.format(params)); } } else { if (registeredResourceBundle) { log.strictWarning(pos, key, params); } else { MessageFormat format = new MessageFormat(messages.getFormat(DeptectiveMessages.WARNING_PREFIX, key)); log.rawWarning(pos.getPreferredPosition(), format.format(params)); } } }
private static String formatMessage( String checkName, JavaFileObject file, DiagnosticPosition pos, Throwable cause) { DiagnosticSource source = new DiagnosticSource(file, /*log=*/ null); int column = source.getColumnNumber(pos.getStartPosition(), /*expandTabs=*/ true); int line = source.getLineNumber(pos.getStartPosition()); String snippet = source.getLine(pos.getStartPosition()); StringBuilder sb = new StringBuilder(); sb.append( String.format( "\n%s:%d: %s: An exception was thrown by Error Prone: %s\n", source.getFile().getName(), line, checkName, cause.getMessage())); sb.append(snippet).append('\n'); if (column > 0) { sb.append(Strings.repeat(" ", column - 1)); } sb.append("^\n"); return sb.toString(); }
/** * Report a syntax error using the given DiagnosticPosition object and * arguments, unless one was already reported at the same position. */ private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) { int pos = diagPos.getPreferredPosition(); if (pos > S.errPos() || pos == Position.NOPOS) { if (token.kind == EOF) { error(diagPos, "premature.eof"); } else { error(diagPos, key, args); } } S.errPos(pos); if (token.pos == errorPos) nextToken(); // guarantee progress errorPos = token.pos; }
/** * Report a syntax error using the given DiagnosticPosition object and * arguments, unless one was already reported at the same position. */ private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) { int pos = diagPos.getPreferredPosition(); if (pos > S.errPos() || pos == Position.NOPOS) { if (token.kind == EOF) { error(diagPos, "premature.eof"); } else { error(diagPos, key, args); } } S.errPos(pos); if (token.pos == errorPos) nextToken(); // guarantee progress errorPos = token.pos; }
protected int getIntStartPosition() { return (position == null ? Position.NOPOS : position.getStartPosition()); }
protected int getIntPosition() { return (position == null ? Position.NOPOS : position.getPreferredPosition()); }