Package org.codehaus.groovy.transform.stc

# Class TypeCheckingContext

java.lang.Object
org.codehaus.groovy.transform.stc.TypeCheckingContext

    public class TypeCheckingContext
    extends java.lang.Object

- ## Nested Class Summary

  Nested Classes
  Modifier and Type | Class | Description
  --- | --- | ---
  `static class` | `TypeCheckingContext.EnclosingClosure` | Represents the context of an enclosing closure.

- ## Field Summary

  Fields
  Modifier and Type | Field | Description
  --- | --- | ---
  `protected java.util.Set<MethodNode>` | `alreadyVisitedMethods` |
  `protected java.util.IdentityHashMap<BlockStatement,​java.util.Map<VariableExpression,​java.util.List<ClassNode>>>` | `blockStatements2Types` | Deprecated.
  `protected java.util.Map<VariableExpression,​java.util.List<ClassNode>>` | `closureSharedVariablesAssignmentTypes` | A map used to store every type used in closure shared variable assignments.
  `protected CompilationUnit` | `compilationUnit` |
  `protected java.util.Map<Parameter,​ClassNode>` | `controlStructureVariables` |
  `protected org.codehaus.groovy.transform.stc.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 java.util.LinkedList<BinaryExpression>` | `enclosingBinaryExpressions` |
  `protected java.util.LinkedList<BlockStatement>` | `enclosingBlocks` | Deprecated.
  `protected java.util.LinkedList<ClassNode>` | `enclosingClassNodes` |
  `protected java.util.LinkedList<TypeCheckingContext.EnclosingClosure>` | `enclosingClosures` |
  `protected java.util.LinkedList<Expression>` | `enclosingMethodCalls` |
  `protected java.util.LinkedList<MethodNode>` | `enclosingMethods` |
  `protected java.util.LinkedList<ErrorCollector>` | `errorCollectors` |
  `protected java.util.Map<VariableExpression,​java.util.List<ClassNode>>` | `ifElseForWhileAssignmentTracker` | This field is used to track assignments in if/else branches, for loops and while loops.
  `protected boolean` | `isInStaticContext` |
  `protected ClassNode` | `lastImplicitItType` | The type of the last encountered "it" implicit parameter.
  `protected java.util.Set<MethodNode>` | `methodsToBeVisited` |
  `protected java.util.Set<java.lang.Long>` | `reportedErrors` |
  `protected java.util.LinkedHashSet<org.codehaus.groovy.transform.stc.SecondPassExpression>` | `secondPassExpressions` | Some expressions need to be visited twice, because type information may be insufficient at some point.
  `protected SourceUnit` | `source` |
  `protected java.util.LinkedList<SwitchStatement>` | `switchStatements` |
  `protected java.util.Stack<java.util.Map<java.lang.Object,​java.util.List<ClassNode>>>` | `temporaryIfBranchTypeInformation` | Stores information which is only valid in the "if" branch of an if-then-else statement.
  `protected StaticTypeCheckingVisitor` | `visitor` |

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `TypeCheckingContext​(StaticTypeCheckingVisitor visitor)` |

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `CompilationUnit` | `getCompilationUnit()` |
  `BinaryExpression` | `getEnclosingBinaryExpression()` | Returns the binary expression which is on the top of the stack, or null if there's no such element.
  `java.util.List<BinaryExpression>` | `getEnclosingBinaryExpressionStack()` | Returns the current stack of enclosing binary expressions.
  `ClassNode` | `getEnclosingClassNode()` | Returns the class node which is on the top of the stack, or null if there's no such element.
  `java.util.List<ClassNode>` | `getEnclosingClassNodes()` | Returns the current stack of enclosing classes.
  `TypeCheckingContext.EnclosingClosure` | `getEnclosingClosure()` | Returns the closure expression which is on the top of the stack, or null if there's no such element.
  `java.util.List<TypeCheckingContext.EnclosingClosure>` | `getEnclosingClosureStack()` | Returns the current stack of enclosing closure expressions.
  `MethodNode` | `getEnclosingMethod()` | Returns the method node which is on the top of the stack, or null if there's no such element.
  `Expression` | `getEnclosingMethodCall()` | Returns the method call which is on the top of the stack, or null if there's no such element.
  `java.util.List<Expression>` | `getEnclosingMethodCalls()` | Returns the current stack of enclosing method calls.
  `java.util.List<MethodNode>` | `getEnclosingMethods()` | Returns the current stack of enclosing methods.
  `SwitchStatement` | `getEnclosingSwitchStatement()` | Returns the switch statement which is on the top of the stack, or null if there's no such element.
  `java.util.List<SwitchStatement>` | `getEnclosingSwitchStatements()` | Returns the current stack of enclosing switch statements.
  `ErrorCollector` | `getErrorCollector()` |
  `java.util.List<ErrorCollector>` | `getErrorCollectors()` |
  `SourceUnit` | `getSource()` |
  `boolean` | `isTargetOfEnclosingAssignment​(Expression expression)` |
  `BinaryExpression` | `popEnclosingBinaryExpression()` | Pops a binary expression from the binary expression stack.
  `ClassNode` | `popEnclosingClassNode()` | Pops a class from the enclosing classes stack.
  `TypeCheckingContext.EnclosingClosure` | `popEnclosingClosure()` | Pops a closure expression from the closure expression stack.
  `MethodNode` | `popEnclosingMethod()` | Pops a method from the enclosing methods stack.
  `Expression` | `popEnclosingMethodCall()` | Pops a method call from the enclosing method call stack.
  `SwitchStatement` | `popEnclosingSwitchStatement()` | Pops a switch statement from the enclosing switch statements stack.
  `ErrorCollector` | `popErrorCollector()` |
  `void` | `popTemporaryTypeInfo()` |
  `void` | `pushEnclosingBinaryExpression​(BinaryExpression binaryExpression)` | Pushes a binary expression into the binary expression stack.
  `void` | `pushEnclosingClassNode​(ClassNode classNode)` | Pushes a class into the classes stack.
  `void` | `pushEnclosingClosureExpression​(ClosureExpression closureExpression)` | Pushes a closure expression into the closure expression stack.
  `void` | `pushEnclosingMethod​(MethodNode methodNode)` | Pushes a method into the method stack.
  `void` | `pushEnclosingMethodCall​(Expression call)` | Pushes a method call into the method call stack.
  `void` | `pushEnclosingSwitchStatement​(SwitchStatement switchStatement)` | Pushes a switch statement into the switch statement stack.
  `ErrorCollector` | `pushErrorCollector()` |
  `void` | `pushErrorCollector​(ErrorCollector collector)` |
  `void` | `pushTemporaryTypeInfo()` |
  `void` | `setCompilationUnit​(CompilationUnit compilationUnit)` |

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

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

