Package org.codehaus.groovy.classgen

# Class VariableScopeVisitor.InstanceofFlowBindings

java.lang.Object
org.codehaus.groovy.classgen.VariableScopeVisitor.InstanceofFlowBindings

Enclosing class:
  VariableScopeVisitor

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 `VariableExpression`s 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(org.codehaus.groovy.ast.expr.Expression)`, declares from the variable lists, and attaches this instance as AST metadata (`put(org.codehaus.groovy.ast.ASTNode, org.codehaus.groovy.classgen.VariableScopeVisitor.InstanceofFlowBindings)`/`get(org.codehaus.groovy.ast.ASTNode)`). Later phases must use `get(org.codehaus.groovy.ast.ASTNode)` only — never re-call `of(org.codehaus.groovy.ast.expr.Expression)` 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).

Since:
  6.0.0
See Also:
  - `VariableScopeVisitor`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final VariableScopeVisitor.InstanceofFlowBindings`
  `EMPTY`
  Singleton for "no pattern variables on either path".
  `static final Object`
  `KEY`
  Metadata key for `NodeMetaDataHandler.putNodeMetaData(java.lang.Object, java.lang.Object)`/`getNodeMetaData`.

- ## Method Summary

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

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### KEY

    public static final Object KEY
    Metadata key for `NodeMetaDataHandler.putNodeMetaData(java.lang.Object, java.lang.Object)`/`getNodeMetaData`.

  - ### EMPTY

    public static final VariableScopeVisitor.InstanceofFlowBindings EMPTY
    Singleton for "no pattern variables on either path".

- ## Method Details

  - ### whenTrue

    public List<VariableExpression> whenTrue()
    Pattern variables definitely assigned when the condition is `true`. Used by `VariableScopeVisitor` to declare into scopes.

  - ### whenFalse

    public List<VariableExpression> whenFalse()
    Pattern variables definitely assigned when the condition is `false`. Used by `VariableScopeVisitor` to declare into scopes.

  - ### whenTrueNames

    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()`.

  - ### whenFalseNames

    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()`.

  - ### isEmpty

    public boolean isEmpty()
    Whether any pattern variable is bound on either path.

  - ### allNames

    public Set<String> allNames()
    All pattern-variable names in either path (stable encounter order).

  - ### put

    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`.

  - ### get

    public static VariableScopeVisitor.InstanceofFlowBindings get(ASTNode node)
    Returns the analysis result previously attached to `node`, or `EMPTY` if none (no path-live pattern variables).

  - ### of

    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`

  - ### containsPattern

    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(org.codehaus.groovy.ast.expr.Expression)`). Used by tests and diagnostics; classgen has its own structural check for expression-statement isolation.

  - ### allPatternNames

    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.