Package org.codehaus.groovy.classgen
Class VariableScopeVisitor.InstanceofFlowBindings
java.lang.Object
org.codehaus.groovy.classgen.VariableScopeVisitor.InstanceofFlowBindings
- Enclosing class:
- VariableScopeVisitor
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()— patternVariableExpressions forVariableScopeVisitorto 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final VariableScopeVisitor.InstanceofFlowBindingsSingleton for "no pattern variables on either path".static final ObjectMetadata key forNodeMetaDataHandler.putNodeMetaData(java.lang.Object, java.lang.Object)/getNodeMetaData. -
Method Summary
Modifier and TypeMethodDescriptionallNames()All pattern-variable names in either path (stable encounter order).allPatternNames(Expression expression) Names of all pattern variables inexpression, regardless of definite-assignment path.static booleancontainsPattern(Expression expression) Returnstrueifexpressioncontains any JEP 394 type-pattern node at any depth.Returns the analysis result previously attached tonode, orEMPTYif none (no path-live pattern variables).booleanisEmpty()Whether any pattern variable is bound on either path.of(Expression expression) Analysesexpressionfor definiteinstanceofpattern bindings.static voidput(ASTNode node, VariableScopeVisitor.InstanceofFlowBindings bindings) Attaches this analysis result tonodefor later phases.Pattern variables definitely assigned when the condition isfalse.Names of pattern variables bound when the condition isfalse.whenTrue()Pattern variables definitely assigned when the condition istrue.Names of pattern variables bound when the condition istrue.
-
Field Details
-
KEY
Metadata key forNodeMetaDataHandler.putNodeMetaData(java.lang.Object, java.lang.Object)/getNodeMetaData. -
EMPTY
Singleton for "no pattern variables on either path".
-
-
Method Details
-
whenTrue
Pattern variables definitely assigned when the condition istrue. Used byVariableScopeVisitorto declare into scopes. -
whenFalse
Pattern variables definitely assigned when the condition isfalse. Used byVariableScopeVisitorto declare into scopes. -
whenTrueNames
Names of pattern variables bound when the condition istrue. Used by classgen for CompileStack path-hide; same set aswhenTrue(). -
whenFalseNames
Names of pattern variables bound when the condition isfalse. Used by classgen for CompileStack path-hide; same set aswhenFalse(). -
isEmpty
public boolean isEmpty()Whether any pattern variable is bound on either path. -
allNames
All pattern-variable names in either path (stable encounter order). -
put
-
get
Returns the analysis result previously attached tonode, orEMPTYif none (no path-live pattern variables). -
of
Analysesexpressionfor definiteinstanceofpattern bindings. Call only fromVariableScopeVisitor(or tests); classgen must useget(ASTNode).- Parameters:
expression- a boolean condition (may be aBooleanExpressionwrapper);nullyieldsEMPTY- Returns:
- the true/false binding sets; never
null
-
containsPattern
Returnstrueifexpressioncontains any JEP 394 type-pattern node at any depth. Full subtree walk (unlikeof(org.codehaus.groovy.ast.expr.Expression)). Used by tests and diagnostics; classgen has its own structural check for expression-statement isolation. -
allPatternNames
Names of all pattern variables inexpression, regardless of definite-assignment path. Full tree walk; for tests/diagnostics. Classgen tracks allocated slots via CompileStack instead.
-