org.codehaus.groovy.transform.stc

## Class StaticTypeCheckingVisitor

- java.lang.Object
- - org.codehaus.groovy.ast.CodeVisitorSupport
  - - org.codehaus.groovy.ast.ClassCodeVisitorSupport
    - - org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor

All Implemented Interfaces:
  GroovyClassVisitor, GroovyCodeVisitor

Direct Known Subclasses:
  StaticCompilationVisitor

    public class StaticTypeCheckingVisitor
    extends ClassCodeVisitorSupport

The main class code visitor responsible for static type checking. It will perform various inspections like checking assignment types, type inference, ... Eventually, class nodes may be annotated with inferred type information.

### Nested Class Summary

Nested Classes
`protected static interface` `StaticTypeCheckingVisitor.SignatureCodec`
`protected static class` `StaticTypeCheckingVisitor.SignatureCodecFactory`

### Field Summary

Fields
`static MethodNode` `CLOSURE_CALL_NO_ARG`
`static MethodNode` `CLOSURE_CALL_ONE_ARG`
`static MethodNode` `CLOSURE_CALL_VARGS`

### Constructor Summary

Constructors
Constructor and Description
`StaticTypeCheckingVisitor(SourceUnit source, ClassNode cn, TypeCheckerPluginFactory pluginFactory)`

### Method Summary

