Class ReplacementVariableFinder

java.lang.Object
com.google.errorprone.bugpatterns.ReplacementVariableFinder

public final class ReplacementVariableFinder extends Object
Utility methods to find replacement variables with similar names.
  • Method Details

    • fixesByReplacingExpressionWithLocallyDeclaredField

      public static com.google.common.collect.ImmutableList<Fix> fixesByReplacingExpressionWithLocallyDeclaredField(com.sun.source.tree.ExpressionTree input, Predicate<com.sun.tools.javac.tree.JCTree.JCVariableDecl> validFieldPredicate, VisitorState state)
      Suggest replacing input with a qualified reference to a locally declared field with a similar or the same name as the input expression.
      Parameters:
      input - a MEMBER_SELECT or IDENTIFIER expression which should be replaced.
      validFieldPredicate - Predicate used to decide which locally declared fields are appropriate candidates for replacement (e.g.: is the appropriate type)
    • fixesByReplacingExpressionWithMethodParameter

      public static com.google.common.collect.ImmutableList<Fix> fixesByReplacingExpressionWithMethodParameter(com.sun.source.tree.ExpressionTree input, Predicate<com.sun.tools.javac.tree.JCTree.JCVariableDecl> validParameterPredicate, VisitorState state)
      Suggest replacing input with a reference to a method parameter in the nearest enclosing method declaration with a similar or the same name as the input expression.
      Parameters:
      input - a MEMBER_SELECT or IDENTIFIER expression which should be replaced.
      validParameterPredicate - Predicate used to decide which method parameters are appropriate candidates for replacement (e.g.: is the appropriate type)