Package groovy.transform.stc
Class PickAnyArgumentHint
- java.lang.Object
-
- groovy.transform.stc.ClosureSignatureHint
-
- groovy.transform.stc.SingleSignatureClosureHint
-
- groovy.transform.stc.PickAnyArgumentHint
-
- Direct Known Subclasses:
FirstParam
,FirstParam.FirstGenericType
,FirstParam.SecondGenericType
,FirstParam.ThirdGenericType
,SecondParam
,SecondParam.FirstGenericType
,SecondParam.SecondGenericType
,SecondParam.ThirdGenericType
,ThirdParam
,ThirdParam.FirstGenericType
,ThirdParam.SecondGenericType
,ThirdParam.ThirdGenericType
public class PickAnyArgumentHint extends SingleSignatureClosureHint
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->
...}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
-
-
Constructor Summary
Constructors Constructor Description PickAnyArgumentHint()
Creates the an argument picker which extracts the type of the first parameter.PickAnyArgumentHint(int parameterIndex, int genericTypeIndex)
Creates a picker which will extract the parameterIndex-th parameter type, or its genericTypeIndex-th generic type genericTypeIndex is >=0.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClassNode[]
getParameterTypes(MethodNode node, String[] options, SourceUnit sourceUnit, CompilationUnit unit, ASTNode usage)
-
Methods inherited from class groovy.transform.stc.SingleSignatureClosureHint
getClosureSignatures
-
Methods inherited from class groovy.transform.stc.ClosureSignatureHint
findClassNode, pickGenericType, pickGenericType
-
-
-
-
Constructor Detail
-
PickAnyArgumentHint
public PickAnyArgumentHint()
Creates the an argument picker which extracts the type of the first parameter.
-
PickAnyArgumentHint
public PickAnyArgumentHint(int parameterIndex, int genericTypeIndex)
Creates a picker which will extract the parameterIndex-th parameter type, or its genericTypeIndex-th generic type genericTypeIndex is >=0.- Parameters:
parameterIndex
- the index of the parameter from which to extract the typegenericTypeIndex
- if >=0, then returns the corresponding generic type instead of the parameter type.
-
-
Method Detail
-
getParameterTypes
public ClassNode[] getParameterTypes(MethodNode node, String[] options, SourceUnit sourceUnit, CompilationUnit unit, ASTNode usage)
- Specified by:
getParameterTypes
in classSingleSignatureClosureHint
-
-