Top Description Fields Constructors Methods
groovy.transform.stc

public Class PickAnyArgumentHint

extends SingleSignatureClosureHint
Class Inheritance
Known Direct Subclasses
groovy.transform.stc.SecondParam, groovy.transform.stc.SecondParam.FirstGenericType, groovy.transform.stc.SecondParam.SecondGenericType, groovy.transform.stc.SecondParam.ThirdGenericType, groovy.transform.stc.ThirdParam, groovy.transform.stc.ThirdParam.FirstGenericType, groovy.transform.stc.ThirdParam.SecondGenericType, groovy.transform.stc.ThirdParam.ThirdGenericType, groovy.transform.stc.FirstParam, groovy.transform.stc.FirstParam.FirstGenericType, groovy.transform.stc.FirstParam.SecondGenericType, groovy.transform.stc.FirstParam.ThirdGenericType
Imports
org.codehaus.groovy.ast.ASTNode, .ClassNode, .MethodNode, org.codehaus.groovy.control.CompilationUnit, .SourceUnit

Base class for hints which use the type of a parameter of the annotated method as the signature. This can optionally use a generic type of the selected parameter as the hint. For example, imagine the following method:

void foo(A firstArg, B secondArg, Closure c) {...}

If the c closure should be { B it -> ...}, then we can see that the parameter type should be picked from the second parameter of the foo method, which is what groovy.transform.stc.PickAnyArgumentHint lets you do.

Alternatively, the method may look like this:

void <T> foo(A<T> firstArg, B secondArg, Closure c) {...}

in which case if you want to express the fact that c should accept a <T> then you can use the genericTypeIndex value.

This class is extended by several hint providers that make it easier to use as annotation values.

Since
2.3.0

Field Summary

Modifier and TypeField and Description
private final int
private final int

Constructor Summary

AccessConstructor and Description
public
PickAnyArgumentHint()

Creates the an argument picker which extracts the type of the first parameter.

public
PickAnyArgumentHint(final int
the index of the parameter from which to extract the type
parameterIndex
,
final int
if >=0, then returns the corresponding generic type instead of the parameter type.
genericTypeIndex
)

Creates a picker which will extract the parameterIndex-th parameter type, or its genericTypeIndex-th generic type genericTypeIndex is >=0.

Method Summary

Modifier and TypeMethod and Description
public ClassNode[]
getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage)

Implements abstract groovy.transform.stc.SingleSignatureClosureHint.getParameterTypes.

Inherited from groovy.transform.stc.SingleSignatureClosureHint:
getClosureSignatures

Field Detail

genericTypeIndexback to summary
private final int genericTypeIndex
parameterIndexback to summary
private final int parameterIndex

Constructor Detail

PickAnyArgumentHintback to summary
public PickAnyArgumentHint()

Creates the an argument picker which extracts the type of the first parameter.

PickAnyArgumentHintback to summary
public PickAnyArgumentHint(final int parameterIndex, final int genericTypeIndex)

Creates a picker which will extract the parameterIndex-th parameter type, or its genericTypeIndex-th generic type genericTypeIndex is >=0.

Parameters
parameterIndex:int

the index of the parameter from which to extract the type

genericTypeIndex:int

if >=0, then returns the corresponding generic type instead of the parameter type.

Method Detail

getParameterTypesback to summary
public ClassNode[] getParameterTypes(final MethodNode node, final String[] options, final SourceUnit sourceUnit, final CompilationUnit unit, final ASTNode usage)

Implements abstract groovy.transform.stc.SingleSignatureClosureHint.getParameterTypes.

Annotations
@Override