Package: org.codehaus.groovy.classgen

## [Java] Class VariableScopeVisitor.InstanceofFlowBindings

- org.codehaus.groovy.classgen.VariableScopeVisitor.InstanceofFlowBindings

-     public static final class VariableScopeVisitor.InstanceofFlowBindings
      extends Object

  Flow-sensitive result for JEP 394 `instanceof` pattern bindings (GROOVY-12242) — the Groovy equivalent of the JLS §6.3.1 “introduced by” sets.

  One type, two views of the same analysis:

  - whenTrue()/whenFalse() — pattern VariableExpressions for VariableScopeVisitor to declare into lexical scopes;
  - whenTrueNames()/whenFalseNames() — the same sets as names for classgen to path-hide CompileStack slots.
  VariableScopeVisitor runs the analysis once via of, declares from the variable lists, and attaches this instance as AST metadata (put/get). Later phases must use get only — never re-call of on the condition.

  Covered shapes: `e instanceof T t`, `e !instanceof T t` (native form and `!(e instanceof T t)`), `!expr`, `a && b`, `a || b`. All other shapes yield EMPTY (conservative: no definite bindings).

  See Also:
    VariableScopeVisitor
  Since:
    6.0.0

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static VariableScopeVisitor.InstanceofFlowBindings` | `EMPTY` | Singleton for "no pattern variables on either path".
    `static Object` | `KEY` | Metadata key for ASTNode.putNodeMetaData/`getNodeMetaData`.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public Set<String>` | `allNames()` All pattern-variable names in either path (stable encounter order).
    `` | `public static Set<String>` | `allPatternNames(Expression expression)` Names of all pattern variables in `expression`, regardless of definite-assignment path.
    `` | `public static boolean` | `containsPattern(Expression expression)` Returns `true` if `expression` contains any JEP 394 type-pattern node at any depth.
    `` | `public static VariableScopeVisitor.InstanceofFlowBindings` | `get(ASTNode node)` Returns the analysis result previously attached to `node`, or EMPTY if none (no path-live pattern variables).
    `` | `public boolean` | `isEmpty()` Whether any pattern variable is bound on either path.
    `` | `public static VariableScopeVisitor.InstanceofFlowBindings` | `of(Expression expression)` Analyses `expression` for definite `instanceof` pattern bindings.
    `` | `public static void` | `put(ASTNode node, VariableScopeVisitor.InstanceofFlowBindings bindings)` Attaches this analysis result to `node` for later phases.
    `` | `public List<VariableExpression>` | `whenFalse()` Pattern variables definitely assigned when the condition is `false`.
    `` | `public Set<String>` | `whenFalseNames()` Names of pattern variables bound when the condition is `false`.
    `` | `public List<VariableExpression>` | `whenTrue()` Pattern variables definitely assigned when the condition is `true`.
    `` | `public Set<String>` | `whenTrueNames()` Names of pattern variables bound when the condition is `true`.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final VariableScopeVisitor.InstanceofFlowBindings EMPTY

      Singleton for "no pattern variables on either path".

    - #### public static final Object KEY

      Metadata key for ASTNode.putNodeMetaData/`getNodeMetaData`.

  - ### Method Detail

    - #### public Set<String> allNames()

      All pattern-variable names in either path (stable encounter order).

    - #### public static Set<String> allPatternNames(Expression expression)

      Names of all pattern variables in `expression`, regardless of definite-assignment path. Full tree walk; for tests/diagnostics. Classgen tracks allocated slots via CompileStack instead.

    - #### public static boolean containsPattern(Expression expression)

      Returns `true` if `expression` contains any JEP 394 type-pattern node at any depth. Full subtree walk (unlike of). Used by tests and diagnostics; classgen has its own structural check for expression-statement isolation.

    - #### public static VariableScopeVisitor.InstanceofFlowBindings get(ASTNode node)

      Returns the analysis result previously attached to `node`, or EMPTY if none (no path-live pattern variables).

    - #### public boolean isEmpty()

      Whether any pattern variable is bound on either path.

    - #### public static VariableScopeVisitor.InstanceofFlowBindings of(Expression expression)

      Analyses `expression` for definite `instanceof` pattern bindings. Call only from VariableScopeVisitor (or tests); classgen must use get(ASTNode).

      Parameters:
        `expression` - a boolean condition (may be a BooleanExpression wrapper); `null` yields EMPTY
      Returns:
        the true/false binding sets; never `null`

    - #### public static void put(ASTNode node, VariableScopeVisitor.InstanceofFlowBindings bindings)

      Attaches this analysis result to `node` for later phases. No-op when `bindings` is null or EMPTY.

    - #### public List<VariableExpression> whenFalse()

      Pattern variables definitely assigned when the condition is `false`. Used by VariableScopeVisitor to declare into scopes.

    - #### public Set<String> whenFalseNames()

      Names of pattern variables bound when the condition is `false`. Used by classgen for CompileStack path-hide; same set as whenFalse().

    - #### public List<VariableExpression> whenTrue()

      Pattern variables definitely assigned when the condition is `true`. Used by VariableScopeVisitor to declare into scopes.

    - #### public Set<String> whenTrueNames()

      Names of pattern variables bound when the condition is `true`. Used by classgen for CompileStack path-hide; same set as whenTrue().