Methods
`protected void` `addError(java.lang.String msg, ASTNode expr)`
`protected void` `addStaticTypeError(java.lang.String msg, ASTNode expr)`
`protected void` `addTypeCheckingInfoAnnotation(MethodNode node)`
`protected boolean` `existsProperty(PropertyExpression pexp, boolean checkForReadOnly, ClassCodeVisitorSupport visitor)` Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the temporary type information table)
`protected MethodNode` `findMethodOrFail(Expression expr, ClassNode receiver, java.lang.String name, ClassNode... args)`
`protected SourceUnit` `getSourceUnit()`
`protected ClassNode` `getType(ASTNode exp)`
`protected ClassNode[]` `getTypeCheckingAnnotations()` Returns the list of type checking annotations class nodes.
`protected boolean` `hasSetter(PropertyExpression pexp)`
`protected ClassNode` `inferComponentType(ClassNode containerType, ClassNode indexType)`
`static ClassNode` `inferLoopElementType(ClassNode collectionType)` Given a loop collection type, returns the inferred type of the loop element.
`boolean` `isSkipMode(AnnotatedNode node)`
`void` `performSecondPass()`
`void` `setErrorCollector(ErrorCollector errorCollector)` Sets an alternative error collector.
`void` `setMethodsToBeVisited(java.util.Set<MethodNode> methodsToBeVisited)`
`protected boolean` `shouldSkipClassNode(ClassNode node)`
`protected boolean` `shouldSkipMethodNode(MethodNode node)`
`void` `visitAttributeExpression(AttributeExpression expression)`
`void` `visitBinaryExpression(BinaryExpression expression)`
`void` `visitBitwiseNegationExpression(BitwiseNegationExpression expression)`
`void` `visitCastExpression(CastExpression expression)`
`void` `visitClass(ClassNode node)` Visit a ClassNode.
`void` `visitClassExpression(ClassExpression expression)`
`void` `visitClosureExpression(ClosureExpression expression)`
`void` `visitConstructorCallExpression(ConstructorCallExpression call)`
`protected void` `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
`void` `visitField(FieldNode node)` Visit a FieldNode.
`void` `visitForLoop(ForStatement forLoop)`
`void` `visitIfElse(IfStatement ifElse)`
`void` `visitMethod(MethodNode node)` Visit a MethodNode.
`void` `visitMethodCallExpression(MethodCallExpression call)`
`void` `visitPostfixExpression(PostfixExpression expression)`
`void` `visitPrefixExpression(PrefixExpression expression)`
`void` `visitPropertyExpression(PropertyExpression pexp)`
`void` `visitRangeExpression(RangeExpression expression)`
`void` `visitReturnStatement(ReturnStatement statement)`
`void` `visitStaticMethodCallExpression(StaticMethodCallExpression call)`
`void` `visitTernaryExpression(TernaryExpression expression)`
`void` `visitTryCatchFinally(TryCatchStatement statement)`
`void` `visitUnaryMinusExpression(UnaryMinusExpression expression)`
`void` `visitUnaryPlusExpression(UnaryPlusExpression expression)`
`void` `visitVariableExpression(VariableExpression vexp)`
`void` `visitWhileLoop(WhileStatement loop)`

### Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport

`visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitImports, visitObjectInitializerStatements, visitPackage, visitProperty, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement`

### Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport

`visitArgumentlistExpression, visitArrayExpression, visitBooleanExpression, visitBytecodeExpression, visitClosureListExpression, visitConstantExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, visitMethodPointerExpression, visitNotExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitTupleExpression`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### CLOSURE_CALL_NO_ARG

    public static final MethodNode CLOSURE_CALL_NO_ARG

#### CLOSURE_CALL_ONE_ARG

    public static final MethodNode CLOSURE_CALL_ONE_ARG

#### CLOSURE_CALL_VARGS

    public static final MethodNode CLOSURE_CALL_VARGS

### Constructor Detail

#### StaticTypeCheckingVisitor

    public StaticTypeCheckingVisitor(SourceUnit source,
                             ClassNode cn,
                             TypeCheckerPluginFactory pluginFactory)

### Method Detail

#### getSourceUnit

    protected SourceUnit getSourceUnit()

Specified by:
  `getSourceUnit` in class `ClassCodeVisitorSupport`

#### setErrorCollector

    public void setErrorCollector(ErrorCollector errorCollector)

Sets an alternative error collector. This can be useful when you want to run static type checking "silently", for example, without failing if errors are found.

Parameters:
  `errorCollector` - an error collector

#### visitClass

    public void visitClass(ClassNode node)

Description copied from interface: `GroovyClassVisitor`
Visit a ClassNode.

Specified by:
  `visitClass` in interface `GroovyClassVisitor`
Overrides:
  `visitClass` in class `ClassCodeVisitorSupport`

#### shouldSkipClassNode

    protected boolean shouldSkipClassNode(ClassNode node)

#### getTypeCheckingAnnotations

    protected ClassNode[] getTypeCheckingAnnotations()

Returns the list of type checking annotations class nodes. Subclasses may override this method in order to provide additional classes which must be looked up when checking if a method or a class node should be skipped.

The default implementation returns `TypeChecked`.

Returns:
  array of class nodes

#### isSkipMode

    public boolean isSkipMode(AnnotatedNode node)

#### visitClassExpression

    public void visitClassExpression(ClassExpression expression)

Specified by:
  `visitClassExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitClassExpression` in class `CodeVisitorSupport`

#### visitVariableExpression

    public void visitVariableExpression(VariableExpression vexp)

Specified by:
  `visitVariableExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitVariableExpression` in class `CodeVisitorSupport`

#### visitPropertyExpression

    public void visitPropertyExpression(PropertyExpression pexp)

Specified by:
  `visitPropertyExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitPropertyExpression` in class `CodeVisitorSupport`

#### visitAttributeExpression

    public void visitAttributeExpression(AttributeExpression expression)

Specified by:
  `visitAttributeExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitAttributeExpression` in class `CodeVisitorSupport`

#### visitRangeExpression

    public void visitRangeExpression(RangeExpression expression)

Specified by:
  `visitRangeExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitRangeExpression` in class `CodeVisitorSupport`

#### visitBinaryExpression

    public void visitBinaryExpression(BinaryExpression expression)

Specified by:
  `visitBinaryExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitBinaryExpression` in class `CodeVisitorSupport`

#### existsProperty

    protected boolean existsProperty(PropertyExpression pexp,
                         boolean checkForReadOnly,
                         ClassCodeVisitorSupport visitor)

Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the temporary type information table)

Parameters:
  `pexp` - a property expression
  `checkForReadOnly` - also lookup for read only properties
  `visitor` - if not null, when the property node is found, visit it with the provided visitor
Returns:
  true if the property is defined in any of the possible receiver classes

#### hasSetter

    protected boolean hasSetter(PropertyExpression pexp)

#### visitField

    public void visitField(FieldNode node)

Description copied from interface: `GroovyClassVisitor`
Visit a FieldNode.

Specified by:
  `visitField` in interface `GroovyClassVisitor`
Overrides:
  `visitField` in class `ClassCodeVisitorSupport`

#### visitForLoop

    public void visitForLoop(ForStatement forLoop)

Specified by:
  `visitForLoop` in interface `GroovyCodeVisitor`
Overrides:
  `visitForLoop` in class `ClassCodeVisitorSupport`

#### inferLoopElementType

    public static ClassNode inferLoopElementType(ClassNode collectionType)

Given a loop collection type, returns the inferred type of the loop element. Used, for example, to infer the element type of a (for e in list) loop.

Parameters:
  `collectionType` - the type of the collection
Returns:
  the inferred component type

#### visitWhileLoop

    public void visitWhileLoop(WhileStatement loop)

Specified by:
  `visitWhileLoop` in interface `GroovyCodeVisitor`
Overrides:
  `visitWhileLoop` in class `ClassCodeVisitorSupport`

#### visitBitwiseNegationExpression

    public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

Specified by:
  `visitBitwiseNegationExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitBitwiseNegationExpression` in class `CodeVisitorSupport`

#### visitUnaryPlusExpression

    public void visitUnaryPlusExpression(UnaryPlusExpression expression)

Specified by:
  `visitUnaryPlusExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitUnaryPlusExpression` in class `CodeVisitorSupport`

#### visitUnaryMinusExpression

    public void visitUnaryMinusExpression(UnaryMinusExpression expression)

Specified by:
  `visitUnaryMinusExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitUnaryMinusExpression` in class `CodeVisitorSupport`

#### visitPostfixExpression

    public void visitPostfixExpression(PostfixExpression expression)

Specified by:
  `visitPostfixExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitPostfixExpression` in class `CodeVisitorSupport`

#### visitPrefixExpression

    public void visitPrefixExpression(PrefixExpression expression)

Specified by:
  `visitPrefixExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitPrefixExpression` in class `CodeVisitorSupport`

#### visitConstructorOrMethod

    protected void visitConstructorOrMethod(MethodNode node,
                                boolean isConstructor)

Overrides:
  `visitConstructorOrMethod` in class `ClassCodeVisitorSupport`

#### visitReturnStatement

    public void visitReturnStatement(ReturnStatement statement)

Specified by:
  `visitReturnStatement` in interface `GroovyCodeVisitor`
Overrides:
  `visitReturnStatement` in class `ClassCodeVisitorSupport`

#### visitConstructorCallExpression

    public void visitConstructorCallExpression(ConstructorCallExpression call)

Specified by:
  `visitConstructorCallExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitConstructorCallExpression` in class `CodeVisitorSupport`

#### visitClosureExpression

    public void visitClosureExpression(ClosureExpression expression)

Specified by:
  `visitClosureExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitClosureExpression` in class `CodeVisitorSupport`

#### shouldSkipMethodNode

    protected boolean shouldSkipMethodNode(MethodNode node)

#### visitMethod

    public void visitMethod(MethodNode node)

Description copied from interface: `GroovyClassVisitor`
Visit a MethodNode.

Specified by:
  `visitMethod` in interface `GroovyClassVisitor`
Overrides:
  `visitMethod` in class `ClassCodeVisitorSupport`

#### addTypeCheckingInfoAnnotation

    protected void addTypeCheckingInfoAnnotation(MethodNode node)

#### visitStaticMethodCallExpression

    public void visitStaticMethodCallExpression(StaticMethodCallExpression call)

Specified by:
  `visitStaticMethodCallExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitStaticMethodCallExpression` in class `CodeVisitorSupport`

#### visitMethodCallExpression

    public void visitMethodCallExpression(MethodCallExpression call)

Specified by:
  `visitMethodCallExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitMethodCallExpression` in class `CodeVisitorSupport`

#### visitIfElse

    public void visitIfElse(IfStatement ifElse)

Specified by:
  `visitIfElse` in interface `GroovyCodeVisitor`
Overrides:
  `visitIfElse` in class `ClassCodeVisitorSupport`

#### visitCastExpression

    public void visitCastExpression(CastExpression expression)

Specified by:
  `visitCastExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitCastExpression` in class `CodeVisitorSupport`

#### visitTernaryExpression

    public void visitTernaryExpression(TernaryExpression expression)

Specified by:
  `visitTernaryExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitTernaryExpression` in class `CodeVisitorSupport`

#### visitTryCatchFinally

    public void visitTryCatchFinally(TryCatchStatement statement)

Specified by:
  `visitTryCatchFinally` in interface `GroovyCodeVisitor`
Overrides:
  `visitTryCatchFinally` in class `ClassCodeVisitorSupport`

#### inferComponentType

    protected ClassNode inferComponentType(ClassNode containerType,
                               ClassNode indexType)

#### findMethodOrFail

    protected MethodNode findMethodOrFail(Expression expr,
                              ClassNode receiver,
                              java.lang.String name,
                              ClassNode... args)

#### getType

    protected ClassNode getType(ASTNode exp)

#### addError

    protected void addError(java.lang.String msg,
                ASTNode expr)

Overrides:
  `addError` in class `ClassCodeVisitorSupport`

#### addStaticTypeError

    protected void addStaticTypeError(java.lang.String msg,
                          ASTNode expr)

#### setMethodsToBeVisited

    public void setMethodsToBeVisited(java.util.Set<MethodNode> methodsToBeVisited)

#### performSecondPass

    public void performSecondPass()