Top Inners Fields Constructors Methods
org.codehaus.groovy.transform.stc

public Class TypeCheckingContext

extends Object
Class Inheritance
Imports
org.codehaus.groovy.ast.ClassNode, .MethodNode, .Parameter, org.codehaus.groovy.ast.expr.BinaryExpression, .ClosureExpression, .Expression, .MethodCallExpression, .StaticMethodCallExpression, .VariableExpression, org.codehaus.groovy.ast.stmt.BlockStatement, .SwitchStatement, org.codehaus.groovy.control.CompilationUnit, .CompilerConfiguration, .ErrorCollector, .SourceUnit, java.util.Collections, .HashMap, .HashSet, .IdentityHashMap, .LinkedHashSet, .LinkedList, .List, .Map, .Optional, .Set, .Stack, .TreeSet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
TypeCheckingContext.EnclosingClosure

Represents the context of an enclosing closure.

Field Summary

Modifier and TypeField and Description
protected Set<MethodNode>
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.

protected CompilationUnit
protected Map<Parameter, ClassNode>
protected 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.

protected final LinkedList<BinaryExpression>
protected final LinkedList<BlockStatement>
protected final LinkedList<ClassNode>
protected final LinkedList<TypeCheckingContext.EnclosingClosure>
protected final LinkedList<Expression>
protected final LinkedList<MethodNode>
protected final LinkedList<ErrorCollector>
protected Map<VariableExpression, List<ClassNode>>
ifElseForWhileAssignmentTracker

This field is used to track assignments in if/else branches, for loops and while loops.

protected boolean
protected ClassNode
lastImplicitItType

The type of the last encountered "it" implicit parameter.

protected Set<MethodNode>
protected final Set<Long>
protected final LinkedHashSet<SecondPassExpression<T>>
secondPassExpressions

Some expressions need to be visited twice, because type information may be insufficient at some point.

protected SourceUnit
protected final LinkedList<SwitchStatement>
protected Stack<Map<Object, List<ClassNode>>>
temporaryIfBranchTypeInformation

Stores information which is only valid in the "if" branch of an if-then-else statement.

protected final StaticTypeCheckingVisitor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public CompilationUnit
public BinaryExpression
getEnclosingBinaryExpression()

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

public List<BinaryExpression>
getEnclosingBinaryExpressionStack()

Returns the current stack of enclosing 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.

public List<ClassNode>
getEnclosingClassNodes()

Returns the current stack of enclosing classes.

public TypeCheckingContext.EnclosingClosure
getEnclosingClosure()

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

public List<TypeCheckingContext.EnclosingClosure>
getEnclosingClosureStack()

Returns the current stack of enclosing 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.

public Expression
getEnclosingMethodCall()

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

public List<Expression>
getEnclosingMethodCalls()

Returns the current stack of enclosing method calls.

public List<MethodNode>
getEnclosingMethods()

Returns the current stack of enclosing methods.

public SwitchStatement
getEnclosingSwitchStatement()

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

public List<SwitchStatement>
getEnclosingSwitchStatements()

Returns the current stack of enclosing switch statements.

public ErrorCollector
public List<ErrorCollector>
public SourceUnit
public boolean
public BinaryExpression
popEnclosingBinaryExpression()

Pops a binary expression from the binary expression stack.

public ClassNode
popEnclosingClassNode()

Pops a class from the enclosing classes stack.

public TypeCheckingContext.EnclosingClosure
popEnclosingClosure()

Pops a closure expression from the closure expression stack.

public MethodNode
popEnclosingMethod()

Pops a method from the enclosing methods stack.

public Expression
popEnclosingMethodCall()

Pops a method call from the enclosing method call stack.

public SwitchStatement
popEnclosingSwitchStatement()

Pops a switch statement from the enclosing switch statements stack.

public ErrorCollector
public void
public void
pushEnclosingBinaryExpression(final BinaryExpression binaryExpression)

Pushes a binary expression into the binary expression stack.

