Package groovy.lang
Annotation Type DelegatesTo
-
@Documented @Retention(RUNTIME) @Target(PARAMETER) public @interface DelegatesTo
This annotation can be used by API or DSL writers to document parameters which accept a closure. In that case, using this annotation, you can specify what the delegate type of the closure will be. This is important for IDE support.This annotation can also be used to help the type checker (
TypeChecked
) which would not report errors then if the delegate is of the documented type. Of course, it is also compatible withCompileStatic
.Example:
// Document the fact that the delegate of the closure will be an ExecSpec ExecResult exec(@DelegatesTo(ExecSpec) Closure closure) { ... }
- Since:
- 2.1.0
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description int
genericTypeIndex
The index of the generic type that will be the type of the closure's delegate.int
strategy
TheClosure.resolveStrategy
used by the closure.String
target
In cases when there are multiple@DelegatesTo.Target
annotated parameters, this member should be set to theDelegatesTo.Target.value()
of the correct target.String
type
The type member should be used when the type of the delegate cannot be represented withvalue()
,genericTypeIndex()
ortarget()
.Class
value
-
-
-
Element Detail
-
value
Class value
- Default:
- groovy.lang.DelegatesTo.Target.class
-
-
-
strategy
int strategy
TheClosure.resolveStrategy
used by the closure.- Default:
- 0
-
-
-
target
String target
In cases when there are multiple@DelegatesTo.Target
annotated parameters, this member should be set to theDelegatesTo.Target.value()
of the correct target.- Default:
- ""
-
-
-
type
String type
The type member should be used when the type of the delegate cannot be represented withvalue()
,genericTypeIndex()
ortarget()
. In this case, it is possible to use a String to represent the type, at the cost of potential uncaught errors at compile time if the type is invalid and increased compile time.- Returns:
- a String representation of a type
- Since:
- 2.4.0
- Default:
- ""
-
-