Class TypeCheckingContext
- java.lang.Object
- 
- org.codehaus.groovy.transform.stc.TypeCheckingContext
 
- 
 public class TypeCheckingContext extends 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 Set<MethodNode>alreadyVisitedMethodsprotected 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 Runnableprotected Map<VariableExpression,List<ClassNode>>closureSharedVariablesAssignmentTypesA map used to store every type used in closure shared variable assignments.protected CompilationUnitcompilationUnitprotected Map<Parameter,ClassNode>controlStructureVariablesprotected org.codehaus.groovy.transform.stc.DelegationMetadatadelegationMetadataWhenever a method using a closure as argument (typically, "with") is detected, this list is updated with the receiver type of the with method.protected LinkedList<BinaryExpression>enclosingBinaryExpressionsprotected LinkedList<BlockStatement>enclosingBlocksprotected LinkedList<ClassNode>enclosingClassNodesprotected LinkedList<TypeCheckingContext.EnclosingClosure>enclosingClosuresprotected LinkedList<Expression>enclosingMethodCallsprotected LinkedList<MethodNode>enclosingMethodsprotected LinkedList<ErrorCollector>errorCollectorsprotected Map<VariableExpression,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 parameter.protected Set<MethodNode>methodsToBeVisitedprotected Set<Long>reportedErrorsprotected 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 LinkedList<SwitchStatement>switchStatementsprotected Stack<Map<Object,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 visitor)
 - 
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.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.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.List<TypeCheckingContext.EnclosingClosure>getEnclosingClosureStack()Returns the current stack of enclosing closure expressions.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.List<Expression>getEnclosingMethodCalls()Returns the current stack of enclosing method calls.List<MethodNode>getEnclosingMethods()Returns the current stack of enclosing methods.SwitchStatementgetEnclosingSwitchStatement()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.ErrorCollectorgetErrorCollector()List<ErrorCollector>getErrorCollectors()SourceUnitgetSource()booleanisTargetOfEnclosingAssignment(Expression expression)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.MethodNodepopEnclosingMethod()Pops a method from the enclosing methods stack.ExpressionpopEnclosingMethodCall()Pops a method call from the enclosing method call stack.SwitchStatementpopEnclosingSwitchStatement()Pops a switch statement from the enclosing switch 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.voidpushEnclosingMethod(MethodNode methodNode)Pushes a method into the method stack.voidpushEnclosingMethodCall(Expression call)Pushes a method call into the method call stack.voidpushEnclosingSwitchStatement(SwitchStatement switchStatement)Pushes a switch statement into the switch statement stack.ErrorCollectorpushErrorCollector()voidpushErrorCollector(ErrorCollector collector)voidpushTemporaryTypeInfo()voidsetCompilationUnit(CompilationUnit compilationUnit)
 
- 
- 
- 
Field Detail- 
visitorprotected final StaticTypeCheckingVisitor visitor 
 - 
sourceprotected SourceUnit source 
 - 
compilationUnitprotected CompilationUnit compilationUnit 
 - 
errorCollectorsprotected final LinkedList<ErrorCollector> errorCollectors 
 - 
temporaryIfBranchTypeInformationprotected 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
 - 
delegationMetadataprotected 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.
 - 
isInStaticContextprotected boolean isInStaticContext 
 - 
lastImplicitItTypeprotected ClassNode lastImplicitItType The type of the last encountered "it" implicit parameter.
 - 
methodsToBeVisitedprotected Set<MethodNode> methodsToBeVisited 
 - 
ifElseForWhileAssignmentTrackerprotected 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 and String.
 - 
blockStatements2Typesprotected 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
 - 
alreadyVisitedMethodsprotected Set<MethodNode> alreadyVisitedMethods 
 - 
secondPassExpressionsprotected 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.
 - 
closureSharedVariablesAssignmentTypesprotected 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.
 - 
enclosingClassNodesprotected final LinkedList<ClassNode> enclosingClassNodes 
 - 
enclosingMethodsprotected final LinkedList<MethodNode> enclosingMethods 
 - 
enclosingMethodCallsprotected final LinkedList<Expression> enclosingMethodCalls 
 - 
enclosingBlocksprotected final LinkedList<BlockStatement> enclosingBlocks 
 - 
