Class DefaultTypeCheckingExtension
java.lang.Object
org.codehaus.groovy.transform.stc.TypeCheckingExtension
org.codehaus.groovy.transform.stc.DefaultTypeCheckingExtension
public class DefaultTypeCheckingExtension extends TypeCheckingExtension
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
Fields Modifier and Type Field Description protected java.util.List<TypeCheckingExtension>
handlers
Fields inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension
typeCheckingVisitor
-
Constructor Summary
Constructors Constructor Description DefaultTypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor)
-
Method Summary
Modifier and Type Method Description void
addHandler(TypeCheckingExtension handler)
void
afterMethodCall(MethodCall call)
Allows the extension to perform additional tasks after the type checker actually visits a method call.void
afterVisitClass(ClassNode node)
Allows the extension to perform additional tasks after the type checker actually visited a class node.void
afterVisitMethod(MethodNode node)
Allows the extension to perform additional tasks after the type checker actually visited a method node.boolean
beforeMethodCall(MethodCall call)
Allows the extension to perform additional tasks before the type checker actually visits a method call.boolean
beforeVisitClass(ClassNode node)
Allows the extension to perform additional tasks before the type checker actually visits a class node.boolean
beforeVisitMethod(MethodNode node)
Allows the extension to perform additional tasks before the type checker actually visits a method node.void
finish()
Subclasses should implement this method if they need to perform additional checks after the type checker has finished its work.java.util.List<MethodNode>
handleAmbiguousMethods(java.util.List<MethodNode> nodes, Expression origin)
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.boolean
handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)
This method is called by the type checker when an assignment is not allowed by the type checker.boolean
handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)
Allows the extension to catch incompatible return types.java.util.List<MethodNode>
handleMissingMethod(ClassNode receiver, java.lang.String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)
This method is called by the type checker when a method call cannot be resolved.boolean
handleUnresolvedAttribute(AttributeExpression aexp)
This method is called by the type checker when an attribute expression cannot be resolved (for example, when an attribute doesn't exist).boolean
handleUnresolvedProperty(PropertyExpression pexp)
This method is called by the type checker when a property expression cannot be resolved (for example, when a property doesn't exist).boolean
handleUnresolvedVariableExpression(VariableExpression vexp)
This method is called by the type checker when a variable expression cannot be resolved.void
onMethodSelection(Expression expression, MethodNode target)
Allows the extension to listen to method selection events.void
removeHandler(TypeCheckingExtension handler)
void
setup()
Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.Methods inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension
addStaticTypeError, buildListType, buildMapType, classNodeFor, classNodeFor, existsProperty, existsProperty, extractStaticReceiver, getArgumentTypes, getTargetMethod, getType, isStaticMethodCallOnClass, lookupClassNodeFor, parameterizedType, storeType
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
handlers
-
-
Constructor Details
-
DefaultTypeCheckingExtension
-
-
Method Details
-
addHandler
-
removeHandler
-
handleUnresolvedVariableExpression
Description copied from class:TypeCheckingExtension
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.- Overrides:
handleUnresolvedVariableExpression
in classTypeCheckingExtension
- Parameters:
vexp
- the unresolved variable extension- Returns:
boolean
false if the extension doesn't handle it, true if the extension handles this variable.
-
handleUnresolvedProperty
Description copied from class:TypeCheckingExtension
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.- Overrides:
handleUnresolvedProperty
in classTypeCheckingExtension
- Parameters:
pexp
- the unresolved property- Returns:
boolean
false if this extension doesn't resolve the property, true if it resolves the property.
-
handleUnresolvedAttribute
Description copied from class:TypeCheckingExtension
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.- Overrides:
handleUnresolvedAttribute
in classTypeCheckingExtension
- Parameters:
aexp
- the unresolved attribute- Returns:
boolean
false if this extension doesn't resolve the attribute, true if it resolves the attribute.
-
handleIncompatibleAssignment
public boolean handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)Description copied from class:TypeCheckingExtension
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.- Overrides:
handleIncompatibleAssignment
in classTypeCheckingExtension
- Parameters:
lhsType
- the type of the left hand side of the assignment, as found by the type checkerrhsType
- the type of the right hand side of the assignment, as found by the type checkerassignmentExpression
- the assignment expression which triggered this call- Returns:
boolean
false if the extension does not handle this assignment, true otherwise
-
handleIncompatibleReturnType
public boolean handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)Description copied from class:TypeCheckingExtension
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.- Overrides:
handleIncompatibleReturnType
in classTypeCheckingExtension
- Parameters:
returnStatement
- the statement that triggered the errorinferredReturnType
- the inferred return type for this statement- Returns:
- false if the extension doesn't handle the error, true otherwise
-
handleAmbiguousMethods
public java.util.List<MethodNode> handleAmbiguousMethods(java.util.List<MethodNode> nodes, Expression origin)Description copied from class:TypeCheckingExtension
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.- Overrides:
handleAmbiguousMethods
in classTypeCheckingExtension
- Parameters:
nodes
- the list of ambiguous methodsorigin
- the expression which originated the method selection process- Returns:
- a single element list of disambiguated selection, or more elements if still ambiguous. It is not allowed to return an empty list.
-
handleMissingMethod
public java.util.List<MethodNode> handleMissingMethod(ClassNode receiver, java.lang.String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)Description copied from class:TypeCheckingExtension
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.- Overrides:
handleMissingMethod
in classTypeCheckingExtension
- Parameters:
receiver
- the type of the receivername
- the name of the called methodargumentList
- the list of arguments of the callargumentTypes
- the types of the arguments of the callcall
- the method call itself, if needed- Returns:
- 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.
-
afterVisitMethod
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
afterVisitMethod
in classTypeCheckingExtension
- Parameters:
node
- a method node
-
beforeVisitMethod
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
beforeVisitMethod
in classTypeCheckingExtension
- Parameters:
node
- a method node- Returns:
- false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the method.
-
afterVisitClass
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
afterVisitClass
in classTypeCheckingExtension
- Parameters:
node
- a class node
-
beforeVisitClass
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
beforeVisitClass
in classTypeCheckingExtension
- Parameters:
node
- a class node- Returns:
- false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the class.
-
afterMethodCall
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
afterMethodCall
in classTypeCheckingExtension
- Parameters:
call
- a method call, either aMethodCallExpression
,StaticMethodCallExpression
, orConstructorCallExpression
-
beforeMethodCall
Description copied from class:TypeCheckingExtension
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 withTypeCheckingMode.SKIP
.- Overrides:
beforeMethodCall
in classTypeCheckingExtension
- Parameters:
call
- a method call, either aMethodCallExpression
,StaticMethodCallExpression
, orConstructorCallExpression
- Returns:
- 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.
-
onMethodSelection
Description copied from class:TypeCheckingExtension
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.- Overrides:
onMethodSelection
in classTypeCheckingExtension
- Parameters:
expression
- the expression for which a corresponding method has been foundtarget
- the method which has been chosen by the type checker
-
setup
public void setup()Description copied from class:TypeCheckingExtension
Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.- Overrides:
setup
in classTypeCheckingExtension
-
finish
public void finish()Description copied from class:TypeCheckingExtension
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.- Overrides:
finish
in classTypeCheckingExtension
-