Top Description Inners Methods
groovy.lang

public @Interface DelegatesTo

extends Annotation
Annotations
@Documented
@Retention:RUNTIME
@Target:PARAMETER
Imports
java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target

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 (groovy.transform.TypeChecked) which would not report errors then if the delegate is of the documented type. Of course, it is also compatible with groovy.transform.CompileStatic.

Example:

// Document the fact that the delegate of the closure will be an ExecSpec
ExecResult exec(@DelegatesTo(ExecSpec) Closure closure) { ... }
Since
2.1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static @interface
DelegatesTo.Target

Parameter annotation used to specify the delegate for a @DelegatesTo annotated parameter of the same method.

Method Summary

Modifier and TypeMethod and Description
public int
genericTypeIndex()

The index of the generic type that will be the type of the closure's delegate.

public int
strategy()

The Closure#resolveStrategy used by the closure.

public String
target()

In cases when there are multiple @DelegatesTo.Target annotated parameters, this member should be set to the DelegatesTo.Target#value() of the correct target.

public String

Returns:

a String representation of a type
type
()

The type member should be used when the type of the delegate cannot be represented with value(), genericTypeIndex() or target().

public Class<T>
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

genericTypeIndexback to summary
public int genericTypeIndex()

The index of the generic type that will be the type of the closure's delegate. The generic types are considered with respect to the @DelegatesTo.Target annotated parameter for this usage, with the index starting at 0.

strategyback to summary
public int strategy()

The Closure#resolveStrategy used by the closure.

targetback to summary
public String target()

In cases when there are multiple @DelegatesTo.Target annotated parameters, this member should be set to the DelegatesTo.Target#value() of the correct target.

typeback to summary
public String type()

The type member should be used when the type of the delegate cannot be represented with value(), genericTypeIndex() or target(). 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:String

a String representation of a type

Since
2.4.0
valueback to summary
public Class<T> value()
groovy.lang back to summary

public @Interface DelegatesTo.Target

extends Annotation
Annotations
@Retention:RUNTIME
@Target:PARAMETER

Parameter annotation used to specify the delegate for a @DelegatesTo annotated parameter of the same method.

Method Summary

Modifier and TypeMethod and Description
public String
value()

An identifier that should be used to disambiguate targets when there are multiple @DelegatesTo.Target annotated parameters.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()

An identifier that should be used to disambiguate targets when there are multiple @DelegatesTo.Target annotated parameters.