Class UnusedLocalVariableCheck.VariableDesc

java.lang.Object
com.puppycrawl.tools.checkstyle.checks.coding.UnusedLocalVariableCheck.VariableDesc
Enclosing class:
UnusedLocalVariableCheck

private static final class UnusedLocalVariableCheck.VariableDesc extends Object
Maintains information about the variable.
Since:
9.3
  • Field Details

    • name

      private final String name
      The name of the variable.
    • typeAst

      private final DetailAST typeAst
      Ast of type TokenTypes.TYPE.
    • scope

      private final DetailAST scope
      The scope of variable is determined by the ast of type TokenTypes.SLIST or TokenTypes.LITERAL_FOR or TokenTypes.OBJBLOCK which is enclosing the variable.
    • instVarOrClassVar

      private boolean instVarOrClassVar
      Is an instance variable or a class variable.
    • namedPatternVar

      private boolean namedPatternVar
      Is a named pattern variable declared in a switch label.
    • used

      private boolean used
      Is the variable used.
  • Constructor Details

  • Method Details

    • getName

      String getName()
      Get the name of variable.
      Returns:
      name of variable
    • getTypeAst

      DetailAST getTypeAst()
      Get the associated ast node of type TokenTypes.TYPE.
      Returns:
      the associated ast node of type TokenTypes.TYPE
    • getScope

      DetailAST getScope()
      Get ast of type TokenTypes.SLIST or TokenTypes.LITERAL_FOR or TokenTypes.OBJBLOCK which is enclosing the variable i.e. its scope.
      Returns:
      the scope associated with the variable
    • registerAsUsed

      void registerAsUsed()
      Register the variable as used.
    • registerAsInstOrClassVar

      void registerAsInstOrClassVar()
      Register the variable as an instance variable or class variable.
    • registerAsNamedPatternVar

      void registerAsNamedPatternVar()
      Register the variable as a forced-name pattern variable declared in a switch label or instanceof record Destructuring.
    • isUsed

      boolean isUsed()
      Is the variable used or not.
      Returns:
      true if variable is used
    • isInstVarOrClassVar

      boolean isInstVarOrClassVar()
      Is an instance variable or a class variable.
      Returns:
      true if is an instance variable or a class variable
    • isNamedPatternVar

      boolean isNamedPatternVar()
      Is a forced-name pattern variable from a switch label or instanceof record Destructuring.
      Returns:
      true if this variable was declared in a context where pre-JDK 22 forces a name to be given even when unused