Class FindIdentifiers

java.lang.Object
com.google.errorprone.util.FindIdentifiers

public final class FindIdentifiers extends Object
A helper class to find all identifiers in scope at a given program point.
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.google.common.collect.ImmutableList<com.sun.tools.javac.code.Symbol.VarSymbol>
    findAllFields(com.sun.tools.javac.code.Type classType, VisitorState state)
    Finds all the visible fields declared or inherited in the target class
    static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol.VarSymbol>
    Finds the set of all bare variable identifiers in scope at the current location.
    static com.sun.tools.javac.code.Symbol
    Finds a variable declaration with the given name that is in scope at the current location.
    static com.sun.tools.javac.code.Symbol
    findIdent(String name, VisitorState state, com.sun.tools.javac.code.Kinds.KindSelector kind)
    Finds a declaration with the given name and type that is in scope at the current location.
    static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol>
    findReferencedIdentifiers(com.sun.source.tree.Tree tree)
    Find the set of all identifiers referenced within this Tree
    static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol.VarSymbol>
    Finds all variable declarations which are unused at this point in the AST (i.e.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • findIdent

      public static com.sun.tools.javac.code.Symbol findIdent(String name, VisitorState state)
      Finds a variable declaration with the given name that is in scope at the current location.
    • findIdent

      @Nullable public static com.sun.tools.javac.code.Symbol findIdent(String name, VisitorState state, com.sun.tools.javac.code.Kinds.KindSelector kind)
      Finds a declaration with the given name and type that is in scope at the current location.
    • findAllIdents

      public static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol.VarSymbol> findAllIdents(VisitorState state)
      Finds the set of all bare variable identifiers in scope at the current location. Identifiers are ordered by ascending distance/scope count from the current location to match shadowing rules. That is, if two variables with the same simple names appear in the set, the one that appears first in iteration order is the one you get if you use the bare name in the source code.

      We do not report variables that would require a qualified access. We also do not handle wildcard imports.

    • findUnusedIdentifiers

      public static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol.VarSymbol> findUnusedIdentifiers(VisitorState state)
      Finds all variable declarations which are unused at this point in the AST (i.e. they might be used further on).
    • findReferencedIdentifiers

      public static com.google.common.collect.ImmutableSet<com.sun.tools.javac.code.Symbol> findReferencedIdentifiers(com.sun.source.tree.Tree tree)
      Find the set of all identifiers referenced within this Tree
    • findAllFields

      public static com.google.common.collect.ImmutableList<com.sun.tools.javac.code.Symbol.VarSymbol> findAllFields(com.sun.tools.javac.code.Type classType, VisitorState state)
      Finds all the visible fields declared or inherited in the target class