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

public Class DefaultTypeCheckingExtension

extends TypeCheckingExtension
Class Inheritance
Imports
org.codehaus.groovy.ast.ClassHelper, .ClassNode, .MethodNode, org.codehaus.groovy.ast.expr.ArgumentListExpression, .AttributeExpression, .Expression, .MethodCall, .PropertyExpression, .VariableExpression, org.codehaus.groovy.ast.stmt.ReturnStatement, java.util.ArrayList, .Iterator, .LinkedList, .List

The default type checking handler is used by the standard type checker and doesn't handle any of the type checking errors by default. This just means that whenever a type checking error is detected, there's no additional information available to the type checker that could help it. The default handler is also capable of handling a collection of delegate handlers. If a list of delegates is set, then the type checker will try all the delegates until one is capable of handling an error.
Since
2.1.0

Field Summary

Modifier and TypeField and Description
protected final List<TypeCheckingExtension>
Inherited from org.codehaus.groovy.transform.stc.TypeCheckingExtension:
typeCheckingVisitor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
afterVisitClass(final ClassNode
a class node
node
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitClass.

Allows the extension to perform additional tasks after the type checker actually visited a class node.
public void
afterVisitMethod(final MethodNode
a method node
node
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitMethod.

Allows the extension to perform additional tasks after the type checker actually visited a method node.
public boolean
public boolean
beforeVisitClass(final ClassNode
a class node
node
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitClass.

Allows the extension to perform additional tasks before the type checker actually visits a class node.
public boolean
beforeVisitMethod(final MethodNode
a method node
node
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitMethod.

Allows the extension to perform additional tasks before the type checker actually visits a method node.
public void
finish()

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.finish.

Subclasses should implement this method if they need to perform additional checks after the type checker has finished its work.
public List<MethodNode>
handleAmbiguousMethods(final List<MethodNode>
the list of ambiguous methods
nodes
,
final Expression
the expression which originated the method selection process
origin
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleAmbiguousMethods.

This method is called by the type checker before throwing an "ambiguous method" error, giving the chance to the extension to select the method properly.
public boolean
handleIncompatibleAssignment(final ClassNode
the type of the left hand side of the assignment, as found by the type checker
lhsType
,
final ClassNode
the type of the right hand side of the assignment, as found by the type checker
rhsType
,
final Expression
the assignment expression which triggered this call
assignmentExpression
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleAssignment.

This method is called by the type checker when an assignment is not allowed by the type checker.
public boolean
handleIncompatibleReturnType(ReturnStatement
the statement that triggered the error
returnStatement
,
ClassNode
the inferred return type for this statement
inferredReturnType
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleReturnType.

Allows the extension to catch incompatible return types.
public List<MethodNode>
handleMissingMethod(final ClassNode
the type of the receiver
receiver
,
final String
the name of the called method
name
,
final ArgumentListExpression
the list of arguments of the call
argumentList
,
final ClassNode[]
the types of the arguments of the call
argumentTypes
,
final MethodCall
the method call itself, if needed
call
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleMissingMethod.

This method is called by the type checker when a method call cannot be resolved.
public boolean
handleUnresolvedAttribute(final AttributeExpression
the unresolved attribute
aexp
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedAttribute.

This method is called by the type checker when an attribute expression cannot be resolved (for example, when an attribute doesn't exist).
public boolean
handleUnresolvedProperty(final PropertyExpression
the unresolved property
pexp
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedProperty.

This method is called by the type checker when a property expression cannot be resolved (for example, when a property doesn't exist).
public boolean
handleUnresolvedVariableExpression(VariableExpression
the unresolved variable extension
vexp
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedVariableExpression.

This method is called by the type checker when a variable expression cannot be resolved.
public void
onMethodSelection(final Expression
the expression for which a corresponding method has been found
expression
,
final MethodNode
the method which has been chosen by the type checker
target
)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.onMethodSelection.

Allows the extension to listen to method selection events.
public void
public void
setup()

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.setup.

Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.
Inherited from org.codehaus.groovy.transform.stc.TypeCheckingExtension:
addStaticTypeErrorbuildListTypebuildMapTypeclassNodeForclassNodeForexistsPropertyexistsPropertyextractStaticReceivergetArgumentTypesgetTargetMethodgetTypeisStaticMethodCallOnClasslookupClassNodeForparameterizedTypestoreType

Field Detail

handlersback to summary
protected final List<TypeCheckingExtension> handlers

Constructor Detail

DefaultTypeCheckingExtensionback to summary
public DefaultTypeCheckingExtension(final StaticTypeCheckingVisitor typeCheckingVisitor)

Method Detail

addHandlerback to summary
public void addHandler(TypeCheckingExtension handler)
afterMethodCallback to summary
public void afterMethodCall(final MethodCall call)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterMethodCall.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterMethodCall.

Allows the extension to perform additional tasks after the type checker actually visits a method call. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
call:MethodCall

a method call, either a org.codehaus.groovy.ast.expr.MethodCallExpression, org.codehaus.groovy.ast.expr.StaticMethodCallExpression, or org.codehaus.groovy.ast.expr.ConstructorCallExpression

Annotations
@Override
afterVisitClassback to summary
public void afterVisitClass(final ClassNode node)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitClass.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitClass.

Allows the extension to perform additional tasks after the type checker actually visited a class node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
node:ClassNode

a class node

Annotations
@Override
afterVisitMethodback to summary
public void afterVisitMethod(final MethodNode node)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitMethod.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.afterVisitMethod.

Allows the extension to perform additional tasks after the type checker actually visited a method node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
node:MethodNode

a method node

Annotations
@Override
beforeMethodCallback to summary
public boolean beforeMethodCall(final MethodCall call)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeMethodCall.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeMethodCall.

Allows the extension to perform additional tasks before the type checker actually visits a method call. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
call:MethodCall

a method call, either a org.codehaus.groovy.ast.expr.MethodCallExpression, org.codehaus.groovy.ast.expr.StaticMethodCallExpression, or org.codehaus.groovy.ast.expr.ConstructorCallExpression

Returns:boolean

false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the method call.

Annotations
@Override
beforeVisitClassback to summary
public boolean beforeVisitClass(final ClassNode node)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitClass.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitClass.

Allows the extension to perform additional tasks before the type checker actually visits a class node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
node:ClassNode

a class node

Returns:boolean

false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the class.

Annotations
@Override
beforeVisitMethodback to summary
public boolean beforeVisitMethod(final MethodNode node)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitMethod.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.beforeVisitMethod.

Allows the extension to perform additional tasks before the type checker actually visits a method node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with groovy.transform.TypeCheckingMode#SKIP.

Parameters
node:MethodNode

a method node

Returns:boolean

false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the method.

Annotations
@Override
finishback to summary
public void finish()

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.finish.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.finish.

Subclasses should implement this method if they need to perform additional checks after the type checker has finished its work. This is particularly useful for situations where you need multiple passes. Some checks in that case may be deferred to the end, using this method.

Annotations
@Override
handleAmbiguousMethodsback to summary
public List<MethodNode> handleAmbiguousMethods(final List<MethodNode> nodes, final Expression origin)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleAmbiguousMethods.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleAmbiguousMethods.

This method is called by the type checker before throwing an "ambiguous method" error, giving the chance to the extension to select the method properly. This means that when this method is called, the "nodes" parameter contains at least two methods. If the returned list still contains at least two methods, then the type checker will throw an ambiguous method call error. If the returned method contains 1 element, then the type checker will not throw any error. It is invalid to return an empty list.

Parameters
nodes:List<MethodNode>

the list of ambiguous methods

origin:Expression

the expression which originated the method selection process

Returns:List<MethodNode>

a single element list of disambiguated selection, or more elements if still ambiguous. It is not allowed to return an empty list.

Annotations
@Override
handleIncompatibleAssignmentback to summary
public boolean handleIncompatibleAssignment(final ClassNode lhsType, final ClassNode rhsType, final Expression assignmentExpression)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleAssignment.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleAssignment.

This method is called by the type checker when an assignment is not allowed by the type checker. Extensions may override this method to allow such assignments where the type checker normally disallows them.

Parameters
lhsType:ClassNode

the type of the left hand side of the assignment, as found by the type checker

rhsType:ClassNode

the type of the right hand side of the assignment, as found by the type checker

assignmentExpression:Expression

the assignment expression which triggered this call

Returns:boolean

boolean false if the extension does not handle this assignment, true otherwise

Annotations
@Override
handleIncompatibleReturnTypeback to summary
public boolean handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleReturnType.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleIncompatibleReturnType.

Allows the extension to catch incompatible return types. This event is called whenever the type checker finds that an inferred return type is incompatible with the declared return type of a method.

Parameters
returnStatement:ReturnStatement

the statement that triggered the error

inferredReturnType:ClassNode

the inferred return type for this statement

Returns:boolean

false if the extension doesn't handle the error, true otherwise

Annotations
@Override
handleMissingMethodback to summary
public List<MethodNode> handleMissingMethod(final ClassNode receiver, final String name, final ArgumentListExpression argumentList, final ClassNode[] argumentTypes, final MethodCall call)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleMissingMethod.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleMissingMethod.

This method is called by the type checker when a method call cannot be resolved. Extensions may override this method to handle missing methods and prevent the type checker from throwing an error.

Parameters
receiver:ClassNode

the type of the receiver

name:String

the name of the called method

argumentList:ArgumentListExpression

the list of arguments of the call

argumentTypes:ClassNode[]

the types of the arguments of the call

call:MethodCall

the method call itself, if needed

Returns:List<MethodNode>

an empty list if the extension cannot resolve the method, or a list of potential methods if the extension finds candidates. This method must not return null.

handleUnresolvedAttributeback to summary
public boolean handleUnresolvedAttribute(final AttributeExpression aexp)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedAttribute.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedAttribute.

This method is called by the type checker when an attribute expression cannot be resolved (for example, when an attribute doesn't exist). It gives the extension a chance to resolve it.

Parameters
aexp:AttributeExpression

the unresolved attribute

Returns:boolean

boolean false if this extension doesn't resolve the attribute, true if it resolves the attribute.

handleUnresolvedPropertyback to summary
public boolean handleUnresolvedProperty(final PropertyExpression pexp)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedProperty.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedProperty.

This method is called by the type checker when a property expression cannot be resolved (for example, when a property doesn't exist). It gives the extension a chance to resolve it.

Parameters
pexp:PropertyExpression

the unresolved property

Returns:boolean

boolean false if this extension doesn't resolve the property, true if it resolves the property.

handleUnresolvedVariableExpressionback to summary
public boolean handleUnresolvedVariableExpression(VariableExpression vexp)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedVariableExpression.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.handleUnresolvedVariableExpression.

This method is called by the type checker when a variable expression cannot be resolved. It gives the extension a chance to resolve it for the type checker.

Parameters
vexp:VariableExpression

the unresolved variable extension

Returns:boolean

boolean false if the extension doesn't handle it, true if the extension handles this variable.

onMethodSelectionback to summary
public void onMethodSelection(final Expression expression, final MethodNode target)

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.onMethodSelection.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.onMethodSelection.

Allows the extension to listen to method selection events. Given an expression, which may be a method call expression, a static method call expression, a pre/postfix expression, ..., if a corresponding method is found, this method is called.

Parameters
expression:Expression

the expression for which a corresponding method has been found

target:MethodNode

the method which has been chosen by the type checker

Annotations
@Override
removeHandlerback to summary
public void removeHandler(TypeCheckingExtension handler)
setupback to summary
public void setup()

Overrides org.codehaus.groovy.transform.stc.TypeCheckingExtension.setup.

Doc from org.codehaus.groovy.transform.stc.TypeCheckingExtension.setup.

Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.

Annotations
@Override