public class TypeCheckingContext
extends Object
Holds mutable state shared across a static type-checking visit.
| Modifiers | Name | Description |
|---|---|---|
static class |
TypeCheckingContext.EnclosingClosure |
Represents the context of an enclosing closure. |
| Modifiers | Name | Description |
|---|---|---|
protected Set<MethodNode> |
alreadyVisitedMethods |
Methods already visited during the current checking pass. |
protected Map<VariableExpression, List<ClassNode>> |
closureSharedVariablesAssignmentTypes |
A map used to store every type used in closure shared variable assignments. |
protected CompilationUnit |
compilationUnit |
Compilation unit associated with the current type-checking run. |
protected Map<Parameter, ClassNode> |
controlStructureVariables |
Types tracked for variables introduced by control structures. |
protected DelegationMetadata |
delegationMetadata |
Whenever a method using a closure as argument (typically, "with") is detected, this list is updated with the receiver type of the with method. |
protected LinkedList<BinaryExpression> |
enclosingBinaryExpressions |
Stack of enclosing binary expressions. |
protected LinkedList<ClassNode> |
enclosingClassNodes |
Stack of enclosing class nodes. |
protected LinkedList<EnclosingClosure> |
enclosingClosures |
Stack of enclosing closures. |
protected LinkedList<Expression> |
enclosingMethodCalls |
Stack of enclosing method-call expressions. |
protected LinkedList<MethodNode> |
enclosingMethods |
Stack of enclosing methods. |
protected LinkedList<ErrorCollector> |
errorCollectors |
Error collectors stacked for nested type-checking operations. |
protected Map<VariableExpression, List<ClassNode>> |
ifElseForWhileAssignmentTracker |
This field is used to track assignments in if/else branches, for loops and while loops. |
protected boolean |
isInStaticContext |
Indicates whether the current visit happens in a static context. |
protected ClassNode |
lastImplicitItType |
The type of the last encountered "it" implicit parameter. |
protected Set<MethodNode> |
methodsToBeVisited |
Optional filter restricting which methods should be visited. |
protected Set<Long> |
reportedErrors |
Source positions that already produced a type-checking error. |
protected LinkedHashSet<SecondPassExpression> |
secondPassExpressions |
Some expressions need to be visited twice, because type information may be insufficient at some point. |
protected SourceUnit |
source |
Source unit currently being type checked. |
protected LinkedList<SwitchStatement> |
switchStatements |
Stack of enclosing switch statements. |
protected Stack<Map<Object, List<ClassNode>>> |
temporaryIfBranchTypeInformation |
Stores information which is valid in the "then" branch of an if-then-else statement. |
protected StaticTypeCheckingVisitor |
visitor |
Visitor that owns this context. |
| Constructor and description |
|---|
TypeCheckingContext(StaticTypeCheckingVisitor visitor)Creates a context for the supplied type-checking visitor. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public CompilationUnit |
getCompilationUnit()Returns the compilation unit associated with this context. |
|
public BinaryExpression |
getEnclosingBinaryExpression()Returns the binary expression which is on the top of the stack, or null if there's no such element. |
|
public List<BinaryExpression> |
getEnclosingBinaryExpressionStack()Returns the current stack of enclosing binary expressions. |
|
public ClassNode |
getEnclosingClassNode()Returns the class node which is on the top of the stack, or null if there's no such element. |
|
public List<ClassNode> |
getEnclosingClassNodes()Returns the current stack of enclosing classes. |
|
public TypeCheckingContext.EnclosingClosure |
getEnclosingClosure()Returns the closure expression which is on the top of the stack, or null if there's no such element. |
|
public List<EnclosingClosure> |
getEnclosingClosureStack()Returns the current stack of enclosing closure expressions. |
|
public MethodNode |
getEnclosingMethod()Returns the method node which is on the top of the stack, or null if there's no such element. |
|
public Expression |
getEnclosingMethodCall()Returns the method call which is on the top of the stack, or null if there's no such element. |
|
public List<Expression> |
getEnclosingMethodCalls()Returns the current stack of enclosing method calls. |
|
public List<MethodNode> |
getEnclosingMethods()Returns the current stack of enclosing methods. |
|
public SwitchStatement |
getEnclosingSwitchStatement()Returns the switch statement which is on the top of the stack, or null if there's no such element. |
|
public List<SwitchStatement> |
getEnclosingSwitchStatements()Returns the current stack of enclosing switch statements. |
|
public ErrorCollector |
getErrorCollector()Returns the current error collector, or null if none is active. |
|
public List<ErrorCollector> |
getErrorCollectors()Returns the active error collector stack. |
|
public SourceUnit |
getSource()Returns the source unit currently being type checked. |
|
public boolean |
isTargetOfEnclosingAssignment(Expression expression)Indicates whether the expression is the left-hand side of the current assignment. |
|
public BinaryExpression |
popEnclosingBinaryExpression()Pops a binary expression from the binary expression stack. |
|
public ClassNode |
popEnclosingClassNode()Pops a class from the enclosing classes stack. |
|
public TypeCheckingContext.EnclosingClosure |
popEnclosingClosure()Pops a closure expression from the closure expression stack. |
|
public MethodNode |
popEnclosingMethod()Pops a method from the enclosing methods stack. |
|
public Expression |
popEnclosingMethodCall()Pops a method call from the enclosing method call stack. |
|
public SwitchStatement |
popEnclosingSwitchStatement()Pops a switch statement from the enclosing switch statements stack. |
|
public ErrorCollector |
popErrorCollector()Pops the current error collector. |
|
public void |
popTemporaryTypeInfo()Pops the current temporary type-information frame. |
|
public void |
pushEnclosingBinaryExpression(BinaryExpression binaryExpression)Pushes a binary expression into the binary expression stack. |
|
public void |
pushEnclosingClassNode(ClassNode classNode)Pushes a class into the classes stack. |
|
public void |
pushEnclosingClosureExpression(ClosureExpression closureExpression)Pushes a closure expression into the closure expression stack. |
|
public void |
pushEnclosingMethod(MethodNode methodNode)Pushes a method into the method stack. |
|
public void |
pushEnclosingMethodCall(Expression call)Pushes a method call into the method call stack. |
|
public void |
pushEnclosingSwitchStatement(SwitchStatement switchStatement)Pushes a switch statement into the switch statement stack. |
|
public ErrorCollector |
pushErrorCollector()Pushes a fresh error collector derived from the current compiler configuration. |
|
public void |
pushErrorCollector(ErrorCollector collector)Pushes the supplied error collector. |
|
public void |
pushTemporaryTypeInfo()Pushes a temporary type-information frame. |
|
public void |
setCompilationUnit(CompilationUnit compilationUnit)Sets the compilation unit associated with this context. |
Methods already visited during the current checking pass.
A map used to store every type used in closure shared variable assignments. In a second pass, we will compute the LUB of each type and check that method calls on those variables are valid.
Compilation unit associated with the current type-checking run.
Types tracked for variables introduced by control structures.
Whenever a method using a closure as argument (typically, "with") is detected, this list is updated with the receiver type of the with method.
Stack of enclosing binary expressions.
Stack of enclosing class nodes.
Stack of enclosing closures.
Stack of enclosing method-call expressions.
Stack of enclosing methods.
Error collectors stacked for nested type-checking operations.
This field is used to track assignments in if/else branches, for loops and
while loops. For example, in the following code: if (cond) { x = 1 } else { x = '123' }
the inferred type of x after the if/else statement should be the LUB of int and String.
Indicates whether the current visit happens in a static context.
The type of the last encountered "it" implicit parameter.
Optional filter restricting which methods should be visited.
Source positions that already produced a type-checking error.
Some expressions need to be visited twice, because type information may be insufficient at some point. For example, for closure shared variables, we need a first pass to collect every type which is assigned to a closure shared variable, then a second pass to ensure that every method call on such a variable is made on a LUB.
Source unit currently being type checked.
Stack of enclosing switch statements.
Stores information which is valid in the "then" branch of an if-then-else
statement. This is used when the if condition expression makes use of an
instanceof check.
Visitor that owns this context.
Creates a context for the supplied type-checking visitor.
Returns the compilation unit associated with this context.
Returns the binary expression which is on the top of the stack, or null if there's no such element.
Returns the current stack of enclosing binary expressions. The first element is the top of the stack.
Returns the class node which is on the top of the stack, or null if there's no such element.
Returns the current stack of enclosing classes. The first element is the top of the stack, that is to say the currently visited class.
Returns the closure expression which is on the top of the stack, or null if there's no such element.
Returns the current stack of enclosing closure expressions. The first element is the top of the stack.
Returns the method node which is on the top of the stack, or null if there's no such element.
Returns the method call which is on the top of the stack, or null if there's no such element.
Returns the current stack of enclosing method calls. The first element is the top of the stack, that is to say the currently visited method call.
Returns the current stack of enclosing methods. The first element is the top of the stack, that is to say the last visited method.
Returns the switch statement which is on the top of the stack, or null if there's no such element.
Returns the current stack of enclosing switch statements. The first element is the top of the stack, that is to say the last visited switch statement.
Returns the current error collector, or null if none is active.
Returns the active error collector stack.
Returns the source unit currently being type checked.
Indicates whether the expression is the left-hand side of the current assignment.
Pops a binary expression from the binary expression stack.
Pops a class from the enclosing classes stack.
Pops a closure expression from the closure expression stack.
Pops a method from the enclosing methods stack.
Pops a method call from the enclosing method call stack.
Pops a switch statement from the enclosing switch statements stack.
Pops the current error collector.
Pops the current temporary type-information frame.
Pushes a binary expression into the binary expression stack.
Pushes a class into the classes stack.
Pushes a closure expression into the closure expression stack.
Pushes a method into the method stack.
Pushes a method call into the method call stack.
call - the call expression to be pushed, either a MethodCallExpression or a StaticMethodCallExpressionPushes a switch statement into the switch statement stack.
Pushes a fresh error collector derived from the current compiler configuration.
Pushes the supplied error collector.
Pushes a temporary type-information frame.
Sets the compilation unit associated with this context.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.