public ReplacementFix(DiagnosticPosition original, String replacement) { checkArgument(original.getStartPosition() >= 0, "invalid start position"); this.original = original; this.replacement = replacement; }
protected InsertionFix(DiagnosticPosition position, String insertion) { checkArgument(position.getStartPosition() >= 0, "invalid start position"); this.position = position; this.insertion = insertion; }
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(); }
/** The qualifier to be used for accessing a symbol in an outer class. * This is either C.sym or C.this.sym, depending on whether or not * sym is static. * @param sym The accessed symbol. */ JCExpression accessBase(DiagnosticPosition pos, Symbol sym) { return (sym.flags() & STATIC) != 0 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner)) : makeOwnerThis(pos, sym, true); }
@Override protected int getInsertionIndex(EndPosTable endPositions) { return position.getStartPosition(); } }
protected InsertionFix(DiagnosticPosition position, String insertion) { checkArgument(position.getStartPosition() >= 0, "invalid start position"); this.position = position; this.insertion = insertion; }
/** Reassign current position. */ public TreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
/** Reassign current position. */ public TreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
/** The qualifier to be used for accessing a symbol in an outer class. * This is either C.sym or C.this.sym, depending on whether or not * sym is static. * @param sym The accessed symbol. */ JCExpression accessBase(DiagnosticPosition pos, Symbol sym) { return (sym.flags() & STATIC) != 0 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner)) : makeOwnerThis(pos, sym, true); }
/** Reassign current position. */ public TreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
public ReplacementFix(DiagnosticPosition original, String replacement) { checkArgument(original.getStartPosition() >= 0, "invalid start position"); this.original = original; this.replacement = replacement; }
/** The qualifier to be used for accessing a symbol in an outer class. * This is either C.sym or C.this.sym, depending on whether or not * sym is static. * @param sym The accessed symbol. */ JCExpression accessBase(DiagnosticPosition pos, Symbol sym) { return (sym.flags() & STATIC) != 0 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner)) : makeOwnerThis(pos, sym, true); }
/** The qualifier to be used for accessing a symbol in an outer class. * This is either C.sym or C.this.sym, depending on whether or not * sym is static. * @param sym The accessed symbol. */ JCExpression accessBase(DiagnosticPosition pos, Symbol sym) { return (sym.flags() & STATIC) != 0 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner)) : makeOwnerThis(pos, sym, true); }
/** Reassign current position. */ public TreeMaker at(DiagnosticPosition pos) { this.pos = (pos == null ? Position.NOPOS : pos.getStartPosition()); return this; }
@Override public Replacement getReplacement(EndPosTable endPositions) { return Replacement.create( original.getStartPosition(), original.getEndPosition(endPositions), replacement); } }
private int getStartPos(JCTree tree) { return tree.pos().getStartPosition(); }
/** * determines whether a lambda parameter is missing an explicit type declaration * * @param lambdaParameter the parameter * @return true if there is no type declaration, false otherwise */ public static boolean lambdaParamIsImplicitlyTyped(VariableTree lambdaParameter) { // kind of a hack; the "preferred position" seems to be the position // of the variable name. if this differs from the start position, it // means there is an explicit type declaration JCDiagnostic.DiagnosticPosition diagnosticPosition = (JCDiagnostic.DiagnosticPosition) lambdaParameter; return diagnosticPosition.getStartPosition() == diagnosticPosition.getPreferredPosition(); }
@Override public Replacement getReplacement(EndPosTable endPositions) { return Replacement.create( original.getStartPosition(), original.getEndPosition(endPositions), replacement); } }
@Override protected int getInsertionIndex(EndPosTable endPositions) { return position.getStartPosition(); } }
PossibleFix(Tree tree) { this.tree = tree; DiagnosticPosition position = (DiagnosticPosition) tree; this.startPosition = position.getStartPosition(); this.endPosition = position.getEndPosition(compilationUnit.endPositions); this.trace = new RuntimeException(); }