A closure signature hint class is always used in conjunction with the {@link ClosureParams} annotation. It iscalled at compile time (or may be used by IDEs) to infer the types of the parameters of a {@link groovy.lang.Closure}.
A closure hint class is responsible for generating the list of arguments that a closure accepts. Since closures may accept several signatures, {@link #getClosureSignatures(org.codehaus.groovy.ast.MethodNode,org.codehaus.groovy.control.SourceUnit,org.codehaus.groovy.control.CompilationUnit,String[],org.codehaus.groovy.ast.ASTNode)} shouldreturn a list.
Whenever the type checker encounters a method call that targets a method accepting a closure, it will search for the {@link ClosureParams} annotation on the {@link groovy.lang.Closure} argument. If it is found, then itcreates an instance of the hint class and calls the {@link #getClosureSignatures(org.codehaus.groovy.ast.MethodNode,org.codehaus.groovy.control.SourceUnit,org.codehaus.groovy.control.CompilationUnit,String[],org.codehaus.groovy.ast.ASTNode)}method, which will in turn return the list of signatures.
Note that the signature concept here is used only to describe the parameter types, not the result type, which is found in the generic type argument of the {@link groovy.lang.Closure} class.
Several predefined hints can be found, which should cover most of the use cases.
@author Cédric Champeau @since 2.3.0
|
|