Class TypeCheckingContext
- java.lang.Object
- 
- org.codehaus.groovy.transform.stc.TypeCheckingContext
 
- 
 public class TypeCheckingContext extends java.lang.Object
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classTypeCheckingContext.EnclosingClosureRepresents the context of an enclosing closure.
 - 
Field SummaryFields Modifier and Type Field Description protected java.util.Set<MethodNode>alreadyVisitedMethodsprotected java.util.IdentityHashMap<BlockStatement,java.util.Map<VariableExpression,java.util.List<ClassNode>>>blockStatements2TypesThis field used for type derivation Check IfStatement matched pattern : Object var1; if (!(var1 instanceOf Runnable)){ return } // Here var1 instance of Runnableprotected java.util.Map<VariableExpression,java.util.List<ClassNode>>closureSharedVariablesAssignmentTypesA map used to store every type used in closure shared variable assignments.protected CompilationUnitcompilationUnitprotected java.util.Map<Parameter,ClassNode>controlStructureVariablesprotected org.codehaus.groovy.transform.stc.DelegationMetadatadelegationMetadataprotected java.util.LinkedList<BinaryExpression>enclosingBinaryExpressionsprotected java.util.LinkedList<BlockStatement>enclosingBlocksprotected java.util.LinkedList<ClassNode>enclosingClassNodesprotected java.util.LinkedList<TypeCheckingContext.EnclosingClosure>enclosingClosuresprotected java.util.LinkedList<ConstructorCallExpression>enclosingConstructorCallsprotected java.util.LinkedList<Expression>enclosingMethodCallsprotected java.util.LinkedList<MethodNode>enclosingMethodsprotected java.util.LinkedList<PropertyExpression>enclosingPropertyExpressionsprotected java.util.LinkedList<ReturnStatement>enclosingReturnStatementsprotected java.util.LinkedList<ErrorCollector>errorCollectorsprotected java.util.Map<VariableExpression,java.util.List<ClassNode>>ifElseForWhileAssignmentTrackerThis field is used to track assignments in if/else branches, for loops and while loops.protected booleanisInStaticContextprotected ClassNodelastImplicitItTypeThe type of the last encountered "it" implicit parameterprotected java.util.Set<MethodNode>methodsToBeVisitedprotected java.util.Set<java.lang.Long>reportedErrorsprotected java.util.LinkedHashSet<org.codehaus.groovy.transform.stc.SecondPassExpression>secondPassExpressionsSome expressions need to be visited twice, because type information may be insufficient at some point.protected SourceUnitsourceprotected java.util.Stack<java.util.Map<java.lang.Object,java.util.List<ClassNode>>>temporaryIfBranchTypeInformationStores information which is only valid in the "if" branch of an if-then-else statement.protected StaticTypeCheckingVisitorvisitor
 - 
