public abstract class SingleSignatureClosureHint
extends ClosureSignatureHint
A simplified version of a ClosureSignatureHint which is suitable for monomorphic closures, that is to say closures which only respond to a single signature.
| Type Params | Return Type | Name and description |
|---|---|---|
|
public List<ClassNode> |
getClosureSignatures(MethodNode node, SourceUnit sourceUnit, CompilationUnit compilationUnit, String[] options, ASTNode usage)* Subclasses should implement this method, which returns the list of accepted closure signatures. * *The compiler will call this method each time, in a source file, a method call using a closure * literal is encountered and that the target method has the corresponding Closure parameter * annotated with ClosureParams. So imagine the following code needs to be compiled: * *@groovy.transform.TypeChecked
* void doSomething() {
* println ['a','b'].collect { it.toUpperCase() }
* }
*
* The collect method accepts a closure, but normally, the type checker doesn't have enough type information * in the sole DefaultGroovyMethods.collect method * signature to infer the type of it. With the annotation, it will now try to find an annotation on the closure parameter. * If it finds it, then an instance of the hint class is created and the type checker calls it with the following arguments: *
Now, the hint instance can return the list of expected parameters. Here, it would have to say that the collect method accepts * a closure for which the only argument is of the type of the first generic type of the first argument. *With that type information, the type checker can now infer that the type of it is String, because the first argument (here the receiver of the collect method) * is a List<String> * * * *Subclasses are therefore expected to return the signatures according to the available context, which is only the target method and the potential options. * * *
|
|
public abstract ClassNode[] |
getParameterTypes(MethodNode node, String[] options, SourceUnit sourceUnit, CompilationUnit unit, ASTNode usage)Returns the single parameter signature accepted by the hinted closure. |
| Methods inherited from class | Name |
|---|---|
class ClosureSignatureHint |
findClassNode, getClosureSignatures, pickGenericType, pickGenericType |
*
Subclasses should implement this method, which returns the list of accepted closure signatures.
* *The compiler will call this method each time, in a source file, a method call using a closure * literal is encountered and that the target method has the corresponding Closure parameter * annotated with ClosureParams. So imagine the following code needs to be compiled:
* *@groovy.transform.TypeChecked
* void doSomething() {
* println ['a','b'].collect { it.toUpperCase() }
* }
*
* The collect method accepts a closure, but normally, the type checker doesn't have enough type information * in the sole DefaultGroovyMethods.collect method * signature to infer the type of it. With the annotation, it will now try to find an annotation on the closure parameter. * If it finds it, then an instance of the hint class is created and the type checker calls it with the following arguments:
*Now, the hint instance can return the list of expected parameters. Here, it would have to say that the collect method accepts * a closure for which the only argument is of the type of the first generic type of the first argument.
*With that type information, the type checker can now infer that the type of it is String, because the first argument (here the receiver of the collect method) * is a List<String>
* * * *Subclasses are therefore expected to return the signatures according to the available context, which is only the target method and the potential options.
* * *node - the method node for which a Closure parameter was annotated with
* ClosureParams
*sourceUnit - the source unit of the file being compiled
*compilationUnit - the compilation unit of the file being compiled
*options - the options, corresponding to the ClosureParams.options found on the annotationusage - the AST node, in the compiled file, which triggered a call to this method. Normally only used for logging/error handlingReturns the single parameter signature accepted by the hinted closure.
node - the annotated method nodeoptions - the hint optionssourceUnit - the current source unitunit - the current compilation unitusage - the closure expression or related AST node