Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.transform.stc
[Java] Class StaticTypeCheckingVisitor

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

    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.

Authors:
  Cedric Champeau
  Jochen Theodorou

Nested Class Summary
`protected static interface` | `StaticTypeCheckingVisitor.SignatureCodec`
`protected static class` | `StaticTypeCheckingVisitor.SignatureCodecFactory`

Field Summary
`static MethodNode` | `CLOSURE_CALL_NO_ARG`
`static MethodNode` | `CLOSURE_CALL_ONE_ARG`
`static MethodNode` | `CLOSURE_CALL_VARGS`

Constructor Summary
`StaticTypeCheckingVisitor(SourceUnit source, ClassNode cn, TypeCheckerPluginFactory pluginFactory)`

Method Summary
`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)`
`protected MethodNode` | `findMethodOrFail(Expression expr, ClassNode receiver, java.lang.String name, ClassNode... args)`
`protected SourceUnit` | `getSourceUnit()` Sets an alternative error collector.
`protected ClassNode` | `getType(ASTNode exp)`
`protected ClassNode[]` | `getTypeCheckingAnnotations()`
`protected boolean` | `hasSetter(PropertyExpression pexp)`
`protected ClassNode` | `inferComponentType(ClassNode containerType, ClassNode indexType)`
`static ClassNode` | `inferLoopElementType(ClassNode collectionType)`
`boolean` | `isSkipMode(AnnotatedNode node)`
`void` | `performSecondPass()`
`void` | `setErrorCollector(ErrorCollector errorCollector)`
`void` | `setMethodsToBeVisited(java.util.Set 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)`
`void` | `visitClassExpression(ClassExpression expression)`
`void` | `visitClosureExpression(ClosureExpression expression)`
`void` | `visitConstructorCallExpression(ConstructorCallExpression call)`
`protected void` | `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
`void` | `visitField(FieldNode node)`
`void` | `visitForLoop(ForStatement forLoop)` Given a loop collection type, returns the inferred type of the loop element.
`void` | `visitIfElse(IfStatement ifElse)`
`void` | `visitMethod(MethodNode node)`
`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 ClassCodeVisitorSupport
addError, getSourceUnit, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop

Methods inherited from class CodeVisitorSupport
visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

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

### addError

    doEncode(bound, dos);
    protected void addError(java.lang.String msg, ASTNode expr)

### addStaticTypeError

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

### addTypeCheckingInfoAnnotation

    protected void addTypeCheckingInfoAnnotation(MethodNode node)

### existsProperty

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

### findMethodOrFail

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

### getSourceUnit

    protected SourceUnit getSourceUnit()

  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

### getType

    protected ClassNode getType(ASTNode exp)

### getTypeCheckingAnnotations

    protected ClassNode[] getTypeCheckingAnnotations()

### hasSetter

    protected boolean hasSetter(PropertyExpression pexp)

### inferComponentType

    protected ClassNode inferComponentType(ClassNode containerType, ClassNode indexType)

### inferLoopElementType

    public static ClassNode inferLoopElementType(ClassNode collectionType)

### isSkipMode

    public boolean isSkipMode(AnnotatedNode node)

### performSecondPass

    public void performSecondPass()

### setErrorCollector

    public void setErrorCollector(ErrorCollector errorCollector)

### setMethodsToBeVisited

    public void setMethodsToBeVisited(java.util.Set methodsToBeVisited)

### shouldSkipClassNode

    protected boolean shouldSkipClassNode(ClassNode node)

### shouldSkipMethodNode

    protected boolean shouldSkipMethodNode(MethodNode node)

### visitAttributeExpression

    public void visitAttributeExpression(AttributeExpression expression)

### visitBinaryExpression

    && oldBinaryExpression.getLeftExpression()==expression
    public void visitBinaryExpression(BinaryExpression expression)

### visitBitwiseNegationExpression

    String name = type == PLUS_PLUS ? "next" : type == MINUS_MINUS ? "previous" : null;
    public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

### visitCastExpression

    ClassNode leftRedirect = left.redirect();
    public void visitCastExpression(CastExpression expression)

### visitClass

    InnerClassNode innerClassNode = innerClasses.next();
    public void visitClass(ClassNode node)

### visitClassExpression

    if (vexp.getName().equals("this")) storeType(vexp, classNode);
    public void visitClassExpression(ClassExpression expression)

### visitClosureExpression

    protected boolean shouldSkipMethodNode(final MethodNode node) {
    public void visitClosureExpression(ClosureExpression expression)

### visitConstructorCallExpression

    // collect every variable expression used in the loop body
    public void visitConstructorCallExpression(ConstructorCallExpression call)

### visitConstructorOrMethod

    }
    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

### visitField

    }
    public void visitField(FieldNode node)

### visitForLoop

    private boolean isSecondPassNeededForControlStructure(final Map varOrigType, final Map> oldTracker) {
    public void visitForLoop(ForStatement forLoop)

  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

### visitIfElse

    }
    public void visitIfElse(IfStatement ifElse)

### visitMethod

    public void visitMethod(MethodNode node)

### visitMethodCallExpression

    if (data != null) {
    public void visitMethodCallExpression(MethodCallExpression call)

### visitPostfixExpression

    this.methodNode = node;
    public void visitPostfixExpression(PostfixExpression expression)

### visitPrefixExpression

    && !checkCompatibleAssignmentTypes(methodNode.getReturnType(), type)
    public void visitPrefixExpression(PrefixExpression expression)

### visitPropertyExpression

    if (!existsProperty(expression, true)) {
    public void visitPropertyExpression(PropertyExpression pexp)

### visitRangeExpression

    ClassNode rType = getType(rightExpression);
    public void visitRangeExpression(RangeExpression expression)

### visitReturnStatement

    MapExpression argList = (MapExpression) expression;
    public void visitReturnStatement(ReturnStatement statement)

### visitStaticMethodCallExpression

    returnType = irtg!=null && implementsInterfaceOrIsSubclassOf(irtg, returnType)?irtg:returnType;
    public void visitStaticMethodCallExpression(StaticMethodCallExpression call)

### visitTernaryExpression

    }
    public void visitTernaryExpression(TernaryExpression expression)

### visitTryCatchFinally

    if (!isPrimitiveType(leftRedirect) || !isPrimitiveType(rightRedirect)) {
    public void visitTryCatchFinally(TryCatchStatement statement)

### visitUnaryMinusExpression

    storeType(expression, resultType);
    public void visitUnaryMinusExpression(UnaryMinusExpression expression)

### visitUnaryPlusExpression

    if (mn != null) {
    public void visitUnaryPlusExpression(UnaryPlusExpression expression)

### visitVariableExpression

    }
    public void visitVariableExpression(VariableExpression vexp)

### visitWhileLoop

    int type = expression.getOperation().getType();
    public void visitWhileLoop(WhileStatement loop)

Groovy Documentation