public void
pushEnclosingClassNode(final ClassNode classNode)

Pushes a class into the classes stack.

public void
pushEnclosingClosureExpression(final ClosureExpression closureExpression)

Pushes a closure expression into the closure expression stack.

public void
pushEnclosingMethod(final MethodNode methodNode)

Pushes a method into the method stack.

public void
pushEnclosingMethodCall(final Expression
the call expression to be pushed, either a MethodCallExpression or a StaticMethodCallExpression
call
)

Pushes a method call into the method call stack.

public void
pushEnclosingSwitchStatement(final SwitchStatement switchStatement)

Pushes a switch statement into the switch statement stack.

public ErrorCollector
public void
public void
public void
setCompilationUnit(final CompilationUnit compilationUnit)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alreadyVisitedMethodsback to summary
protected Set<MethodNode> alreadyVisitedMethods
blockStatements2Typesback to summary
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

closureSharedVariablesAssignmentTypesback to summary
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.

compilationUnitback to summary
protected CompilationUnit compilationUnit
controlStructureVariablesback to summary
protected Map<Parameter, ClassNode> controlStructureVariables
delegationMetadataback to summary
protected 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.

enclosingBinaryExpressionsback to summary
protected final LinkedList<BinaryExpression> enclosingBinaryExpressions
enclosingBlocksback to summary
protected final LinkedList<BlockStatement> enclosingBlocks
enclosingClassNodesback to summary
protected final LinkedList<ClassNode> enclosingClassNodes
enclosingClosuresback to summary
protected final LinkedList<TypeCheckingContext.EnclosingClosure> enclosingClosures
enclosingMethodCallsback to summary
protected final LinkedList<Expression> enclosingMethodCalls
enclosingMethodsback to summary
protected final LinkedList<MethodNode> enclosingMethods
errorCollectorsback to summary
protected final LinkedList<ErrorCollector> errorCollectors
ifElseForWhileAssignmentTrackerback to summary
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 and String.

isInStaticContextback to summary
protected boolean isInStaticContext
lastImplicitItTypeback to summary
protected ClassNode lastImplicitItType

The type of the last encountered "it" implicit parameter.

methodsToBeVisitedback to summary
protected Set<MethodNode> methodsToBeVisited
reportedErrorsback to summary
protected final Set<Long> reportedErrors
secondPassExpressionsback to summary
protected final LinkedHashSet<SecondPassExpression<T>> 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.

sourceback to summary
protected SourceUnit source
switchStatementsback to summary
protected final LinkedList<SwitchStatement> switchStatements
temporaryIfBranchTypeInformationback to summary
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

visitorback to summary
protected final StaticTypeCheckingVisitor visitor

Constructor Detail

TypeCheckingContextback to summary
public TypeCheckingContext(final StaticTypeCheckingVisitor visitor)

Method Detail

getCompilationUnitback to summary
public CompilationUnit getCompilationUnit()
getEnclosingBinaryExpressionback to summary
public BinaryExpression getEnclosingBinaryExpression()

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

getEnclosingBinaryExpressionStackback to summary
public List<BinaryExpression> getEnclosingBinaryExpressionStack()

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

getEnclosingClassNodeback to summary
public ClassNode getEnclosingClassNode()

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

getEnclosingClassNodesback to summary
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.

getEnclosingClosureback to summary
public TypeCheckingContext.EnclosingClosure getEnclosingClosure()

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

getEnclosingClosureStackback to summary
public List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack()

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

getEnclosingMethodback to summary
public MethodNode getEnclosingMethod()

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

getEnclosingMethodCallback to summary
public Expression getEnclosingMethodCall()

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

getEnclosingMethodCallsback to summary
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.

getEnclosingMethodsback to summary
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.

getEnclosingSwitchStatementback to summary
public SwitchStatement getEnclosingSwitchStatement()

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

getEnclosingSwitchStatementsback to summary
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.

