org.codehaus.groovy.transform.stc

## Class TypeCheckingContext

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

-     public class TypeCheckingContext
      extends Object

- - ### Nested Class Summary

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

  - ### Field Summary

    Fields
    Modifier and Type | Field and 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 (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnable
    `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 org.codehaus.groovy.transform.stc.DelegationMetadata` | `delegationMetadata`
    `protected LinkedList<BinaryExpression>` | `enclosingBinaryExpressions`
    `protected LinkedList<BlockStatement>` | `enclosingBlocks`
    `protected LinkedList<ClassNode>` | `enclosingClassNodes`
    `protected LinkedList<TypeCheckingContext.EnclosingClosure>` | `enclosingClosures`
    `protected LinkedList<ConstructorCallExpression>` | `enclosingConstructorCalls`
    `protected LinkedList<Expression>` | `enclosingMethodCalls`
    `protected LinkedList<MethodNode>` | `enclosingMethods`
    `protected LinkedList<PropertyExpression>` | `enclosingPropertyExpressions`
    `protected LinkedList<ReturnStatement>` | `enclosingReturnStatements`
    `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<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 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)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method 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<TypeCheckingContext.EnclosingClosure>` | `getEnclosingClosureStack()` Returns the current stack of enclosing closure expressions.
    `ConstructorCallExpression` | `getEnclosingConstructorCall()` Returns the constructor call which is on the top of the stack, or null if there's no such element.
    `List<ConstructorCallExpression>` | `getEnclosingConstructorCalls()` Returns the current stack of enclosing constructor calls.
    `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.
    `Expression` | `getEnclosingPropertyExpression()` Returns the property expression which is on the top of the stack, or null if there's no such element.
    `List<PropertyExpression>` | `getEnclosingPropertyExpressions()` Returns the current stack of property expressions.
    `ReturnStatement` | `getEnclosingReturnStatement()` Returns the return statement which is on the top of the stack, or null if there's no such element.
    `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.
    `ConstructorCallExpression` | `popEnclosingConstructorCall()` Pops a constructor call from the enclosing constructor call stack.
    `MethodNode` | `popEnclosingMethod()` Pops a method from the enclosing methods stack.
    `Expression` | `popEnclosingMethodCall()` Pops a method call from the enclosing method call stack.
    `Expression` | `popEnclosingPropertyExpression()` Pops a property expression from the property expression stack.
    `ReturnStatement` | `popEnclosingReturnStatement()` Pops a return statement from the enclosing return 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` | `pushEnclosingConstructorCall(ConstructorCallExpression call)` Pushes a constructor call into the constructor call 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` | `pushEnclosingPropertyExpression(PropertyExpression propertyExpression)` Pushes a property expression into the property expression stack.
    `void` | `pushEnclosingReturnStatement(ReturnStatement returnStatement)` Pushes a return statement into the return 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 Detail

    - #### source

          protected SourceUnit source

    - #### methodsToBeVisited

          protected Set<MethodNode> methodsToBeVisited

    - #### isInStaticContext

          protected boolean isInStaticContext

    - #### errorCollectors

          protected final LinkedList<ErrorCollector> errorCollectors

    - #### enclosingClassNodes

          protected final LinkedList<ClassNode> enclosingClassNodes

    - #### enclosingMethods

          protected final LinkedList<MethodNode> enclosingMethods

    - #### enclosingMethodCalls

          protected final LinkedList<Expression> enclosingMethodCalls

    - #### enclosingConstructorCalls

          protected final LinkedList<ConstructorCallExpression> enclosingConstructorCalls

    - #### enclosingBlocks

          protected final LinkedList<BlockStatement> enclosingBlocks

    - #### enclosingReturnStatements

          protected final LinkedList<ReturnStatement> enclosingReturnStatements

    - #### enclosingPropertyExpressions

          protected final LinkedList<PropertyExpression> enclosingPropertyExpressions

    - #### enclosingClosures

          protected final LinkedList<TypeCheckingContext.EnclosingClosure> enclosingClosures

    - #### delegationMetadata

          protected org.codehaus.groovy.transform.stc.DelegationMetadata delegationMetadata

    - #### lastImplicitItType

          protected ClassNode lastImplicitItType

      The type of the last encountered "it" implicit parameter

    - #### ifElseForWhileAssignmentTracker

          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)

    - #### blockStatements2Types

          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

    - #### temporaryIfBranchTypeInformation

          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

    - #### alreadyVisitedMethods

          protected Set<MethodNode> alreadyVisitedMethods

    - #### secondPassExpressions

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

    - #### controlStructureVariables

          protected Map<Parameter,ClassNode> controlStructureVariables

    - #### reportedErrors

          protected final Set<Long> reportedErrors

    - #### enclosingBinaryExpressions

          protected final LinkedList<BinaryExpression> enclosingBinaryExpressions

    - #### visitor

          protected final StaticTypeCheckingVisitor visitor

    - #### compilationUnit

          protected CompilationUnit compilationUnit

  - ### Constructor Detail

    - #### TypeCheckingContext

          public TypeCheckingContext(StaticTypeCheckingVisitor staticTypeCheckingVisitor)

  - ### Method Detail

    - #### pushEnclosingBinaryExpression

          public void pushEnclosingBinaryExpression(BinaryExpression binaryExpression)

      Pushes a binary expression into the binary expression stack.
      Parameters:
        `binaryExpression` - the binary expression to be pushed

    - #### popEnclosingBinaryExpression

          public BinaryExpression popEnclosingBinaryExpression()

      Pops a binary expression from the binary expression stack.
      Returns:
        the popped binary expression

    - #### getEnclosingBinaryExpression

          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.

    - #### getEnclosingBinaryExpressionStack

          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.

    - #### pushEnclosingClosureExpression

          public void pushEnclosingClosureExpression(ClosureExpression closureExpression)

      Pushes a closure expression into the closure expression stack.
      Parameters:
        `closureExpression` - the closure expression to be pushed

    - #### popEnclosingClosure

          public TypeCheckingContext.EnclosingClosure popEnclosingClosure()

      Pops a closure expression from the closure expression stack.
      Returns:
        the popped closure expression

    - #### 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.
      Returns:
        the closure expression on top of the stack, or null if no such element.

    - #### getEnclosingClosureStack

          public List<TypeCheckingContext.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.

    - #### pushEnclosingMethod

          public void pushEnclosingMethod(MethodNode methodNode)

      Pushes a method into the method stack.
      Parameters:
        `methodNode` - the method to be pushed

    - #### popEnclosingMethod

          public MethodNode popEnclosingMethod()

      Pops a method from the enclosing methods stack.
      Returns:
        the popped method

    - #### getEnclosingMethod

          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.

    - #### pushEnclosingReturnStatement

          public void pushEnclosingReturnStatement(ReturnStatement returnStatement)

      Pushes a return statement into the return statement stack.
      Parameters:
        `returnStatement` - the return statement to be pushed

    - #### popEnclosingReturnStatement

          public ReturnStatement popEnclosingReturnStatement()

      Pops a return statement from the enclosing return statements stack.
      Returns:
        the popped return statement

    - #### getEnclosingReturnStatement

          public ReturnStatement getEnclosingReturnStatement()

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

    - #### getEnclosingMethods

          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.

    - #### pushEnclosingClassNode

          public void pushEnclosingClassNode(ClassNode classNode)

      Pushes a class into the classes stack.
      Parameters:
        `classNode` - the class to be pushed

    - #### popEnclosingClassNode

          public ClassNode popEnclosingClassNode()

      Pops a class from the enclosing classes stack.
      Returns:
        the popped class

    - #### getEnclosingClassNode

          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.

    - #### getEnclosingClassNodes

          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.

    - #### pushTemporaryTypeInfo

          public void pushTemporaryTypeInfo()

    - #### popTemporaryTypeInfo

          public void popTemporaryTypeInfo()

    - #### pushEnclosingPropertyExpression

          public void pushEnclosingPropertyExpression(PropertyExpression propertyExpression)

      Pushes a property expression into the property expression stack.
      Parameters:
        `propertyExpression` - the property expression to be pushed

    - #### popEnclosingPropertyExpression

          public Expression popEnclosingPropertyExpression()

      Pops a property expression from the property expression stack.
      Returns:
        the popped property expression

    - #### getEnclosingPropertyExpression

          public Expression getEnclosingPropertyExpression()

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

    - #### getEnclosingPropertyExpressions

          public List<PropertyExpression> getEnclosingPropertyExpressions()

      Returns the current stack of property expressions. The first element is the top of the stack, that is to say the currently visited property expression.
      Returns:
        an immutable list of property expressions.

    - #### 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.
      Returns:
        the popped call

    - #### getEnclosingMethodCall

          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.

    - #### getEnclosingMethodCalls

          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.

    - #### pushEnclosingConstructorCall

          public void pushEnclosingConstructorCall(ConstructorCallExpression call)

      Pushes a constructor call into the constructor call stack.
      Parameters:
        `call` - the call expression to be pushed

    - #### popEnclosingConstructorCall

          public ConstructorCallExpression popEnclosingConstructorCall()

      Pops a constructor call from the enclosing constructor call stack.
      Returns:
        the popped call

    - #### getEnclosingConstructorCall

          public ConstructorCallExpression getEnclosingConstructorCall()

      Returns the constructor call which is on the top of the stack, or null if there's no such element.
      Returns:
        the enclosing constructor call on top of the stack, or null if no such element.

    - #### getEnclosingConstructorCalls

          public List<ConstructorCallExpression> getEnclosingConstructorCalls()

      Returns the current stack of enclosing constructor calls. The first element is the top of the stack, that is to say the currently visited constructor call.
      Returns:
        an immutable list of enclosing constructor calls.

    - #### getErrorCollectors

          public List<ErrorCollector> getErrorCollectors()

    - #### getErrorCollector

          public ErrorCollector getErrorCollector()

    - #### pushErrorCollector

          public void pushErrorCollector(ErrorCollector collector)

    - #### pushErrorCollector

          public ErrorCollector pushErrorCollector()

    - #### popErrorCollector

          public ErrorCollector popErrorCollector()

    - #### getCompilationUnit

          public CompilationUnit getCompilationUnit()

    - #### setCompilationUnit

          public void setCompilationUnit(CompilationUnit compilationUnit)

    - #### getSource

          public SourceUnit getSource()