Groovy 2.2.1

groovy.transform
[Java] Annotation Type TupleConstructor

java.lang.Object
  groovy.transform.TupleConstructor

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@GroovyASTTransformationClass("org.codehaus.groovy.transform.TupleConstructorASTTransformation")
public @interface TupleConstructor

Class annotation used to assist in the creation of tuple constructors in classes.

It allows you to write classes in this shortened form:

 @TupleConstructor class Customer {
     String first, last
     int age
     Date since
     Collection favItems
 }
 def c1 = new Customer(first:'Tom', last:'Jones', age:21, since:new Date(), favItems:['Books', 'Games'])
 def c2 = new Customer('Tom', 'Jones', 21, new Date(), ['Books', 'Games'])
 def c3 = new Customer('Tom', 'Jones')
 
The @TupleConstructor annotation instructs the compiler to execute an AST transformation which adds the necessary constructor method to your class.

A tuple constructor is created with a parameter for each property (and optionally field and super properties). A default value is provided (using Java's default values) for all parameters in the constructor. Groovy's normal conventions then allows any number of parameters to be left off the end of the parameter list including all of the parameters - giving a no-arg constructor which can be used with the map-style naming conventions.

The order of parameters is given by the properties of any super classes with most super first (if includeSuperProperties is set) followed by the properties of the class followed by the fields of the class (if includeFields is set). Within each grouping the order is as attributes appear within the respective class.

Limitations:

Authors:
Paul King
Since:
1.8.0


 
Optional Element Summary
boolean callSuper

Should super properties be called within a call to the parent constructor.

java.lang.String excludes

List of field and/or property names to exclude from the constructor.

boolean force

By default, this annotation becomes a no-op if you provide your own constructor.

boolean includeFields

Include fields in the constructor.

boolean includeProperties

Include properties in the constructor.

boolean includeSuperFields

Include fields from super classes in the constructor.

boolean includeSuperProperties

Include properties from super classes in the constructor.

java.lang.String includes

List of field and/or property names to include within the constructor.

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

Element Detail

callSuper

public boolean callSuper
Should super properties be called within a call to the parent constructor. rather than set as properties @default false


excludes

public String[] excludes
List of field and/or property names to exclude from the constructor. Must not be used if 'includes' is used. For convenience, a String with comma separated names can be used in addition to an array (using Groovy's literal list notation) of String values. @default {}


force

public boolean force
By default, this annotation becomes a no-op if you provide your own constructor. By setting force=true then the tuple constructor(s) will be added regardless of whether existing constructors exist. It is up to you to avoid creating duplicate constructors. @default false


includeFields

public boolean includeFields
Include fields in the constructor. @default false


includeProperties

public boolean includeProperties
Include properties in the constructor. @default true


includeSuperFields

public boolean includeSuperFields
Include fields from super classes in the constructor. @default false


includeSuperProperties

public boolean includeSuperProperties
Include properties from super classes in the constructor. @default false


includes

public String[] includes
List of field and/or property names to include within the constructor. Must not be used if 'excludes' is used. For convenience, a String with comma separated names can be used in addition to an array (using Groovy's literal list notation) of String values. @default {}


 

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