Groovy 2.2.1

groovy.transform
[Java] Annotation Type AnnotationCollector

java.lang.Object
  groovy.transform.AnnotationCollector

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
public @interface AnnotationCollector

The AnnotationCollector can be used to define aliases for groups of annotations. The Alias needs to be a class or annotation annotated with AnnotationCollector, otherwise nothing is required. The alias will be replaced on the AST level and will never appear in later. Any members of the class or annotation will be ignored, but could be used by a custom processor. Annotation arguments are mapped to the aliased annotations if existing. Should the default processor not be able to map one of the arguments and error will be given. Is this not wished or if you want a different mapping a custom processor has to be used. There are two ways of using the alias. The first way is by providing the annotations as list/array:

          import groovy.transform.*
          @AnnotationCollector([ToString, EqualsAndHashCode, Immutable])
          @interface Alias {}
          @Alias(excludes=["a"])
          class Foo {
              Integer a, b
          }
          assert Foo.class.annotations.size()==3 
          assert new Foo(1,2).toString() == "Foo(2)"
 
In the example above we have Alias as the alias annotation and an argument excludes which will be mapped to ToString and EqualsAndHashCode. Immutable doesn't have excludes, thus nothing will be done there.
The other way is to add annotations to the alias:
 import groovy.transform.*
 @ToString(excludes=["a"])
 @EqualsAndHashCode
 @Immutable
 @AnnotationCollector
 @interface Alias {}

 @Alias
 class Foo {
     Integer a, b
 }
 assert Foo.class.annotations.size()==3
 assert new Foo(1,2).toString() == "Foo(2)"
 
In the example above we have again Alias as the alias annotation, but this time the argument is part of the alias. Instead of mapping excludes to ToString as well as EqualsAndHashCode, only ToString will have the excludes. Again the alias can have an argument excludes, which would overwrite the excludes given in from the definition and be mapped to ToString as well as EqualsAndHashCode. If both ways are combined, then the list overwrites annotation usage. NOTE: The aliasing does not support aliasing of aliased annotations.
Authors:
Jochen "blackdrag" Theodorou
See Also:
AnnotationCollectorTransform


 
Optional Element Summary
java.lang.String processor

Processor used for computing custom logic or the list of annotations, or both.

java.lang.Class value

List of aliased annotations.

 
Method Summary
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Element Detail

processor

public String processor
Processor used for computing custom logic or the list of annotations, or both. The default is org.codehaus.groovy.transform.AnnotationCollectorTransform. Custom processors need to extend that class. @default "org.codehaus.groovy.transform.AnnotationCollectorTransform"


value

public Class[] value
List of aliased annotations. @default {}


 

Copyright © 2003-2013 The Codehaus. All rights reserved.