Constructor SummaryConstructors Constructor Description TypeCheckingContext(StaticTypeCheckingVisitor staticTypeCheckingVisitor)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description CompilationUnitgetCompilationUnit()BinaryExpressiongetEnclosingBinaryExpression()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.ClassNodegetEnclosingClassNode()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.EnclosingClosuregetEnclosingClosure()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.ConstructorCallExpressiongetEnclosingConstructorCall()Returns the constructor call which is on the top of the stack, or null if there's no such element.java.util.List<ConstructorCallExpression>getEnclosingConstructorCalls()Returns the current stack of enclosing constructor calls.MethodNodegetEnclosingMethod()Returns the method node which is on the top of the stack, or null if there's no such element.ExpressiongetEnclosingMethodCall()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.ExpressiongetEnclosingPropertyExpression()Returns the property expression which is on the top of the stack, or null if there's no such element.java.util.List<PropertyExpression>getEnclosingPropertyExpressions()Returns the current stack of property expressions.ReturnStatementgetEnclosingReturnStatement()Returns the return statement which is on the top of the stack, or null if there's no such element.ErrorCollectorgetErrorCollector()java.util.List<ErrorCollector>getErrorCollectors()SourceUnitgetSource()BinaryExpressionpopEnclosingBinaryExpression()Pops a binary expression from the binary expression stack.ClassNodepopEnclosingClassNode()Pops a class from the enclosing classes stack.TypeCheckingContext.EnclosingClosurepopEnclosingClosure()Pops a closure expression from the closure expression stack.ConstructorCallExpressionpopEnclosingConstructorCall()Pops a constructor call from the enclosing constructor call stack.MethodNodepopEnclosingMethod()Pops a method from the enclosing methods stack.ExpressionpopEnclosingMethodCall()Pops a method call from the enclosing method call stack.ExpressionpopEnclosingPropertyExpression()Pops a property expression from the property expression stack.ReturnStatementpopEnclosingReturnStatement()Pops a return statement from the enclosing return statements stack.ErrorCollectorpopErrorCollector()voidpopTemporaryTypeInfo()voidpushEnclosingBinaryExpression(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.voidpushEnclosingConstructorCall(ConstructorCallExpression call)Pushes a constructor call into the constructor call stack.voidpushEnclosingMethod(MethodNode methodNode)Pushes a method into the method stack.voidpushEnclosingMethodCall(Expression call)Pushes 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.ErrorCollectorpushErrorCollector()voidpushErrorCollector(ErrorCollector collector)voidpushTemporaryTypeInfo()voidsetCompilationUnit(CompilationUnit compilationUnit)
 
- 
- 
- 
Field Detail- 
sourceprotected SourceUnit source 
 - 
methodsToBeVisitedprotected java.util.Set<MethodNode> methodsToBeVisited 
 - 
isInStaticContextprotected boolean isInStaticContext 
 - 
errorCollectorsprotected final java.util.LinkedList<ErrorCollector> errorCollectors 
 - 
enclosingClassNodesprotected final java.util.LinkedList<ClassNode> enclosingClassNodes 
 - 
enclosingMethodsprotected final java.util.LinkedList<MethodNode> enclosingMethods 
 - 
enclosingMethodCallsprotected final java.util.LinkedList<Expression> enclosingMethodCalls 
 - 
enclosingConstructorCallsprotected final java.util.LinkedList<ConstructorCallExpression> enclosingConstructorCalls 
 - 
enclosingBlocksprotected final java.util.LinkedList<BlockStatement> enclosingBlocks 
 - 
enclosingReturnStatementsprotected final java.util.LinkedList<ReturnStatement> enclosingReturnStatements 
 - 
enclosingPropertyExpressionsprotected final java.util.LinkedList<PropertyExpression> enclosingPropertyExpressions 
 - 
enclosingClosuresprotected final java.util.LinkedList<TypeCheckingContext.EnclosingClosure> enclosingClosures 
 - 
delegationMetadataprotected org.codehaus.groovy.transform.stc.DelegationMetadata delegationMetadata 
 - 
lastImplicitItTypeprotected ClassNode lastImplicitItType The type of the last encountered "it" implicit parameter
 - 
ifElseForWhileAssignmentTrackerprotected 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, String)
 - 
blockStatements2Typesprotected final java.util.IdentityHashMap<BlockStatement,java.util.Map<VariableExpression,java.util.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
 - 
temporaryIfBranchTypeInformationprotected 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
 - 
alreadyVisitedMethodsprotected java.util.Set<MethodNode> alreadyVisitedMethods 
 - 
secondPassExpressionsprotected 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.
 - 
closureSharedVariablesAssignmentTypesprotected 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.
 - 
reportedErrorsprotected final java.util.Set<java.lang.Long> reportedErrors 
 - 
enclosingBinaryExpressionsprotected final java.util.LinkedList<BinaryExpression> enclosingBinaryExpressions 
 - 
visitorprotected final StaticTypeCheckingVisitor visitor 
 - 
compilationUnitprotected CompilationUnit compilationUnit 
 
- 
 - 
Constructor Detail- 
TypeCheckingContextpublic TypeCheckingContext(StaticTypeCheckingVisitor staticTypeCheckingVisitor) 
 
- 
 - 
Method Detail- 
pushEnclosingBinaryExpressionpublic void pushEnclosingBinaryExpression(BinaryExpression binaryExpression) Pushes a binary expression into the binary expression stack.- Parameters:
- binaryExpression- the binary expression to be pushed
 
 - 
popEnclosingBinaryExpressionpublic BinaryExpression popEnclosingBinaryExpression() Pops a binary expression from the binary expression stack.- Returns:
- the popped binary expression
 
 - 
getEnclosingBinaryExpressionpublic 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.
 
 - 
getEnclosingBinaryExpressionStackpublic java.util.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.
 
 - 
pushEnclosingClosureExpressionpublic void pushEnclosingClosureExpression(ClosureExpression closureExpression) Pushes a closure expression into the closure expression stack.- Parameters:
- closureExpression- the closure expression to be pushed
 
 - 
