genType
equals null
@@ -60,26 +64,33 @@ class BuilderTemplate extends AbstractBuilderTemplate {
* @return string with JAVA source code
*/
override body() '''
- «wrapToDocumentation(formatDataForJavaDoc(type))»
+ «wrapToDocumentation(formatDataForJavaDoc(targetType))»
+ «targetType.annotations.generateDeprecatedAnnotation»
public class «type.name» implements «Builder.importedName»<«targetType.importedName»> {
«generateFields(false)»
«constantsDeclarations()»
- «generateAugmentField(false)»
+ «IF augmentType !== null»
+ «generateAugmentField()»
+ «ENDIF»
«generateConstructorsFromIfcs()»
- «generateCopyConstructor(false, targetType, type.enclosedTypes.get(0))»
+ public «generateCopyConstructor(targetType, type.enclosedTypes.get(0))»
«generateMethodFieldsFrom()»
«generateGetters(false)»
+ «IF augmentType !== null»
+
+ «generateAugmentation()»
+ «ENDIF»
«generateSetters»
- @«Override.importedName»
+ @«OVERRIDE.importedName»
public «targetType.name» build() {
return new «type.enclosedTypes.get(0).importedName»(this);
}
@@ -88,6 +99,14 @@ class BuilderTemplate extends AbstractBuilderTemplate {
}
'''
+ override generateDeprecatedAnnotation(AnnotationType ann) {
+ val forRemoval = ann.getParameter("forRemoval")
+ if (forRemoval !== null) {
+ return "@" + DEPRECATED.importedName + "(forRemoval = " + forRemoval.value + ")"
+ }
+ return "@" + SUPPRESS_WARNINGS.importedName + "(\"deprecation\")"
+ }
+
/**
* Generate default constructor and constructor for every implemented interface from uses statements.
*/
@@ -106,7 +125,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
*/
def private Object generateConstructorFromIfc(Type impl) '''
«IF (impl instanceof GeneratedType)»
- «IF !(impl.methodDefinitions.empty)»
+ «IF impl.hasNonDefaultMethods»
public «type.name»(«impl.fullyQualifiedName» arg) {
«printConstructorPropertySetter(impl)»
}
@@ -120,8 +139,10 @@ class BuilderTemplate extends AbstractBuilderTemplate {
def private Object printConstructorPropertySetter(Type implementedIfc) '''
«IF (implementedIfc instanceof GeneratedType && !(implementedIfc instanceof GeneratedTransferObject))»
«val ifc = implementedIfc as GeneratedType»
- «FOR getter : ifc.methodDefinitions»
- this._«getter.propertyNameFromGetter» = arg.«getter.name»();
+ «FOR getter : ifc.nonDefaultMethods»
+ «IF BindingMapping.isGetterMethodName(getter.name)»
+ this._«getter.propertyNameFromGetter» = arg.«getter.name»();
+ «ENDIF»
«ENDFOR»
«FOR impl : ifc.implements»
«printConstructorPropertySetter(impl)»
@@ -142,7 +163,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
«FOR impl : targetType.getAllIfcs»
«generateIfCheck(impl, done)»
«ENDFOR»
- «CodeHelpers.importedName».validValue(isValidArg, arg, "«targetType.getAllIfcs.toListOfNames»");
+ «CODEHELPERS.importedName».validValue(isValidArg, arg, "«targetType.getAllIfcs.toListOfNames»");
}
«ENDIF»
«ENDIF»
@@ -168,7 +189,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
def boolean hasImplementsFromUses(GeneratedType type) {
var i = 0
for (impl : type.getAllIfcs) {
- if ((impl instanceof GeneratedType) && !((impl as GeneratedType).methodDefinitions.empty)) {
+ if (impl instanceof GeneratedType && (impl as GeneratedType).hasNonDefaultMethods) {
i = i + 1
}
}
@@ -176,7 +197,7 @@ class BuilderTemplate extends AbstractBuilderTemplate {
}
def private generateIfCheck(Type impl, List+ In general, this class is supposed to be used like this template: +
+
+ «target» createTarget(int fooXyzzy, int barBaz) {
+ return new «target»Builder()
+ .setFoo(new FooBuilder().setXyzzy(fooXyzzy).build())
+ .setBar(new BarBuilder().setBaz(barBaz).build())
+ .build();
+ }
+
+
+
+ + This pattern is supported by the immutable nature of «target», as instances can be freely passed around without + worrying about synchronization issues. + +
+ As a side note: method chaining results in: +