Class FindIdentifiers
java.lang.Object
com.google.errorprone.util.FindIdentifiers
A helper class to find all identifiers in scope at a given program point.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 classstatic 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.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.static @Nullable 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 Treestatic 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.
-
Method Details
-
findIdent
Finds a variable declaration with the given name that is in scope at the current location. -
findIdent
public static @Nullable 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
-