popEnclosingClosurepublic TypeCheckingContext.EnclosingClosure popEnclosingClosure() Pops a closure expression from the closure expression stack.- Returns:
- the popped closure expression
 
 - 
getEnclosingClosurepublic 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.
 
 - 
getEnclosingClosureStackpublic java.util.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.
 
 - 
pushEnclosingMethodpublic void pushEnclosingMethod(MethodNode methodNode) Pushes a method into the method stack.- Parameters:
- methodNode- the method to be pushed
 
 - 
popEnclosingMethodpublic MethodNode popEnclosingMethod() Pops a method from the enclosing methods stack.- Returns:
- the popped method
 
 - 
getEnclosingMethodpublic 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.
 
 - 
pushEnclosingReturnStatementpublic void pushEnclosingReturnStatement(ReturnStatement returnStatement) Pushes a return statement into the return statement stack.- Parameters:
- returnStatement- the return statement to be pushed
 
 - 
popEnclosingReturnStatementpublic ReturnStatement popEnclosingReturnStatement() Pops a return statement from the enclosing return statements stack.- Returns:
- the popped return statement
 
 - 
getEnclosingReturnStatementpublic 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.
 
 - 
getEnclosingMethodspublic 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.- Returns:
- an immutable list of method nodes.
 
 - 
pushEnclosingClassNodepublic void pushEnclosingClassNode(ClassNode classNode) Pushes a class into the classes stack.- Parameters:
- classNode- the class to be pushed
 
 - 
popEnclosingClassNodepublic ClassNode popEnclosingClassNode() Pops a class from the enclosing classes stack.- Returns:
- the popped class
 
 - 
getEnclosingClassNodepublic 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.
 
 - 
getEnclosingClassNodespublic 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.- Returns:
- an immutable list of class nodes.
 
 - 
pushTemporaryTypeInfopublic void pushTemporaryTypeInfo() 
 - 
popTemporaryTypeInfopublic void popTemporaryTypeInfo() 
 - 
pushEnclosingPropertyExpressionpublic void pushEnclosingPropertyExpression(PropertyExpression propertyExpression) Pushes a property expression into the property expression stack.- Parameters:
- propertyExpression- the property expression to be pushed
 
 - 
popEnclosingPropertyExpressionpublic Expression popEnclosingPropertyExpression() Pops a property expression from the property expression stack.- Returns:
- the popped property expression
 
 - 
getEnclosingPropertyExpressionpublic 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.
 
 - 
getEnclosingPropertyExpressionspublic java.util.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.
 
 - 
pushEnclosingMethodCallpublic void pushEnclosingMethodCall(Expression call) Pushes a method call into the method call stack.- Parameters:
- call- the call expression to be pushed, either a- MethodCallExpressionor a- StaticMethodCallExpression
 
 - 
popEnclosingMethodCallpublic Expression popEnclosingMethodCall() Pops a method call from the enclosing method call stack.- Returns:
- the popped call
 
 - 
getEnclosingMethodCallpublic 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.
 
 - 
getEnclosingMethodCallspublic 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.- Returns:
- an immutable list of enclosing method calls.
 
 - 
pushEnclosingConstructorCallpublic void pushEnclosingConstructorCall(ConstructorCallExpression call) Pushes a constructor call into the constructor call stack.- Parameters:
- call- the call expression to be pushed
 
 - 
popEnclosingConstructorCallpublic ConstructorCallExpression popEnclosingConstructorCall() Pops a constructor call from the enclosing constructor call stack.- Returns:
- the popped call
 
 - 
getEnclosingConstructorCallpublic 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.
 
 - 
getEnclosingConstructorCallspublic java.util.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.
 
 - 
getErrorCollectorspublic java.util.List<ErrorCollector> getErrorCollectors() 
 - 
getErrorCollectorpublic ErrorCollector getErrorCollector() 
 - 
pushErrorCollectorpublic void pushErrorCollector(ErrorCollector collector) 
 - 
pushErrorCollectorpublic ErrorCollector pushErrorCollector() 
 - 
popErrorCollectorpublic ErrorCollector popErrorCollector() 
 - 
getCompilationUnitpublic CompilationUnit getCompilationUnit() 
 - 
setCompilationUnitpublic void setCompilationUnit(CompilationUnit compilationUnit) 
 - 
getSourcepublic SourceUnit getSource() 
 
- 
 
-