- ## Field Details

  - ### visitor

    protected final StaticTypeCheckingVisitor visitor

  - ### source

    protected SourceUnit source

  - ### compilationUnit

    protected CompilationUnit compilationUnit

  - ### errorCollectors

    protected final java.util.LinkedList<ErrorCollector> errorCollectors

  - ### temporaryIfBranchTypeInformation

    protected java.util.Stack<java.util.Map<java.lang.Object,​java.util.List<ClassNode>>> temporaryIfBranchTypeInformation
    Stores information which is only valid in the "if" branch of an if-then-else statement. This is used when the if condition expression makes use of an instanceof check

  - ### delegationMetadata

    protected org.codehaus.groovy.transform.stc.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.

  - ### isInStaticContext

    protected boolean isInStaticContext

  - ### lastImplicitItType

    protected ClassNode lastImplicitItType
    The type of the last encountered "it" implicit parameter.

  - ### methodsToBeVisited

    protected java.util.Set<MethodNode> methodsToBeVisited

  - ### ifElseForWhileAssignmentTracker

    protected java.util.Map<VariableExpression,​java.util.List<ClassNode>> ifElseForWhileAssignmentTracker
    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.

  - ### blockStatements2Types

    @Deprecated protected final java.util.IdentityHashMap<BlockStatement,​java.util.Map<VariableExpression,​java.util.List<ClassNode>>> blockStatements2Types
    Deprecated.
    This field used for type derivation Check IfStatement matched pattern: Object var1; if (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnable

  - ### alreadyVisitedMethods

    protected java.util.Set<MethodNode> alreadyVisitedMethods

  - ### secondPassExpressions

    protected final java.util.LinkedHashSet<org.codehaus.groovy.transform.stc.SecondPassExpression> secondPassExpressions
    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.

  - ### closureSharedVariablesAssignmentTypes

    protected final java.util.Map<VariableExpression,​java.util.List<ClassNode>> closureSharedVariablesAssignmentTypes
    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.

  - ### controlStructureVariables

    protected java.util.Map<Parameter,​ClassNode> controlStructureVariables

  - ### reportedErrors

    protected final java.util.Set<java.lang.Long> reportedErrors

  - ### enclosingClassNodes

    protected final java.util.LinkedList<ClassNode> enclosingClassNodes

  - ### enclosingMethods

    protected final java.util.LinkedList<MethodNode> enclosingMethods

  - ### enclosingMethodCalls

    protected final java.util.LinkedList<Expression> enclosingMethodCalls

  - ### enclosingBlocks

    @Deprecated protected final java.util.LinkedList<BlockStatement> enclosingBlocks
    Deprecated.

  - ### switchStatements

    protected final java.util.LinkedList<SwitchStatement> switchStatements

  - ### enclosingClosures

    protected final java.util.LinkedList<TypeCheckingContext.EnclosingClosure> enclosingClosures

  - ### enclosingBinaryExpressions

    protected final java.util.LinkedList<BinaryExpression> enclosingBinaryExpressions

- ## Constructor Details

  - ### TypeCheckingContext

    public TypeCheckingContext​(StaticTypeCheckingVisitor visitor)

- ## Method Details

  - ### getSource

    public SourceUnit getSource()

  - ### getCompilationUnit

    public CompilationUnit getCompilationUnit()

  - ### setCompilationUnit

    public void setCompilationUnit​(CompilationUnit compilationUnit)

  - ### pushErrorCollector

    public ErrorCollector pushErrorCollector()

  - ### pushErrorCollector

    public void pushErrorCollector​(ErrorCollector collector)

  - ### popErrorCollector

    public ErrorCollector popErrorCollector()

  - ### getErrorCollector

    public ErrorCollector getErrorCollector()

  - ### getErrorCollectors

    public java.util.List<ErrorCollector> getErrorCollectors()

  - ### pushTemporaryTypeInfo

    public void pushTemporaryTypeInfo()

  - ### popTemporaryTypeInfo

    public void popTemporaryTypeInfo()

  - ### pushEnclosingBinaryExpression

    public void pushEnclosingBinaryExpression​(BinaryExpression binaryExpression)
    Pushes a binary expression into the binary expression stack.

  - ### popEnclosingBinaryExpression

    public BinaryExpression popEnclosingBinaryExpression()
    Pops a binary expression from the binary expression stack.

  - ### getEnclosingBinaryExpression

    public BinaryExpression getEnclosingBinaryExpression()
    Returns the binary expression which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingBinaryExpressionStack

    public java.util.List<BinaryExpression> getEnclosingBinaryExpressionStack()
    Returns the current stack of enclosing binary expressions. The first element is the top of the stack.

  - ### isTargetOfEnclosingAssignment

    public boolean isTargetOfEnclosingAssignment​(Expression expression)

  - ### pushEnclosingClosureExpression

    public void pushEnclosingClosureExpression​(ClosureExpression closureExpression)
    Pushes a closure expression into the closure expression stack.

  - ### popEnclosingClosure

    public TypeCheckingContext.EnclosingClosure popEnclosingClosure()
    Pops a closure expression from the closure expression stack.

  - ### getEnclosingClosure

    public TypeCheckingContext.EnclosingClosure getEnclosingClosure()
    Returns the closure expression which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingClosureStack

    public java.util.List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack()
    Returns the current stack of enclosing closure expressions. The first element is the top of the stack.

  - ### pushEnclosingClassNode

    public void pushEnclosingClassNode​(ClassNode classNode)
    Pushes a class into the classes stack.

  - ### popEnclosingClassNode

    public ClassNode popEnclosingClassNode()
    Pops a class from the enclosing classes stack.

  - ### getEnclosingClassNode

    public ClassNode getEnclosingClassNode()
    Returns the class node which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingClassNodes

    public java.util.List<ClassNode> getEnclosingClassNodes()
    Returns the current stack of enclosing classes. The first element is the top of the stack, that is to say the currently visited class.

  - ### pushEnclosingMethod

    public void pushEnclosingMethod​(MethodNode methodNode)
    Pushes a method into the method stack.

  - ### popEnclosingMethod

    public MethodNode popEnclosingMethod()
    Pops a method from the enclosing methods stack.

  - ### getEnclosingMethod

    public MethodNode getEnclosingMethod()
    Returns the method node which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingMethods

    public java.util.List<MethodNode> getEnclosingMethods()
    Returns the current stack of enclosing methods. The first element is the top of the stack, that is to say the last visited method.

  - ### pushEnclosingMethodCall

    public void pushEnclosingMethodCall​(Expression call)
    Pushes a method call into the method call stack.
    Parameters:
      `call` - the call expression to be pushed, either a `MethodCallExpression` or a `StaticMethodCallExpression`

  - ### popEnclosingMethodCall

    public Expression popEnclosingMethodCall()
    Pops a method call from the enclosing method call stack.

  - ### getEnclosingMethodCall

    public Expression getEnclosingMethodCall()
    Returns the method call which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingMethodCalls

    public java.util.List<Expression> getEnclosingMethodCalls()
    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.

  - ### pushEnclosingSwitchStatement

    public void pushEnclosingSwitchStatement​(SwitchStatement switchStatement)
    Pushes a switch statement into the switch statement stack.

  - ### popEnclosingSwitchStatement

    public SwitchStatement popEnclosingSwitchStatement()
    Pops a switch statement from the enclosing switch statements stack.

  - ### getEnclosingSwitchStatement

    public SwitchStatement getEnclosingSwitchStatement()
    Returns the switch statement which is on the top of the stack, or null if there's no such element.

  - ### getEnclosingSwitchStatements

    public java.util.List<SwitchStatement> getEnclosingSwitchStatements()
    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.