getErrorCollectorback to summary
public ErrorCollector getErrorCollector()
getErrorCollectorsback to summary
public List<ErrorCollector> getErrorCollectors()
getSourceback to summary
public SourceUnit getSource()
isTargetOfEnclosingAssignmentback to summary
public boolean isTargetOfEnclosingAssignment(final Expression expression)
popEnclosingBinaryExpressionback to summary
public BinaryExpression popEnclosingBinaryExpression()

Pops a binary expression from the binary expression stack.

popEnclosingClassNodeback to summary
public ClassNode popEnclosingClassNode()

Pops a class from the enclosing classes stack.

popEnclosingClosureback to summary
public TypeCheckingContext.EnclosingClosure popEnclosingClosure()

Pops a closure expression from the closure expression stack.

popEnclosingMethodback to summary
public MethodNode popEnclosingMethod()

Pops a method from the enclosing methods stack.

popEnclosingMethodCallback to summary
public Expression popEnclosingMethodCall()

Pops a method call from the enclosing method call stack.

popEnclosingSwitchStatementback to summary
public SwitchStatement popEnclosingSwitchStatement()

Pops a switch statement from the enclosing switch statements stack.

popErrorCollectorback to summary
public ErrorCollector popErrorCollector()
popTemporaryTypeInfoback to summary
public void popTemporaryTypeInfo()
pushEnclosingBinaryExpressionback to summary
public void pushEnclosingBinaryExpression(final BinaryExpression binaryExpression)

Pushes a binary expression into the binary expression stack.

pushEnclosingClassNodeback to summary
public void pushEnclosingClassNode(final ClassNode classNode)

Pushes a class into the classes stack.

pushEnclosingClosureExpressionback to summary
public void pushEnclosingClosureExpression(final ClosureExpression closureExpression)

Pushes a closure expression into the closure expression stack.

pushEnclosingMethodback to summary
public void pushEnclosingMethod(final MethodNode methodNode)

Pushes a method into the method stack.

pushEnclosingMethodCallback to summary
public void pushEnclosingMethodCall(final Expression call)

Pushes a method call into the method call stack.

Parameters
call:Expression

the call expression to be pushed, either a MethodCallExpression or a StaticMethodCallExpression

pushEnclosingSwitchStatementback to summary
public void pushEnclosingSwitchStatement(final SwitchStatement switchStatement)

Pushes a switch statement into the switch statement stack.

pushErrorCollectorback to summary
public ErrorCollector pushErrorCollector()
pushErrorCollectorback to summary
public void pushErrorCollector(final ErrorCollector collector)
pushTemporaryTypeInfoback to summary
public void pushTemporaryTypeInfo()
setCompilationUnitback to summary
public void setCompilationUnit(final CompilationUnit compilationUnit)
org.codehaus.groovy.transform.stc back to summary

public Class TypeCheckingContext.EnclosingClosure

extends Object
Class Inheritance
  • java.lang.Object
  • org.codehaus.groovy.transform.stc.TypeCheckingContext.EnclosingClosure

Represents the context of an enclosing closure. An enclosing closure wraps a closure expression and the list of return types found in the closure body.

Field Summary

Modifier and TypeField and Description
private final ClosureExpression
private final List<ClassNode>

Constructor Summary

AccessConstructor and Description
public
EnclosingClosure(final ClosureExpression closureExpression)

Method Summary

Modifier and TypeMethod and Description
public void
public ClosureExpression
public List<ClassNode>
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

closureExpressionback to summary
private final ClosureExpression closureExpression
returnTypesback to summary
private final List<ClassNode> returnTypes

Constructor Detail

EnclosingClosureback to summary
public EnclosingClosure(final ClosureExpression closureExpression)

Method Detail

addReturnTypeback to summary
public void addReturnType(final ClassNode type)
getClosureExpressionback to summary
public ClosureExpression getClosureExpression()
getReturnTypesback to summary
public List<ClassNode> getReturnTypes()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override