Class TypeCheckingContext
java.lang.Object
org.codehaus.groovy.transform.stc.TypeCheckingContext
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents the context of an enclosing closure. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Set<MethodNode> protected final IdentityHashMap<BlockStatement, Map<VariableExpression, List<ClassNode>>> This field used for type derivation Check IfStatement matched pattern : Object var1; if (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnableprotected final Map<VariableExpression, List<ClassNode>> A map used to store every type used in closure shared variable assignments.protected CompilationUnitprotected org.codehaus.groovy.transform.stc.DelegationMetadataprotected final LinkedList<BinaryExpression> protected final LinkedList<BlockStatement> protected final LinkedList<ClassNode> protected final LinkedList<TypeCheckingContext.EnclosingClosure> protected final LinkedList<ConstructorCallExpression> protected final LinkedList<Expression> protected final LinkedList<MethodNode> protected final LinkedList<PropertyExpression> protected final LinkedList<ReturnStatement> protected final LinkedList<ErrorCollector> protected Map<VariableExpression, List<ClassNode>> This field is used to track assignments in if/else branches, for loops and while loops.protected booleanprotected ClassNodeThe type of the last encountered "it" implicit parameterprotected Set<MethodNode> protected final LinkedHashSet<org.codehaus.groovy.transform.stc.SecondPassExpression> Some expressions need to be visited twice, because type information may be insufficient at some point.protected SourceUnitStores information which is only valid in the "if" branch of an if-then-else statement.protected final StaticTypeCheckingVisitor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns 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.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.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.Returns the constructor call which is on the top of the stack, or null if there's no such element.Returns the current stack of enclosing constructor calls.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.Returns the current stack of enclosing methods.Returns the property expression which is on the top of the stack, or null if there's no such element.Returns the current stack of property expressions.Returns the return statement which is on the top of the stack, or null if there's no such element.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 constructor call from the enclosing constructor call stack.Pops a method from the enclosing methods stack.Pops a method call from the enclosing method call stack.Pops a property expression from the property expression stack.Pops a return statement from the enclosing return statements stack.voidvoidpushEnclosingBinaryExpression(BinaryExpression binaryExpression) Pushes a binary expression into the binary expression stack.voidpushEnclosingClassNode(ClassNode classNode) Pushes a class into the classes stack.voidpushEnclosingClosureExpression(ClosureExpression closureExpression) Pushes a closure expression into the closure expression stack.voidPushes a constructor call into the constructor call stack.voidpushEnclosingMethod(MethodNode methodNode) Pushes a method into the method stack.voidPushes a method call into the method call stack.voidpushEnclosingPropertyExpression(PropertyExpression propertyExpression) Pushes a property expression into the property expression stack.voidpushEnclosingReturnStatement(ReturnStatement returnStatement) Pushes a return statement into the return statement stack.voidpushErrorCollector(ErrorCollector collector) voidvoidsetCompilationUnit(CompilationUnit compilationUnit)
-
Field Details
-
source
-
methodsToBeVisited
-
isInStaticContext
protected boolean isInStaticContext -
errorCollectors
-
enclosingClassNodes
-
enclosingMethods
-
enclosingMethodCalls
-
enclosingConstructorCalls
-
enclosingBlocks
-
enclosingReturnStatements
-
enclosingPropertyExpressions
-
enclosingClosures
-
delegationMetadata
protected org.codehaus.groovy.transform.stc.DelegationMetadata delegationMetadata -
lastImplicitItType
The type of the last encountered "it" implicit parameter -
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>>> blockStatements2TypesThis field used for type derivation Check IfStatement matched pattern : Object var1; if (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnable -
temporaryIfBranchTypeInformation
-
alreadyVisitedMethods
-
secondPassExpressions
protected final LinkedHashSet<org.codehaus.groovy.transform.stc.SecondPassExpression> secondPassExpressionsSome 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. -
controlStructureVariables
-
reportedErrors
-
enclosingBinaryExpressions
-
visitor
-
compilationUnit
-
-
Constructor Details
-
TypeCheckingContext
-
-
Method Details
-
pushEnclosingBinaryExpression
Pushes a binary expression into the binary expression stack.- Parameters:
binaryExpression- the binary expression to be pushed
-
popEnclosingBinaryExpression
Pops a binary expression from the binary expression stack.- Returns:
- the popped binary expression
-
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
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
Pushes a closure expression into the closure expression stack.- Parameters:
closureExpression- the closure expression to be pushed
-
popEnclosingClosure
Pops a closure expression from the closure expression stack.- Returns:
- the popped closure expression
-
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
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
Pushes a method into the method stack.- Parameters:
methodNode- the method to be pushed
-
popEnclosingMethod
Pops a method from the enclosing methods stack.- Returns:
- the popped method
-
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
Pushes a return statement into the return statement stack.- Parameters:
returnStatement- the return statement to be pushed
-
popEnclosingReturnStatement
Pops a return statement from the enclosing return statements stack.- Returns:
- the popped return statement
-
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
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
Pushes a class into the classes stack.- Parameters:
classNode- the class to be pushed
-
popEnclosingClassNode
Pops a class from the enclosing classes stack.- Returns:
- the popped class
-
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
-
pushTemporaryTypeInfo
public void pushTemporaryTypeInfo() -
popTemporaryTypeInfo
public void popTemporaryTypeInfo() -
pushEnclosingPropertyExpression
Pushes a property expression into the property expression stack.- Parameters:
propertyExpression- the property expression to be pushed
-
popEnclosingPropertyExpression
Pops a property expression from the property expression stack.- Returns:
- the popped property 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
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
Pushes a method call into the method call stack.- Parameters:
call- the call expression to be pushed, either aMethodCallExpressionor aStaticMethodCallExpression
-
popEnclosingMethodCall
Pops a method call from the enclosing method call stack.- Returns:
- the popped call
-
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
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
Pushes a constructor call into the constructor call stack.- Parameters:
call- the call expression to be pushed
-
popEnclosingConstructorCall
Pops a constructor call from the enclosing constructor call stack.- Returns:
- the popped call
-
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
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
-
getErrorCollector
-
pushErrorCollector
-
pushErrorCollector
-
popErrorCollector
-
getCompilationUnit
-
setCompilationUnit
-
getSource
-