switchStatementsprotected final LinkedList<SwitchStatement> switchStatements 
 - 
enclosingClosuresprotected final LinkedList<TypeCheckingContext.EnclosingClosure> enclosingClosures 
 - 
enclosingBinaryExpressionsprotected final LinkedList<BinaryExpression> enclosingBinaryExpressions 
 
- 
 - 
Constructor Detail- 
TypeCheckingContextpublic TypeCheckingContext(StaticTypeCheckingVisitor visitor) 
 
- 
 - 
Method Detail- 
getSourcepublic SourceUnit getSource() 
 - 
getCompilationUnitpublic CompilationUnit getCompilationUnit() 
 - 
setCompilationUnitpublic void setCompilationUnit(CompilationUnit compilationUnit) 
 - 
pushErrorCollectorpublic ErrorCollector pushErrorCollector() 
 - 
pushErrorCollectorpublic void pushErrorCollector(ErrorCollector collector) 
 - 
popErrorCollectorpublic ErrorCollector popErrorCollector() 
 - 
getErrorCollectorpublic ErrorCollector getErrorCollector() 
 - 
getErrorCollectorspublic List<ErrorCollector> getErrorCollectors() 
 - 
pushTemporaryTypeInfopublic void pushTemporaryTypeInfo() 
 - 
popTemporaryTypeInfopublic void popTemporaryTypeInfo() 
 - 
pushEnclosingBinaryExpressionpublic void pushEnclosingBinaryExpression(BinaryExpression binaryExpression) Pushes a binary expression into the binary expression stack.
 - 
popEnclosingBinaryExpressionpublic BinaryExpression popEnclosingBinaryExpression() Pops a binary expression from the binary expression stack.
 - 
getEnclosingBinaryExpressionpublic BinaryExpression getEnclosingBinaryExpression() Returns the binary expression which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingBinaryExpressionStackpublic List<BinaryExpression> getEnclosingBinaryExpressionStack() Returns the current stack of enclosing binary expressions. The first element is the top of the stack.
 - 
isTargetOfEnclosingAssignmentpublic boolean isTargetOfEnclosingAssignment(Expression expression) 
 - 
pushEnclosingClosureExpressionpublic void pushEnclosingClosureExpression(ClosureExpression closureExpression) Pushes a closure expression into the closure expression stack.
 - 
popEnclosingClosurepublic TypeCheckingContext.EnclosingClosure popEnclosingClosure() Pops a closure expression from the closure expression stack.
 - 
getEnclosingClosurepublic TypeCheckingContext.EnclosingClosure getEnclosingClosure() Returns the closure expression which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingClosureStackpublic List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack() Returns the current stack of enclosing closure expressions. The first element is the top of the stack.
 - 
pushEnclosingClassNodepublic void pushEnclosingClassNode(ClassNode classNode) Pushes a class into the classes stack.
 - 
popEnclosingClassNodepublic ClassNode popEnclosingClassNode() Pops a class from the enclosing classes stack.
 - 
getEnclosingClassNodepublic ClassNode getEnclosingClassNode() Returns the class node which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingClassNodespublic 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.
 - 
pushEnclosingMethodpublic void pushEnclosingMethod(MethodNode methodNode) Pushes a method into the method stack.
 - 
popEnclosingMethodpublic MethodNode popEnclosingMethod() Pops a method from the enclosing methods stack.
 - 
getEnclosingMethodpublic MethodNode getEnclosingMethod() Returns the method node which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingMethodspublic 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.
 - 
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.
 - 
getEnclosingMethodCallpublic Expression getEnclosingMethodCall() Returns the method call which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingMethodCallspublic 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.
 - 
pushEnclosingSwitchStatementpublic void pushEnclosingSwitchStatement(SwitchStatement switchStatement) Pushes a switch statement into the switch statement stack.
 - 
popEnclosingSwitchStatementpublic SwitchStatement popEnclosingSwitchStatement() Pops a switch statement from the enclosing switch statements stack.
 - 
getEnclosingSwitchStatementpublic SwitchStatement getEnclosingSwitchStatement() Returns the switch statement which is on the top of the stack, or null if there's no such element.
 - 
getEnclosingSwitchStatementspublic 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.
 
- 
 
-