Top Description Fields Constructors Methods
groovy.transform.builder

public Class ExternalStrategy

extends AbstractBuilderStrategy
Class Inheritance
Imports
groovy.transform.Undefined, org.codehaus.groovy.ast.AnnotatedNode, .AnnotationNode, .ClassNode, .FieldNode, .MethodNode, org.codehaus.groovy.ast.expr.Expression, org.codehaus.groovy.ast.stmt.BlockStatement, org.codehaus.groovy.transform.BuilderASTTransformation, java.util.ArrayList, .List

This strategy is used with the Builder AST transform to populate a builder helper class so that it can be used for the fluent creation of instances of a specified class. The specified class is not modified in any way and may be a Java class. You use it by creating and annotating an explicit builder class which will be filled in by during annotation processing with the appropriate build method and setters. An example is shown here:
import groovy.transform.builder.*

class Person {
    String firstName
    String lastName
}

@Builder(builderStrategy=ExternalStrategy, forClass=Person)
class PersonBuilder { }

def person = new PersonBuilder().firstName("Robert").lastName("Lewandowski").build()
assert person.firstName == "Robert"
assert person.lastName == "Lewandowski"
The prefix annotation attribute, which defaults to the empty String for this strategy, can be used to create setters with a different naming convention, e.g. with the prefix changed to 'set', you would use your setters as follows:
def p1 = new PersonBuilder().setFirstName("Robert").setLastName("Lewandowski").setAge(21).build()
or using a prefix of 'with':
def p2 = new PersonBuilder().withFirstName("Robert").withLastName("Lewandowski").withAge(21).build()
The properties to use can be filtered using either the 'includes' or 'excludes' annotation attributes for @Builder. The @Builder 'buildMethodName' annotation attribute can be used for configuring the build method's name, default "build". The @Builder 'builderMethodName' and 'builderClassName' annotation attributes aren't applicable for this strategy. The @Builder 'useSetters' annotation attribute is ignored by this strategy which always uses setters.

Field Summary

Modifier and TypeField and Description
private static final Expression

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
private MethodNode
private static MethodNode
private static FieldNode
private static Expression
Inherited from org.codehaus.groovy.transform.BuilderASTTransformation.AbstractBuilderStrategy:
checkKnownFieldcheckKnownPropertygetFieldsgetIncludeExcludegetPropertyInfoFromBeanInfogetPropertyInfoFromClassNodegetPropertyInfoFromClassNodegetPropertyInfoFromClassNodegetPropertyInfosgetSetterNameunsupportedAttributeunsupportedAttribute

Field Detail

DEFAULT_INITIAL_VALUEback to summary
private static final Expression DEFAULT_INITIAL_VALUE

Constructor Detail

ExternalStrategyback to summary
public ExternalStrategy()

Method Detail

buildback to summary
public void build(BuilderASTTransformation transform, AnnotatedNode annotatedNode, AnnotationNode anno)

Implements org.codehaus.groovy.transform.BuilderASTTransformation.BuilderStrategy.build.

createBuilderMethodForFieldback to summary
private MethodNode createBuilderMethodForField(ClassNode builderClass, BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo prop, String prefix)
createBuildMethodback to summary
private static MethodNode createBuildMethod(BuilderASTTransformation transform, AnnotationNode anno, ClassNode sourceClass, List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> fields)
createFieldCopyback to summary
private static FieldNode createFieldCopy(ClassNode builderClass, BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo prop)
initializeInstanceback to summary
private static Expression initializeInstance(ClassNode sourceClass, List<BuilderASTTransformation.AbstractBuilderStrategy.PropertyInfo> props, BlockStatement body)