Groovy Documentation

## 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)` Returns the list of type checking annotations class nodes.
`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)` Given a loop collection type, returns the inferred type of the loop element.
`void` | `visitForLoop(ForStatement forLoop)`
`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

    return encoded;
    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)

  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

### shouldSkipMethodNode

    protected boolean shouldSkipMethodNode(MethodNode node)

### visitAttributeExpression

    public void visitAttributeExpression(AttributeExpression expression)

### visitBinaryExpression

    // unchecked assignment
    public void visitBinaryExpression(BinaryExpression expression)

### visitBitwiseNegationExpression

    }
    public void visitBitwiseNegationExpression(BitwiseNegationExpression expression)

### visitCastExpression

    // is an empty list expression ([]). In that case and only in that case, the inferred type
    public void visitCastExpression(CastExpression expression)

### visitClass

    classNode = node;
    public void visitClass(ClassNode node)

### visitClassExpression

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

### visitClosureExpression

    return;
    public void visitClosureExpression(ClosureExpression expression)

### visitConstructorCallExpression

    Map<VariableExpression, List<ClassNode>> oldTracker = pushAssignmentTracking();
    public void visitConstructorCallExpression(ConstructorCallExpression call)

### visitConstructorOrMethod

    }
    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

### visitField

    public static ClassNode inferLoopElementType(final ClassNode collectionType) {
    public void visitField(FieldNode node)

  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

### visitForLoop

    }
    public void visitForLoop(ForStatement forLoop)

### visitIfElse

    storeType(exp, getOriginalDeclarationType(exp));
    public void visitIfElse(IfStatement ifElse)

### visitMethod

    public void visitMethod(MethodNode node)

### visitMethodCallExpression

    typeCheckClosureCall(callArguments, args, parameters);
    public void visitMethodCallExpression(MethodCallExpression call)

### visitPostfixExpression

    }
    public void visitPostfixExpression(PostfixExpression expression)

### visitPrefixExpression

    && !(isNullConstant(expression))) {
    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

    private MethodNode typeCheckMapConstructor(final ConstructorCallExpression call, final ClassNode receiver, final Expression arguments) {
    public void visitReturnStatement(ReturnStatement statement)

### visitStaticMethodCallExpression

    } else {
    public void visitStaticMethodCallExpression(StaticMethodCallExpression call)

### visitTernaryExpression

    if (isIntCategory(leftRedirect) && isIntCategory(rightRedirect)) return int_TYPE;
    public void visitTernaryExpression(TernaryExpression expression)

### visitTryCatchFinally

    if (DIVIDE == op) {
    public void visitTryCatchFinally(TryCatchStatement statement)

### visitUnaryMinusExpression

    MethodNode mn = findMethodOrFail(expression, type, name);
    public void visitUnaryMinusExpression(UnaryMinusExpression expression)

### visitUnaryPlusExpression

    ClassNode resultType;
    public void visitUnaryPlusExpression(UnaryPlusExpression expression)

### visitVariableExpression

    }
    public void visitVariableExpression(VariableExpression vexp)

### visitWhileLoop

    String name = type == PLUS_PLUS ? "next" : type == MINUS_MINUS ? "previous" : null;
    public void visitWhileLoop(WhileStatement loop)

Groovy Documentation