Groovy Documentation

groovy.lang
[Java] Annotation Type DelegatesTo

java.lang.Object
  groovy.lang.DelegatesTo

@java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
@java.lang.annotation.Target({ElementType.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 with CompileStatic.

Example:

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


Nested Class Summary
static @interface DelegatesTo.Target

   
Optional Element Summary
int strategy

@default Closure.OWNER_FIRST

java.lang.String target

@default ""

java.lang.Class value

@default Target.class

 
Method Summary
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Element Detail

strategy

public int strategy
@default Closure.OWNER_FIRST


target

public java.lang.String target
@default ""


value

public java.lang.Class value
@default Target.class


 

Groovy Documentation