Skip to content

Commit

Permalink
fix JavaPoet formating (#4583)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin committed Dec 16, 2022
1 parent 76f7f70 commit 4f4ed66
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 16 deletions.
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
Expand All @@ -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())
Expand Down
Expand Up @@ -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())
Expand Down
Expand Up @@ -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")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion libraries/apollo-compiler/src/test/graphql/schema.sdl
Expand Up @@ -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"""
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler-hooks/build.gradle.kts
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 4f4ed66

Please sign in to comment.