public class GroovyTypeCheckingExtensionSupport
extends AbstractTypeCheckingExtension
Base class for type checking extensions written in Groovy. Compared to its superclass, TypeCheckingExtension, this class adds a number of utility methods aimed at leveraging the syntax of the Groovy language to improve expressiveness and conciseness.
| Modifiers | Name | Description |
|---|---|---|
static class |
GroovyTypeCheckingExtensionSupport.TypeCheckingDSL |
Event handler registration:
|
| Fields inherited from class | Fields |
|---|---|
class AbstractTypeCheckingExtension |
context, debug, handled |
class TypeCheckingExtension |
typeCheckingVisitor |
| Constructor and description |
|---|
GroovyTypeCheckingExtensionSupport(StaticTypeCheckingVisitor typeCheckingVisitor, String scriptPath, CompilationUnit compilationUnit)Builds a type checking extension relying on a Groovy script (type checking DSL). |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
afterMethodCall(MethodCall call)* 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 * TypeCheckingMode.SKIP. *
|
|
public void |
afterVisitClass(ClassNode node)* 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 * TypeCheckingMode.SKIP. *
|
|
public void |
afterVisitMethod(MethodNode node)* 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 * TypeCheckingMode.SKIP. *
|
|
public boolean |
beforeMethodCall(MethodCall call)* 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 * TypeCheckingMode.SKIP. * *
|
|
public boolean |
beforeVisitClass(ClassNode node)* 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 * TypeCheckingMode.SKIP. *
|
|
public boolean |
beforeVisitMethod(MethodNode node)* 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 * TypeCheckingMode.SKIP. *
|
|
public boolean |
equals(Object that)Compares extensions by script specification and compilation unit. |
|
public void |
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. |
|
public Map<String, Object> |
getOptions()* Returns the options passed to this extension via the parameterized extension syntax, * e.g. @TypeChecked(extensions='my.Extension(key: value)').
*
*
|
|
public List<MethodNode> |
handleAmbiguousMethods(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. 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. * *
|
|
public 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. * Extensions may override this method to allow such assignments where the type checker normally disallows * them. * *
|
|
public boolean |
handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)* 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. * *
|
|
public List<MethodNode> |
handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)* 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. * * *
|
|
public 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). It gives the extension * a chance to resolve it. * *
|
|
public 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). It gives the extension * a chance to resolve it. * *
|
|
public boolean |
handleUnresolvedVariableExpression(VariableExpression vexp)* 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. * *
|
|
public int |
hashCode()Returns a hash code based on the script specification and compilation unit. |
|
public void |
onMethodSelection(Expression expression, MethodNode target)* 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. *
|
|
public void |
setDebug(boolean debug)Enables or disables debug logging for the backing extension. |
|
public void |
setup()* Subclasses should implement this method whenever they need to perform * special checks before the type checker starts working. |
Builds a type checking extension relying on a Groovy script (type checking DSL).
The scriptPath may include parameters in Groovy named-argument style, e.g.
"groovy.typecheckers.NullChecker(strict: true)".
typeCheckingVisitor - the type checking visitorscriptPath - the path to the type checking script (in classpath), optionally with parameters* 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 * TypeCheckingMode.SKIP. *
call - a method call, either a MethodCallExpression, StaticMethodCallExpression, or ConstructorCallExpression* 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 * TypeCheckingMode.SKIP. *
node - a class node* 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 * TypeCheckingMode.SKIP. *
node - a method node* 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 * TypeCheckingMode.SKIP. * *
call - a method call, either a MethodCallExpression, StaticMethodCallExpression, or ConstructorCallExpression
** 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 * TypeCheckingMode.SKIP. *
node - a class node
** 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 * TypeCheckingMode.SKIP. *
node - a method node
*Compares extensions by script specification and compilation unit.
* 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.
* Returns the options passed to this extension via the parameterized extension syntax,
* e.g. @TypeChecked(extensions='my.Extension(key: value)').
*
*
* 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. * *
nodes - the list of ambiguous methods
*origin - the expression which originated the method selection process
** 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. * *
lhsType - the type of the left hand side of the assignment, as found by the type checker
*rhsType - the type of the right hand side of the assignment, as found by the type checker
*assignmentExpression - the assignment expression which triggered this call
*boolean false if the extension does not handle this assignment, true otherwise* 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. * *
returnStatement - the statement that triggered the error
*inferredReturnType - the inferred return type for this statement
** 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. * * *
receiver - the type of the receiver
*name - the name of the called method
*argumentList - the list of arguments of the call
*argumentTypes - the types of the arguments of the call
*call - the method call itself, if needed
** 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. * *
aexp - the unresolved attribute
*boolean false if this extension doesn't resolve the attribute, true
* if it resolves the attribute.* 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. * *
pexp - the unresolved property
*boolean false if this extension doesn't resolve the property, true
* if it resolves the property.* 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. * *
vexp - the unresolved variable extension
*boolean false if the extension doesn't handle it,
* true if the extension handles this variable.Returns a hash code based on the script specification and compilation unit.
* 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. *
expression - the expression for which a corresponding method has been found
*target - the method which has been chosen by the type checkerEnables or disables debug logging for the backing extension.
* Subclasses should implement this method whenever they need to perform * special checks before the type checker starts working.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.