*/
def private generateSetters() '''
«FOR field : properties SEPARATOR '\n'»
- «val restrictions = field.returnType.restrictions»
- «IF restrictions != null»
- «IF !restrictions.rangeConstraints.nullOrEmpty»
- «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
- «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
+ «/* FIXME: generate checkers as simple blocks and embed them directly in setters */»
+ «val restrictions = field.returnType.restrictions»
+ «IF !(field.returnType instanceof GeneratedType) && restrictions != null»
+ «IF !restrictions.rangeConstraints.nullOrEmpty»
+ «val rangeGenerator = AbstractRangeGenerator.forType(field.returnType)»
+ «rangeGenerator.generateRangeChecker(field.name.toFirstUpper, restrictions.rangeConstraints)»
- «ENDIF»
- «IF !restrictions.lengthConstraints.nullOrEmpty»
+ «ENDIF»
+ «IF !restrictions.lengthConstraints.nullOrEmpty»
«LengthGenerator.generateLengthChecker(field.fieldName.toString, field.returnType, restrictions.lengthConstraints)»
- «ENDIF»
+ «ENDIF»
«ENDIF»
public «type.name»«BUILDER» set«field.name.toFirstUpper»(final «field.returnType.importedName» value) {
+ «IF !(field.returnType instanceof GeneratedType) && restrictions != null»
«IF restrictions != null && (!restrictions.rangeConstraints.nullOrEmpty || !restrictions.lengthConstraints.nullOrEmpty)»
if (value != null) {
«IF !restrictions.rangeConstraints.nullOrEmpty»
«ENDIF»
}
«ENDIF»
+ «ENDIF»
this.«field.fieldName» = value;
return this;
}
«IF !(properties === null)»
@Override
public «String.importedName» toString() {
- «StringBuilder.importedName» builder = new «StringBuilder.importedName» ("«type.name» [");
- boolean first = true;
-
- «FOR property : properties»
+ «String.importedName» name = "«type.name» [";
+ «StringBuilder.importedName» builder = new «StringBuilder.importedName» (name);
+ «FOR property : properties SEPARATOR "\n builder.append(\", \");\n}" AFTER " }\n"»
if («property.fieldName» != null) {
- if (first) {
- first = false;
- } else {
- builder.append(", ");
- }
builder.append("«property.fieldName»=");
«IF property.returnType.name.contains("[")»
builder.append(«Arrays.importedName».toString(«property.fieldName»));
«ELSE»
builder.append(«property.fieldName»);
«ENDIF»
- }
«ENDFOR»
«IF augmentField != null»
- if (first) {
- first = false;
- } else {
+ «IF !properties.empty»
+ «««Append comma separator only if it's not there already from previous operation»»»
+final int builderLength = builder.length();
+ final int builderAdditionalLength = builder.substring(name.length(), builderLength).length();
+ if (builderAdditionalLength > 2 && !builder.substring(builderLength - 2, builderLength).equals(", ")) {
builder.append(", ");
}
+ «ENDIF»
builder.append("«augmentField.name»=");
- builder.append(«augmentField.name».values());
+ builder.append(«augmentField.name».values());«"\n"»
+ return builder.append(']').toString();
+ «ELSE»
+ «IF properties.empty»
+ return builder.append(']').toString();
+ «ELSE»
+ return builder.append(']').toString();
+ «ENDIF»
«ENDIF»
- return builder.append(']').toString();
}
«ENDIF»
'''