From 4f4ed66effab74b5bc2b581536c7fb6fc8ef0f9b Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Fri, 16 Dec 2022 10:10:47 +0100 Subject: [PATCH] fix JavaPoet formating (#4583) --- .../compiler/codegen/java/file/InputObjectBuilder.kt | 7 +++---- .../apollo3/compiler/codegen/java/file/SchemaBuilder.kt | 2 +- .../compiler/codegen/java/helpers/BuilderBuilder.kt | 4 +++- .../input_object_type/type/ColorInput.java.expected | 2 +- .../input_object_type/type/ColorInput.kt.expected | 2 +- .../mutation_create_review/type/ColorInput.java.expected | 2 +- .../mutation_create_review/type/ColorInput.kt.expected | 2 +- .../type/ColorInput.java.expected | 2 +- .../type/ColorInput.kt.expected | 2 +- libraries/apollo-compiler/src/test/graphql/schema.sdl | 4 +++- tests/compiler-hooks/build.gradle.kts | 6 +++--- 11 files changed, 19 insertions(+), 16 deletions(-) diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt index c1880e148b9..d8a0aedca20 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/InputObjectBuilder.kt @@ -7,6 +7,7 @@ import com.apollographql.apollo3.compiler.codegen.java.JavaContext import com.apollographql.apollo3.compiler.codegen.java.L import com.apollographql.apollo3.compiler.codegen.java.helpers.BuilderBuilder import com.apollographql.apollo3.compiler.codegen.java.helpers.makeDataClassFromParameters +import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeAddDescription import com.apollographql.apollo3.compiler.codegen.java.helpers.toNamedType import com.apollographql.apollo3.compiler.codegen.java.helpers.toParameterSpec import com.apollographql.apollo3.compiler.ir.IrInputObject @@ -40,7 +41,7 @@ internal class InputObjectBuilder( TypeSpec .classBuilder(simpleName) .addModifiers(Modifier.PUBLIC) - .applyIf(description?.isNotBlank() == true) { addJavadoc("$L\n", description!!) } + .maybeAddDescription(description) .makeDataClassFromParameters(fields.map { it.toNamedType().toParameterSpec(context) }) @@ -54,9 +55,7 @@ internal class InputObjectBuilder( } else { val builderFields = inputObject.fields.map { FieldSpec.builder(context.resolver.resolveIrType(it.type).withoutAnnotations(), context.layout.propertyName(it.name)) - .applyIf(!it.description.isNullOrBlank()) { - addJavadoc(it.description) - } + .maybeAddDescription(it.description) .build() } return addMethod(BuilderBuilder.builderFactoryMethod()) diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/SchemaBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/SchemaBuilder.kt index 63e886490ab..e4669b0b2aa 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/SchemaBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/file/SchemaBuilder.kt @@ -66,7 +66,7 @@ internal class SchemaBuilder( private fun typeSpec(): TypeSpec { return TypeSpec.classBuilder(generatedSchemaName) - .addJavadoc("A Schema object containing all the composite types and a possibleTypes helper function") + .addJavadoc(L, "A Schema object containing all the composite types and a possibleTypes helper function") .addModifiers(Modifier.PUBLIC) .addField(customScalarAdaptersFieldSpec()) .addField(typesFieldSpec()) diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/BuilderBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/BuilderBuilder.kt index ae2a47c94b4..f3a540ab985 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/BuilderBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/BuilderBuilder.kt @@ -59,7 +59,9 @@ internal class BuilderBuilder( } .build() ) - .addJavadoc(field.javadoc) + .applyIf(!field.javadoc.isEmpty) { + addJavadoc(L, field.javadoc) + } .returns(JavaClassNames.Builder) .addStatement("this.$L = $L", field.name, context.wrapValueInOptional(value = CodeBlock.of(L, field.name), fieldType = field.type)) .addStatement("return this") diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected index b24e47ad584..6fd8d630155 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/ColorInput.java.expected @@ -110,7 +110,7 @@ public class ColorInput { } /** - * Red color + * A description with a dollar sign: $10 */ public Builder red(Integer red) { this.red = Optional.present(red); diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/ColorInput.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/ColorInput.kt.expected index 6156ef9f7ed..86f7e261777 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/ColorInput.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/ColorInput.kt.expected @@ -14,7 +14,7 @@ import kotlin.Int */ public data class ColorInput( /** - * Red color + * A description with a dollar sign: $10 */ public val red: Optional = Optional.Absent, /** diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected index b5bc4ef54ce..1921b9a8347 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/ColorInput.java.expected @@ -110,7 +110,7 @@ public class ColorInput { } /** - * Red color + * A description with a dollar sign: $10 */ public Builder red(Integer red) { this.red = Optional.present(red); diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/ColorInput.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/ColorInput.kt.expected index f202cc24e30..b1ca71a62d9 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/ColorInput.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/ColorInput.kt.expected @@ -14,7 +14,7 @@ import kotlin.Int */ internal data class ColorInput( /** - * Red color + * A description with a dollar sign: $10 */ public val red: Optional = Optional.Absent, /** diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected index 8701a168709..8d5d3bbc974 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/ColorInput.java.expected @@ -110,7 +110,7 @@ public class ColorInput { } /** - * Red color + * A description with a dollar sign: $10 */ public Builder red(Integer red) { this.red = Optional.present(red); diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/ColorInput.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/ColorInput.kt.expected index 74c3e6be41d..a2baa226ec8 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/ColorInput.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/ColorInput.kt.expected @@ -14,7 +14,7 @@ import kotlin.Int */ public data class ColorInput( /** - * Red color + * A description with a dollar sign: $10 */ public val red: Optional = Optional.Absent, /** diff --git a/libraries/apollo-compiler/src/test/graphql/schema.sdl b/libraries/apollo-compiler/src/test/graphql/schema.sdl index 67bb1644eb8..89de6479612 100644 --- a/libraries/apollo-compiler/src/test/graphql/schema.sdl +++ b/libraries/apollo-compiler/src/test/graphql/schema.sdl @@ -60,7 +60,9 @@ interface Character { """The input object sent when passing in a color""" input colorInput { - """Red color""" + """ + A description with a dollar sign: $10 + """ red: Int! = 1 """Green color""" diff --git a/tests/compiler-hooks/build.gradle.kts b/tests/compiler-hooks/build.gradle.kts index a592bfbd597..5895c47f4b9 100644 --- a/tests/compiler-hooks/build.gradle.kts +++ b/tests/compiler-hooks/build.gradle.kts @@ -251,7 +251,7 @@ class PrefixNamesJavaHooks(private val prefix: String) : DefaultApolloCompilerJa return when (kind) { com.squareup.javapoet.TypeSpec.Kind.CLASS -> { com.squareup.javapoet.TypeSpec.classBuilder(name) - .addJavadoc(javadoc) + .addJavadoc("\$L", javadoc) .addAnnotations(annotations) .addModifiers(*modifiers.toTypedArray()) .addTypeVariables(typeVariables) @@ -267,7 +267,7 @@ class PrefixNamesJavaHooks(private val prefix: String) : DefaultApolloCompilerJa com.squareup.javapoet.TypeSpec.Kind.ENUM -> { com.squareup.javapoet.TypeSpec.enumBuilder(name) - .addJavadoc(javadoc) + .addJavadoc("\$L", javadoc) .addAnnotations(annotations) .addModifiers(*modifiers.toTypedArray()) .addTypeVariables(typeVariables) @@ -284,7 +284,7 @@ class PrefixNamesJavaHooks(private val prefix: String) : DefaultApolloCompilerJa com.squareup.javapoet.TypeSpec.Kind.INTERFACE -> { com.squareup.javapoet.TypeSpec.interfaceBuilder(name) - .addJavadoc(javadoc) + .addJavadoc("\$L", javadoc) .addAnnotations(annotations) .addModifiers(*modifiers.toTypedArray()) .addTypeVariables(typeVariables)