Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-breaking spaces after 'return' #4127

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.apollographql.apollo3.compiler.codegen.kotlin.adapter

import com.apollographql.apollo3.compiler.applyIf
import com.apollographql.apollo3.compiler.codegen.Identifier
import com.apollographql.apollo3.compiler.codegen.Identifier.__typename
import com.apollographql.apollo3.compiler.codegen.Identifier.customScalarAdapters
import com.apollographql.apollo3.compiler.codegen.Identifier.fromJson
Expand All @@ -17,7 +16,6 @@ import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec

class PolymorphicFieldResponseAdapterBuilder(
Expand Down Expand Up @@ -93,7 +91,7 @@ class PolymorphicFieldResponseAdapterBuilder(

builder.add(typenameFromReaderCodeBlock())

builder.beginControlFlow("return when($__typename) {")
builder.beginControlFlow("return·when($__typename) {")
implementations.sortedByDescending { it.typeSet.size }.forEach { model ->
if (!model.isFallback) {
model.possibleTypes.forEach { possibleType ->
Expand Down Expand Up @@ -137,4 +135,4 @@ class PolymorphicFieldResponseAdapterBuilder(

return builder.build()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class EnumAsEnumBuilder(
.addParameter("rawValue", String::
class)
.returns(ClassName("", simpleName))
.addStatement("return values().find·{·it.rawValue·==·rawValue·} ?: $UNKNOWN__")
.addStatement("return·values().find·{·it.rawValue·==·rawValue·} ?: $UNKNOWN__")
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.apollographql.apollo3.compiler.codegen.Identifier.writer
import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinContext
import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinResolver
import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinSymbols
import com.apollographql.apollo3.compiler.codegen.kotlin.adapter.obj
import com.apollographql.apollo3.compiler.codegen.kotlin.helpers.patchKotlinNativeOptionalArrayProperties
import com.apollographql.apollo3.compiler.ir.IrProperty
import com.squareup.kotlinpoet.ClassName
Expand Down Expand Up @@ -69,7 +68,7 @@ fun rootFieldFunSpec(context: KotlinContext, typeInScope: String, selectionsClas
.returns(KotlinSymbols.CompiledField)
.addCode(
CodeBlock.builder()
.add("return %T(\n", KotlinSymbols.CompiledFieldBuilder)
.add("return·%T(\n", KotlinSymbols.CompiledFieldBuilder)
.indent()
.add("name·=·%S,\n", Identifier.data)
.add("type·=·%L\n", context.resolver.resolveCompiledType(typeInScope))
Expand All @@ -87,4 +86,4 @@ fun TypeSpec.maybeAddFilterNotNull(generateFilterNotNull: Boolean): TypeSpec {
return this
}
return patchKotlinNativeOptionalArrayProperties()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.apollographql.apollo3.compiler.codegen.maybeFlatten
import com.apollographql.apollo3.compiler.ir.IrOperation
import com.apollographql.apollo3.compiler.ir.IrOperationType
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
Expand Down Expand Up @@ -117,15 +116,15 @@ class OperationBuilder(
private fun operationIdFunSpec() = FunSpec.builder(id)
.addModifiers(KModifier.OVERRIDE)
.returns(KotlinSymbols.String)
.addStatement("return $OPERATION_ID")
.addStatement("return·$OPERATION_ID")
.build()

private fun queryDocumentFunSpec(generateQueryDocument: Boolean) = FunSpec.builder(document)
.addModifiers(KModifier.OVERRIDE)
.returns(KotlinSymbols.String)
.apply {
if (generateQueryDocument) {
addStatement("return $OPERATION_DOCUMENT")
addStatement("return·$OPERATION_DOCUMENT")
} else {
addStatement("error(\"The·query·document·was·removed·from·this·operation.·Use·generateQueryDocument.set(true)·if·you·need·it\")")
}
Expand All @@ -135,7 +134,7 @@ class OperationBuilder(
private fun nameFunSpec() = FunSpec.builder(name)
.addModifiers(KModifier.OVERRIDE)
.returns(KotlinSymbols.String)
.addStatement("return OPERATION_NAME")
.addStatement("return·OPERATION_NAME")
.build()

private fun companionTypeSpec(): TypeSpec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SchemaBuilder(

builder.addParameter("type", KotlinSymbols.CompiledNamedType)
builder.returns(KotlinSymbols.List.parameterizedBy(KotlinSymbols.ObjectType))
builder.addCode("return %M(all, type)\n", MemberName("com.apollographql.apollo3.api", "possibleTypes"))
builder.addCode("return·%M(all, type)\n", MemberName("com.apollographql.apollo3.api", "possibleTypes"))
return builder.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class TestBuildersBuilder(

val builder = CodeBlock.builder()

builder.beginControlFlow("return %M(${testResolver})", KotlinMemberNames.withTestResolver)
builder.beginControlFlow("return·%M(${testResolver})", KotlinMemberNames.withTestResolver)

builder.add(
"%L.$fromJson(\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ private fun equalsFunSpec() = FunSpec.builder(Identifier.equals)
.addModifiers(KModifier.OVERRIDE)
.addParameter("other", KotlinSymbols.Any.copy(nullable = true))
.returns(KotlinSymbols.Boolean)
.addStatement("return other != null && other::class == this::class")
.addStatement("return·other != null·&&·other::class·==·this::class")
.build()

private fun hashCodeFunSpec() = FunSpec.builder(Identifier.hashCode)
.addModifiers(KModifier.OVERRIDE)
.returns(KotlinSymbols.Int)
.addStatement("return this::class.hashCode()")
.addStatement("return·this::class.hashCode()")
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ internal fun TypeSpec.patchKotlinNativeOptionalArrayProperties(): TypeSpec {
FunSpec
.builder("${propertySpec.name}FilterNotNull")
.returns(nonOptionalListType)
.addStatement("return %L%L.filterNotNull()", propertySpec.name, if (propertySpec.type.isNullable) "?" else "")
.addStatement("return·%L%L.filterNotNull()", propertySpec.name, if (propertySpec.type.isNullable) "?" else "")
.build()
}
return toBuilder()
.addFunctions(nonOptionalListPropertyAccessors)
.apply { typeSpecs.clear() }
.addTypes(patchedNestedTypes)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ModelBuilder(
val funSpecs = model.accessors.map { accessor ->
FunSpec.builder(accessor.funName())
.receiver(context.resolver.resolveModel(model.id))
.addCode("return this as? %T\n", context.resolver.resolveModel(accessor.returnedModelId))
.addCode("return·this as? %T\n", context.resolver.resolveModel(accessor.returnedModelId))
.build()
}
return TypeSpec.companionObjectBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal class TBuilderBuilder(
builder.addModifiers(KModifier.OVERRIDE)
builder.addCode(
CodeBlock.builder()
.add("return mapOf(\n")
.add("return·mapOf(\n")
.indent()
.apply {
tbuilder.properties.forEach { tprop ->
Expand Down Expand Up @@ -133,7 +133,7 @@ internal class TBuilderBuilder(
.addCode(
CodeBlock.builder()
.add("__shouldBeAssignedFields.add(%S)\n", responseName)
.add("return %T().apply($block).build()", context.resolver.resolveTestBuilder(id))
.add("return·%T().apply($block).build()", context.resolver.resolveTestBuilder(id))
.build()
)
.returns(anyMapClassName)
Expand Down
4 changes: 4 additions & 0 deletions tests/models-fixtures/graphql/operations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,8 @@ query Starship($id: ID!) {
name
starshipType
}

aFieldWithAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName: starship(id: $id) {
id
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class TestBuildersTest {


@Test
fun erroorIfForgotToAssignField() {
fun errorIfForgotToAssignField() {
val e1 = assertFailsWith<IllegalStateException>() {
AllPlanetsQuery.Data {
/* allPlanets = */ allPlanets {
Expand Down