@@ -126,7 +126,7 @@ class BuilderProcessor : AbstractProcessor() {
126126 val code = StringBuilder ()
127127 fields.forEach { field ->
128128 if (getterFieldNames.contains(field.simpleName.toString())) {
129- code.append(" this.${field.simpleName} = $source .${field.simpleName} " )
129+ code.append(" this.${field.simpleName} ·=· $source .${field.simpleName} " )
130130 .appendln()
131131 }
132132 }
@@ -149,11 +149,11 @@ class BuilderProcessor : AbstractProcessor() {
149149 /* * Creates a 'build()' function that will invoke a constructor for [returnType], passing [fields] as arguments and returning the new instance. */
150150 private fun createBuildFunction (fields : List <Element >, returnType : TypeElement ): FunSpec {
151151 val code = StringBuilder (" $CHECK_REQUIRED_FIELDS_FUNCTION_NAME ()" )
152- code.appendln().append(" return ${returnType.simpleName} (" )
152+ code.appendln().append(" return· ${returnType.simpleName} (" )
153153 val iterator = fields.listIterator()
154154 while (iterator.hasNext()) {
155155 val field = iterator.next()
156- code.appendln().append(" ${field.simpleName} = ${field.simpleName} " )
156+ code.appendln().append(" ${field.simpleName} ·=· ${field.simpleName} " )
157157 if (! field.isNullable()) {
158158 code.append(" !!" )
159159 }
@@ -174,7 +174,7 @@ class BuilderProcessor : AbstractProcessor() {
174174 val code = StringBuilder ()
175175 fields.filterNot { it.isNullable() }
176176 .forEach { field ->
177- code.append(" check(${field.simpleName} != null, {\" ${field.simpleName} must not be null\" })" ).appendln()
177+ code.append(" check(${field.simpleName} ·!=· null, {\" ${field.simpleName} · must· not·be· null\" })" ).appendln()
178178 }
179179
180180 return FunSpec .builder(CHECK_REQUIRED_FIELDS_FUNCTION_NAME )
@@ -185,7 +185,8 @@ class BuilderProcessor : AbstractProcessor() {
185185
186186 /* * Creates a property for the field identified by this element. */
187187 private fun Element.asProperty (): PropertySpec =
188- PropertySpec .varBuilder(simpleName.toString(), asKotlinTypeName().asNullable(), KModifier .PRIVATE )
188+ PropertySpec .builder(simpleName.toString(), asKotlinTypeName().copy(nullable = true ), KModifier .PRIVATE )
189+ .mutable()
189190 .initializer(defaultValue())
190191 .build()
191192
@@ -208,14 +209,14 @@ class BuilderProcessor : AbstractProcessor() {
208209 private fun Element.asSetterFunctionReturning (builder : ClassName ): FunSpec {
209210 val fieldType = asKotlinTypeName()
210211 val parameterClass = if (isNullable()) {
211- fieldType.asNullable( )
212+ fieldType.copy(nullable = true )
212213 } else {
213214 fieldType
214215 }
215216 return FunSpec .builder(simpleName.toString())
216217 .addParameter(ParameterSpec .builder(" value" , parameterClass).build())
217218 .returns(builder)
218- .addCode(" return apply { $simpleName = value }\n " )
219+ .addCode(" return apply· { $simpleName ·=· value }\n " )
219220 .build()
220221 }
221222
@@ -245,7 +246,7 @@ class BuilderProcessor : AbstractProcessor() {
245246 * @throws NoSuchElementException if [this.typeArguments] is empty.
246247 */
247248 private fun ParameterizedTypeName.withNullableType (): ParameterizedTypeName {
248- val lastType = this .typeArguments.last().asNullable( )
249+ val lastType = this .typeArguments.last().copy(nullable = true )
249250 val typeArguments = ArrayList <TypeName >()
250251 typeArguments.addAll(this .typeArguments.dropLast(1 ))
251252 typeArguments.add(lastType)
@@ -261,9 +262,9 @@ class BuilderProcessor : AbstractProcessor() {
261262 private fun ParameterizedTypeName.asMutableCollection (): ParameterizedTypeName {
262263 val mutable = MUTABLE_COLLECTIONS [rawType]!!
263264 .parameterizedBy(* this .typeArguments.toTypedArray())
264- .annotated( this .annotations)
265- return if (nullable ) {
266- mutable.asNullable( )
265+ .copy(annotations = this .annotations)
266+ return if (isNullable ) {
267+ mutable.copy(nullable = true )
267268 } else {
268269 mutable
269270 }
0 commit comments