Package: org.codehaus.groovy.transform.stc

## [Java] Class TypeCheckingContext

- org.codehaus.groovy.transform.stc.TypeCheckingContext

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `TypeCheckingContext.EnclosingClosure` | Represents the context of an enclosing closure.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected Set<MethodNode>` | `alreadyVisitedMethods` |
    `protected IdentityHashMap<BlockStatement, Map<VariableExpression, List<ClassNode>>>` | `blockStatements2Types` | This field used for type derivation Check IfStatement matched pattern : Object var1; if (!
    `protected Map<VariableExpression, List<ClassNode>>` | `closureSharedVariablesAssignmentTypes` | A map used to store every type used in closure shared variable assignments.
    `protected CompilationUnit` | `compilationUnit` |
    `protected Map<Parameter, ClassNode>` | `controlStructureVariables` |
    `protected DelegationMetadata` | `delegationMetadata` |
    `protected LinkedList<BinaryExpression>` | `enclosingBinaryExpressions` |
    `protected LinkedList<BlockStatement>` | `enclosingBlocks` |
    `protected LinkedList<ClassNode>` | `enclosingClassNodes` |
    `protected LinkedList<EnclosingClosure>` | `enclosingClosures` |
    `protected LinkedList<Expression>` | `enclosingMethodCalls` |
    `protected LinkedList<MethodNode>` | `enclosingMethods` |
    `protected LinkedList<ErrorCollector>` | `errorCollectors` |
    `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` |
    `protected ClassNode` | `lastImplicitItType` | The type of the last encountered "it" implicit parameter
    `protected Set<MethodNode>` | `methodsToBeVisited` |
    `protected Set<Long>` | `reportedErrors` |
    `protected LinkedHashSet<SecondPassExpression>` | `secondPassExpressions` | Some expressions need to be visited twice, because type information may be insufficient at some point.
    `protected SourceUnit` | `source` |
    `protected LinkedList<SwitchStatement>` | `switchStatements` |
    `protected Stack<Map<Object, 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 and description
    `TypeCheckingContext (StaticTypeCheckingVisitor staticTypeCheckingVisitor)`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and 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.
    `` | `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.
    `` | `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.
    `` | `List<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.
    `` | `List<Expression>` | `getEnclosingMethodCalls()` Returns the current stack of enclosing method calls.
    `` | `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.
    `` | `List<SwitchStatement>` | `getEnclosingSwitchStatements()` Returns the current stack of enclosing switch statements.
    `` | `ErrorCollector` | `getErrorCollector()`
    `` | `List<ErrorCollector>` | `getErrorCollectors()`
    `` | `SourceUnit` | `getSource()`
    `` | `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.
    `` | `void` | `pushErrorCollector(ErrorCollector collector)`
    `` | `ErrorCollector` | `pushErrorCollector()`
    `` | `void` | `pushTemporaryTypeInfo()`
    `` | `void` | `setCompilationUnit(CompilationUnit compilationUnit)`

  - ### Inherited Methods Summary

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

- - ### Field Detail

    - #### protected Set<MethodNode> alreadyVisitedMethods

    - #### protected final IdentityHashMap<BlockStatement, Map<VariableExpression, List<ClassNode>>> blockStatements2Types

      This field used for type derivation Check IfStatement matched pattern : Object var1; if (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnable

    - #### protected final Map<VariableExpression, 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.

    - #### protected CompilationUnit compilationUnit

    - #### protected Map<Parameter, ClassNode> controlStructureVariables

    - #### protected DelegationMetadata delegationMetadata

    - #### protected final LinkedList<BinaryExpression> enclosingBinaryExpressions

    - #### protected final LinkedList<BlockStatement> enclosingBlocks

    - #### protected final LinkedList<ClassNode> enclosingClassNodes

    - #### protected final LinkedList<EnclosingClosure> enclosingClosures

    - #### protected final LinkedList<Expression> enclosingMethodCalls

    - #### protected final LinkedList<MethodNode> enclosingMethods

    - #### protected final LinkedList<ErrorCollector> errorCollectors

    - #### protected Map<VariableExpression, 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, String)

    - #### protected boolean isInStaticContext

    - #### protected ClassNode lastImplicitItType

      The type of the last encountered "it" implicit parameter

    - #### protected Set<MethodNode> methodsToBeVisited

    - #### protected final Set<Long> reportedErrors

    - #### protected final LinkedHashSet<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.

    - #### protected SourceUnit source

    - #### protected final LinkedList<SwitchStatement> switchStatements

    - #### protected Stack<Map<Object, 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

    - #### protected final StaticTypeCheckingVisitor visitor

  - ### Constructor Detail

    - #### public TypeCheckingContext(StaticTypeCheckingVisitor staticTypeCheckingVisitor)

  - ### Method Detail

    - #### public CompilationUnit getCompilationUnit()

    - #### public BinaryExpression getEnclosingBinaryExpression()

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

      Returns:
        the binary expression on top of the stack, or null if no such element.

    - #### public List<BinaryExpression> getEnclosingBinaryExpressionStack()

      Returns the current stack of enclosing binary expressions. The first element is the top of the stack.

      Returns:
        an immutable list of 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.

      Returns:
        the enclosing class on top of the stack, or null if no such element.

    - #### public 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.

      Returns:
        an immutable list of class nodes.

    - #### public TypeCheckingContext.EnclosingClosure getEnclosingClosure()

      Returns the closure expression which is on the top of the stack, or null if there's no such element.

      Returns:
        the closure expression on top of the stack, or null if no such element.

    - #### public List<EnclosingClosure> getEnclosingClosureStack()

      Returns the current stack of enclosing closure expressions. The first element is the top of the stack.

      Returns:
        an immutable list of 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.

      Returns:
        the enclosing method on top of the stack, or null if 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.

      Returns:
        the enclosing method call on top of the stack, or null if no such element.

    - #### public 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.

      Returns:
        an immutable list of enclosing method calls.

    - #### public 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.

      Returns:
        an immutable list of method nodes.

    - #### public SwitchStatement getEnclosingSwitchStatement()

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

      Returns:
        the enclosing switch statement on top of the stack, or null if no such element.

    - #### public 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.

      Returns:
        an immutable list of switch statements.

    - #### public ErrorCollector getErrorCollector()

    - #### public List<ErrorCollector> getErrorCollectors()

    - #### public SourceUnit getSource()

    - #### public BinaryExpression popEnclosingBinaryExpression()

      Pops a binary expression from the binary expression stack.

      Returns:
        the popped binary expression

    - #### public ClassNode popEnclosingClassNode()

      Pops a class from the enclosing classes stack.

      Returns:
        the popped class

    - #### public TypeCheckingContext.EnclosingClosure popEnclosingClosure()

      Pops a closure expression from the closure expression stack.

      Returns:
        the popped closure expression

    - #### public MethodNode popEnclosingMethod()

      Pops a method from the enclosing methods stack.

      Returns:
        the popped method

    - #### public Expression popEnclosingMethodCall()

      Pops a method call from the enclosing method call stack.

      Returns:
        the popped call

    - #### public SwitchStatement popEnclosingSwitchStatement()

      Pops a switch statement from the enclosing switch statements stack.

      Returns:
        the popped switch statement

    - #### public ErrorCollector popErrorCollector()

    - #### public void popTemporaryTypeInfo()

    - #### public void pushEnclosingBinaryExpression(BinaryExpression binaryExpression)

      Pushes a binary expression into the binary expression stack.

      Parameters:
        `binaryExpression` - the binary expression to be pushed

    - #### public void pushEnclosingClassNode(ClassNode classNode)

      Pushes a class into the classes stack.

      Parameters:
        `classNode` - the class to be pushed

    - #### public void pushEnclosingClosureExpression(ClosureExpression closureExpression)

      Pushes a closure expression into the closure expression stack.

      Parameters:
        `closureExpression` - the closure expression to be pushed

    - #### public void pushEnclosingMethod(MethodNode methodNode)

      Pushes a method into the method stack.

      Parameters:
        `methodNode` - the method to be pushed

    - #### 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

    - #### public void pushEnclosingSwitchStatement(SwitchStatement switchStatement)

      Pushes a switch statement into the switch statement stack.

      Parameters:
        `switchStatement` - the switch statement to be pushed

    - #### public void pushErrorCollector(ErrorCollector collector)

    - #### public ErrorCollector pushErrorCollector()

    - #### public void pushTemporaryTypeInfo()

    - #### public void setCompilationUnit(CompilationUnit compilationUnit)