diff --git a/libraries/apollo-annotations/api/apollo-annotations.api b/libraries/apollo-annotations/api/apollo-annotations.api index d0222e2ccd9..36ce888ee3c 100644 --- a/libraries/apollo-annotations/api/apollo-annotations.api +++ b/libraries/apollo-annotations/api/apollo-annotations.api @@ -27,9 +27,6 @@ public final class com/apollographql/apollo3/annotations/ApolloDeprecatedSince$V public static fun values ()[Lcom/apollographql/apollo3/annotations/ApolloDeprecatedSince$Version; } -public abstract interface annotation class com/apollographql/apollo3/annotations/ApolloEnumConstructor : java/lang/annotation/Annotation { -} - public abstract interface annotation class com/apollographql/apollo3/annotations/ApolloExperimental : java/lang/annotation/Annotation { } diff --git a/libraries/apollo-annotations/api/apollo-annotations.klib.api b/libraries/apollo-annotations/api/apollo-annotations.klib.api index de0b77df7d0..586be351c62 100644 --- a/libraries/apollo-annotations/api/apollo-annotations.klib.api +++ b/libraries/apollo-annotations/api/apollo-annotations.klib.api @@ -37,9 +37,6 @@ open annotation class com.apollographql.apollo3.annotations/ApolloDeprecatedSinc final val version // com.apollographql.apollo3.annotations/ApolloDeprecatedSince.version|{}version[0] final fun (): com.apollographql.apollo3.annotations/ApolloDeprecatedSince.Version // com.apollographql.apollo3.annotations/ApolloDeprecatedSince.version.|(){}[0] } -open annotation class com.apollographql.apollo3.annotations/ApolloEnumConstructor : kotlin/Annotation { // com.apollographql.apollo3.annotations/ApolloEnumConstructor|null[0] - constructor () // com.apollographql.apollo3.annotations/ApolloEnumConstructor.|(){}[0] -} open annotation class com.apollographql.apollo3.annotations/ApolloExperimental : kotlin/Annotation { // com.apollographql.apollo3.annotations/ApolloExperimental|null[0] constructor () // com.apollographql.apollo3.annotations/ApolloExperimental.|(){}[0] } diff --git a/libraries/apollo-annotations/src/commonMain/kotlin/com/apollographql/apollo3/annotations/ApolloEnumConstructor.kt b/libraries/apollo-annotations/src/commonMain/kotlin/com/apollographql/apollo3/annotations/ApolloEnumConstructor.kt deleted file mode 100644 index a3821de3c10..00000000000 --- a/libraries/apollo-annotations/src/commonMain/kotlin/com/apollographql/apollo3/annotations/ApolloEnumConstructor.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.apollographql.apollo3.annotations - -@RequiresOptIn( - level = RequiresOptIn.Level.WARNING, - message = "The `UNKNOWN__` class represents GraphQL enums that are not present in the schema and whose `rawValue` cannot be checked at build time. You may want to update your schema instead of calling this constructor directly." -) -@Retention(AnnotationRetention.BINARY) -@Target(AnnotationTarget.CONSTRUCTOR) -annotation class ApolloEnumConstructor diff --git a/libraries/apollo-api-java/src/main/java/com/apollographql/apollo3/api/java/Assertions.java b/libraries/apollo-api-java/src/main/java/com/apollographql/apollo3/api/java/Assertions.java index c02f8958675..7e194fbafed 100644 --- a/libraries/apollo-api-java/src/main/java/com/apollographql/apollo3/api/java/Assertions.java +++ b/libraries/apollo-api-java/src/main/java/com/apollographql/apollo3/api/java/Assertions.java @@ -1,6 +1,7 @@ package com.apollographql.apollo3.api.java; public class Assertions { + // A version of Objects.requireNonNull that allows a customized message public static T checkNotNull(T value, String errorMessage) { if (value == null) { throw new NullPointerException(errorMessage); @@ -8,4 +9,4 @@ public static T checkNotNull(T value, String errorMessage) { return value; } -} \ No newline at end of file +} diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt index 4d434de3583..866ecd61f3c 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/JavaClassNames.kt @@ -111,6 +111,7 @@ internal object JavaClassNames { val Map: ClassName = ClassName.get("java.util", "Map") val MapOfStringToObject = ParameterizedTypeName.get(Map, String, Object) val JavaOptional = ClassName.get("java.util", "Optional") + val Objects = ClassName.get("java.util", "Objects") val ObjectBuilderKt = ClassName.get(apolloApiPackageName, "ObjectBuilderKt") val ObjectMap = ClassName.get(apolloApiPackageName, "ObjectMap") diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/DataClass.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/DataClass.kt index 3526af58279..acd94fb69ee 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/DataClass.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/helpers/DataClass.kt @@ -1,12 +1,13 @@ package com.apollographql.apollo3.compiler.codegen.java.helpers import com.apollographql.apollo3.compiler.GeneratedMethod -import com.apollographql.apollo3.compiler.GeneratedMethod.* -import com.apollographql.apollo3.compiler.internal.applyIf +import com.apollographql.apollo3.compiler.GeneratedMethod.EQUALS_HASH_CODE +import com.apollographql.apollo3.compiler.GeneratedMethod.TO_STRING import com.apollographql.apollo3.compiler.codegen.Identifier.__h import com.apollographql.apollo3.compiler.codegen.java.JavaClassNames import com.apollographql.apollo3.compiler.codegen.java.L import com.apollographql.apollo3.compiler.codegen.java.joinToCode +import com.apollographql.apollo3.compiler.internal.applyIf import com.squareup.javapoet.ClassName import com.squareup.javapoet.CodeBlock import com.squareup.javapoet.FieldSpec @@ -30,7 +31,7 @@ internal fun TypeSpec.Builder.makeClassFromParameters( generateMethods: List, parameters: List, className: ClassName - ): TypeSpec.Builder { +): TypeSpec.Builder { addMethod( MethodSpec.constructorBuilder() .addModifiers(Modifier.PUBLIC) @@ -69,7 +70,7 @@ internal fun TypeSpec.Builder.makeClassFromProperties( generateMethods: List, fields: List, className: ClassName - ): TypeSpec.Builder { +): TypeSpec.Builder { addMethod( MethodSpec.constructorBuilder() .addModifiers(Modifier.PUBLIC) @@ -94,36 +95,36 @@ internal fun TypeSpec.Builder.makeClassFromProperties( internal fun TypeSpec.Builder.withToStringImplementation(className: ClassName): TypeSpec.Builder { fun printFieldCode(fieldIndex: Int, fieldName: String) = - CodeBlock.builder() - .let { if (fieldIndex > 0) it.add(" + \", \"\n") else it.add("\n") } - .indent() - .add("+ \$S + \$L", "$fieldName=", fieldName) - .unindent() - .build() + CodeBlock.builder() + .let { if (fieldIndex > 0) it.add(" + \", \"\n") else it.add("\n") } + .indent() + .add("+ \$S + \$L", "$fieldName=", fieldName) + .unindent() + .build() fun methodCode() = - CodeBlock.builder() - .beginControlFlow("if (\$L == null)", MEMOIZED_TO_STRING_VAR) - .add("\$L = \$S", "\$toString", "${className.simpleName()}{") - .add(fieldSpecs - .filter { !it.hasModifier(Modifier.STATIC) } - .filter { !it.hasModifier(Modifier.TRANSIENT) } - .map { it.name } - .mapIndexed(::printFieldCode) - .fold(CodeBlock.builder(), CodeBlock.Builder::add) - .build()) - .add(CodeBlock.builder() - .indent() - .add("\n+ \$S;\n", "}") - .unindent() - .build()) - .endControlFlow() - .addStatement("return \$L", MEMOIZED_TO_STRING_VAR) - .build() + CodeBlock.builder() + .beginControlFlow("if (\$L == null)", MEMOIZED_TO_STRING_VAR) + .add("\$L = \$S", "\$toString", "${className.simpleName()}{") + .add(fieldSpecs + .filter { !it.hasModifier(Modifier.STATIC) } + .filter { !it.hasModifier(Modifier.TRANSIENT) } + .map { it.name } + .mapIndexed(::printFieldCode) + .fold(CodeBlock.builder(), CodeBlock.Builder::add) + .build()) + .add(CodeBlock.builder() + .indent() + .add("\n+ \$S;\n", "}") + .unindent() + .build()) + .endControlFlow() + .addStatement("return \$L", MEMOIZED_TO_STRING_VAR) + .build() return addField(FieldSpec.builder(JavaClassNames.String, MEMOIZED_TO_STRING_VAR, Modifier.PRIVATE, Modifier.VOLATILE, - Modifier.TRANSIENT) - .build()) + Modifier.TRANSIENT) + .build()) .addMethod(MethodSpec.methodBuilder("toString") .addAnnotation(JavaClassNames.Override) .addModifiers(Modifier.PUBLIC) @@ -138,84 +139,84 @@ private fun List.equalsCode(): CodeBlock = filter { !it.hasModifier(M .joinToCode("\n &&") private fun FieldSpec.equalsCode() = - CodeBlock.builder() - .let { - if (type.isPrimitive) { - if (type == TypeName.DOUBLE) { - it.add("Double.doubleToLongBits(this.\$L) == Double.doubleToLongBits(that.\$L)", - name, name) - } else { - it.add("this.\$L == that.\$L", name, name) - } + CodeBlock.builder() + .let { + if (type.isPrimitive) { + if (type == TypeName.DOUBLE) { + it.add("Double.doubleToLongBits(this.\$L) == Double.doubleToLongBits(that.\$L)", + name, name) } else { - it.add("((this.\$L == null) ? (that.\$L == null) : this.\$L.equals(that.\$L))", name, name, name, name) + it.add("this.\$L == that.\$L", name, name) } + } else { + it.add("((this.\$L == null) ? (that.\$L == null) : this.\$L.equals(that.\$L))", name, name, name, name) } - .build() + } + .build() internal fun TypeSpec.Builder.withEqualsImplementation(className: ClassName): TypeSpec.Builder { fun methodCode(typeJavaClass: ClassName) = - CodeBlock.builder() - .beginControlFlow("if (o == this)") - .addStatement("return true") - .endControlFlow() - .beginControlFlow("if (o instanceof \$T)", typeJavaClass) - .apply { - if (fieldSpecs.isEmpty()) { - add("return true;\n") - } else { - addStatement("\$T that = (\$T) o", typeJavaClass, typeJavaClass) - add("return $L;\n", if (fieldSpecs.isEmpty()) "true" else fieldSpecs.equalsCode()) - } + CodeBlock.builder() + .beginControlFlow("if (o == this)") + .addStatement("return true") + .endControlFlow() + .beginControlFlow("if (o instanceof \$T)", typeJavaClass) + .apply { + if (fieldSpecs.isEmpty()) { + add("return true;\n") + } else { + addStatement("\$T that = (\$T) o", typeJavaClass, typeJavaClass) + add("return $L;\n", if (fieldSpecs.isEmpty()) "true" else fieldSpecs.equalsCode()) } - .endControlFlow() - .addStatement("return false") - .build() + } + .endControlFlow() + .addStatement("return false") + .build() return addMethod(MethodSpec.methodBuilder("equals") - .addAnnotation(JavaClassNames.Override) - .addModifiers(Modifier.PUBLIC) - .returns(TypeName.BOOLEAN) - .addParameter(ParameterSpec.builder(TypeName.OBJECT, "o").build()) - .addCode(methodCode(className)) - .build()) + .addAnnotation(JavaClassNames.Override) + .addModifiers(Modifier.PUBLIC) + .returns(TypeName.BOOLEAN) + .addParameter(ParameterSpec.builder(TypeName.OBJECT, "o").build()) + .addCode(methodCode(className)) + .build()) } internal fun TypeSpec.Builder.withHashCodeImplementation(): TypeSpec.Builder { fun hashFieldCode(field: FieldSpec) = - CodeBlock.builder() - .addStatement("$__h *= 1000003") - .let { - if (field.type.isPrimitive) { - when (field.type.withoutAnnotations()) { - TypeName.DOUBLE -> it.addStatement("$__h ^= Double.valueOf(\$L).hashCode()", field.name) - TypeName.BOOLEAN -> it.addStatement("$__h ^= Boolean.valueOf(\$L).hashCode()", field.name) - else -> it.addStatement("$__h ^= \$L", field.name) - } - } else { - it.addStatement("$__h ^= (\$L == null) ? 0 : \$L.hashCode()", field.name, field.name) + CodeBlock.builder() + .addStatement("$__h *= 1000003") + .let { + if (field.type.isPrimitive) { + when (field.type.withoutAnnotations()) { + TypeName.DOUBLE -> it.addStatement("$__h ^= Double.valueOf(\$L).hashCode()", field.name) + TypeName.BOOLEAN -> it.addStatement("$__h ^= Boolean.valueOf(\$L).hashCode()", field.name) + else -> it.addStatement("$__h ^= \$L", field.name) } + } else { + it.addStatement("$__h ^= (\$L == null) ? 0 : \$L.hashCode()", field.name, field.name) } - .build() + } + .build() fun methodCode() = - CodeBlock.builder() - .beginControlFlow("if (!\$L)", MEMOIZED_HASH_CODE_FLAG_VAR) - .addStatement("int $__h = 1") - .add(fieldSpecs - .filter { !it.hasModifier(Modifier.STATIC) } - .filter { !it.hasModifier(Modifier.TRANSIENT) } - .map(::hashFieldCode) - .fold(CodeBlock.builder(), CodeBlock.Builder::add) - .build()) - .addStatement("\$L = $__h", MEMOIZED_HASH_CODE_VAR) - .addStatement("\$L = true", MEMOIZED_HASH_CODE_FLAG_VAR) - .endControlFlow() - .addStatement("return \$L", MEMOIZED_HASH_CODE_VAR) - .build() + CodeBlock.builder() + .beginControlFlow("if (!\$L)", MEMOIZED_HASH_CODE_FLAG_VAR) + .addStatement("int $__h = 1") + .add(fieldSpecs + .filter { !it.hasModifier(Modifier.STATIC) } + .filter { !it.hasModifier(Modifier.TRANSIENT) } + .map(::hashFieldCode) + .fold(CodeBlock.builder(), CodeBlock.Builder::add) + .build()) + .addStatement("\$L = $__h", MEMOIZED_HASH_CODE_VAR) + .addStatement("\$L = true", MEMOIZED_HASH_CODE_FLAG_VAR) + .endControlFlow() + .addStatement("return \$L", MEMOIZED_HASH_CODE_VAR) + .build() return addField(FieldSpec.builder(TypeName.INT, MEMOIZED_HASH_CODE_VAR, Modifier.PRIVATE, Modifier.VOLATILE, - Modifier.TRANSIENT).build()) + Modifier.TRANSIENT).build()) .addField(FieldSpec.builder(TypeName.BOOLEAN, MEMOIZED_HASH_CODE_FLAG_VAR, Modifier.PRIVATE, Modifier.VOLATILE, Modifier.TRANSIENT).build()) .addMethod(MethodSpec.methodBuilder("hashCode") diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsClassBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsClassBuilder.kt index a76d0426841..f81bdd3bd78 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsClassBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsClassBuilder.kt @@ -10,7 +10,6 @@ import com.apollographql.apollo3.compiler.codegen.java.JavaSchemaContext import com.apollographql.apollo3.compiler.codegen.java.L import com.apollographql.apollo3.compiler.codegen.java.S import com.apollographql.apollo3.compiler.codegen.java.T -import com.apollographql.apollo3.compiler.codegen.java.helpers.addGeneratedMethods import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeAddDescription import com.apollographql.apollo3.compiler.codegen.java.helpers.maybeSuppressDeprecation import com.apollographql.apollo3.compiler.codegen.typePackageName @@ -22,6 +21,7 @@ import com.squareup.javapoet.CodeBlock import com.squareup.javapoet.FieldSpec import com.squareup.javapoet.MethodSpec import com.squareup.javapoet.ParameterSpec +import com.squareup.javapoet.TypeName import com.squareup.javapoet.TypeSpec import javax.lang.model.element.Modifier @@ -63,7 +63,7 @@ internal class EnumAsClassBuilder( ) .addMethod( MethodSpec.constructorBuilder() - .addModifiers(Modifier.PUBLIC) + .addModifiers(Modifier.PRIVATE) .addParameter(ParameterSpec.builder(JavaClassNames.String, rawValue).build()) .addCode("this.$rawValue = $rawValue;\n") .build() @@ -79,6 +79,10 @@ internal class EnumAsClassBuilder( ) .addMethod( MethodSpec.methodBuilder(safeValueOf) + .addJavadoc( + "Returns the ${enum.name} that represents the specified rawValue.\n" + + "Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly.\n", + ) .maybeSuppressDeprecation(enum.values) .addParameter(JavaClassNames.String, rawValue) .addModifiers(Modifier.PUBLIC) @@ -86,7 +90,7 @@ internal class EnumAsClassBuilder( .returns(selfClassName) .addCode( CodeBlock.builder() - .beginControlFlow("switch($rawValue)") + .beginControlFlow("switch ($T.requireNonNull($rawValue))", JavaClassNames.Objects) .apply { values.forEach { add("case $S: return $T.$L;\n", it.name, selfClassName, it.targetName.escapeTypeReservedWord() @@ -113,12 +117,42 @@ internal class EnumAsClassBuilder( .addJavadoc(L, "An enum value that wasn't known at compile time.\n") .addMethod( MethodSpec.constructorBuilder() - .addModifiers(Modifier.PUBLIC) + .addModifiers(Modifier.PRIVATE) .addParameter(ParameterSpec.builder(JavaClassNames.String, rawValue).build()) .addCode("super($rawValue);\n") .build() ) - .addGeneratedMethods(ClassName.get("", Identifier.UNKNOWN__)) + .addMethod( + MethodSpec.methodBuilder("equals") + .addModifiers(Modifier.PUBLIC) + .addAnnotation(JavaClassNames.Override) + .addParameter(ParameterSpec.builder(JavaClassNames.Object, "other").build()) + .returns(TypeName.BOOLEAN) + .addCode( + CodeBlock.builder() + .add("if (this == other) return true;\n") + .add("if (!(other instanceof $L)) return false;\n", Identifier.UNKNOWN__) + .addStatement("return rawValue.equals((($L) other).rawValue)", Identifier.UNKNOWN__) + .build() + ) + .build() + ) + .addMethod( + MethodSpec.methodBuilder("hashCode") + .addModifiers(Modifier.PUBLIC) + .addAnnotation(JavaClassNames.Override) + .returns(TypeName.INT) + .addCode("return rawValue.hashCode();\n") + .build() + ) + .addMethod( + MethodSpec.methodBuilder("toString") + .addModifiers(Modifier.PUBLIC) + .addAnnotation(JavaClassNames.Override) + .returns(JavaClassNames.String) + .addCode("return \"$L(\" + rawValue + \")\";\n", Identifier.UNKNOWN__) + .build() + ) .build() } } diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsEnumBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsEnumBuilder.kt index 271b7e3d462..40374c82c5c 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsEnumBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/java/schema/EnumAsEnumBuilder.kt @@ -78,6 +78,10 @@ internal class EnumAsEnumBuilder( } .addMethod( MethodSpec.methodBuilder(safeValueOf) + .addJavadoc( + "Returns the ${enum.name} that represents the specified rawValue.\n" + + "Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly.\n", + ) .maybeSuppressDeprecation(enum.values) .addParameter(JavaClassNames.String, rawValue) .addModifiers(Modifier.PUBLIC) @@ -85,7 +89,7 @@ internal class EnumAsEnumBuilder( .returns(selfClassName) .addCode( CodeBlock.builder() - .beginControlFlow("switch ($rawValue)") + .beginControlFlow("switch ($T.requireNonNull($rawValue))", JavaClassNames.Objects) .apply { values.forEach { add("case $S: return $T.$L;\n", it.name, selfClassName, it.targetName.escapeTypeReservedWord() diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/KotlinSymbols.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/KotlinSymbols.kt index bb5b99685f4..adb33870e98 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/KotlinSymbols.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/KotlinSymbols.kt @@ -105,7 +105,6 @@ internal object KotlinSymbols { val ApolloAdaptableWith = ClassName(ClassNames.apolloAnnotationsPackageName, "ApolloAdaptableWith") val ApolloExperimental = ClassName(ClassNames.apolloAnnotationsPackageName, "ApolloExperimental") - val ApolloEnumConstructor = ClassName(ClassNames.apolloAnnotationsPackageName, "ApolloEnumConstructor") val JsExport = ClassName("kotlin.js", "JsExport") diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsEnumBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsEnumBuilder.kt index 4f414ed7c4e..497c800d895 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsEnumBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsEnumBuilder.kt @@ -123,6 +123,11 @@ internal class EnumAsEnumBuilder( private fun IrEnum.safeValueOfFunSpec(): FunSpec { val entries = if (context.isTargetLanguageVersionAtLeast(TargetLanguage.KOTLIN_1_9)) "entries" else "values()" return FunSpec.builder("safeValueOf") + .addKdoc( + "Returns the [%T] that represents the specified [rawValue].\n" + + "Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your schema instead of calling this function directly.\n", + selfClassName + ) .addParameter("rawValue", String:: class) .returns(selfClassName) @@ -163,4 +168,4 @@ internal class EnumAsEnumBuilder( .initializer("rawValue") .build() -} \ No newline at end of file +} diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsSealedBuilder.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsSealedBuilder.kt index 3eefb4b5c23..b07379ddcce 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsSealedBuilder.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo3/compiler/codegen/kotlin/schema/EnumAsSealedBuilder.kt @@ -50,16 +50,15 @@ internal class EnumAsSealedBuilder( return CgFile( packageName = packageName, fileName = simpleName, - typeSpecs = listOf(enum.toSealedClassTypeSpec()) + typeSpecs = listOf(enum.toSealedClassTypeSpec(), enum.unknownClassTypeSpec()) ) } private fun IrEnum.toSealedClassTypeSpec(): TypeSpec { - return TypeSpec.classBuilder(simpleName) + return TypeSpec.interfaceBuilder(simpleName) .maybeAddDescription(description) // XXX: can an enum be made deprecated (and not only its values) ? .addModifiers(KModifier.SEALED) - .primaryConstructor(primaryConstructorWithOverriddenParamSpec) .addProperty(rawValuePropertySpec) .addType(companionTypeSpec()) .addTypes(values.map { value -> @@ -82,17 +81,30 @@ internal class EnumAsSealedBuilder( .maybeAddDeprecation(deprecationReason) .maybeAddDescription(description) .maybeAddRequiresOptIn(context.resolver, optInFeature) - .superclass(superClass) - .addSuperclassConstructorParameter("rawValue·=·%S", name) + .addSuperinterface(superClass) + .addProperty( + PropertySpec.builder("rawValue", KotlinSymbols.String) + .addModifiers(KModifier.OVERRIDE) + .initializer("%S", name) + .build() + ) .build() } private fun IrEnum.unknownValueTypeSpec(): TypeSpec { - return TypeSpec.classBuilder("UNKNOWN__") - .addKdoc("An enum value that wasn't known at compile time.\nConstructor is annotated with [%T] to prevent instantiation outside of this file.", KotlinSymbols.ApolloEnumConstructor) + return TypeSpec.interfaceBuilder("UNKNOWN__") + .addKdoc("An enum value that wasn't known at compile time.") + .addSuperinterface(selfClassName) + .addProperty(unknownValueRawValuePropertySpec) + .build() + } + + private fun IrEnum.unknownClassTypeSpec(): TypeSpec { + return TypeSpec.classBuilder("UNKNOWN__${simpleName}") + .addSuperinterface(unknownValueInterfaceName()) .primaryConstructor(unknownValuePrimaryConstructorSpec) - .superclass(selfClassName) - .addSuperclassConstructorParameter("rawValue·=·rawValue") + .addProperty(unknownValueRawValuePropertySpecWithInitializer) + .addModifiers(KModifier.PRIVATE) .addFunction( FunSpec.builder("equals") .addModifiers(KModifier.OVERRIDE) @@ -121,7 +133,11 @@ internal class EnumAsSealedBuilder( private fun IrEnum.safeValueOfFunSpec(): FunSpec { return FunSpec.builder(Identifier.safeValueOf) - .addKdoc("Returns the [%T] that represents the specified [rawValue].\n", selfClassName) + .addKdoc( + "Returns the [%T] that represents the specified [rawValue].\n" + + "Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your schema instead of calling this function directly.\n", + selfClassName + ) .addSuppressions(enum.values.any { it.deprecationReason != null }) .maybeAddOptIn(context.resolver, enum.values) .addParameter("rawValue", KotlinSymbols.String) @@ -132,7 +148,7 @@ internal class EnumAsSealedBuilder( .map { CodeBlock.of("%S·->·%T", it.name, it.valueClassName()) } .joinToCode(separator = "\n", suffix = "\n") ) - .addCode("else -> @OptIn(%T::class) %T(rawValue)\n", KotlinSymbols.ApolloEnumConstructor, unknownValueClassName()) + .addCode("else -> %T(rawValue)\n", unknownValueClassName()) .endControlFlow() .build() } @@ -163,24 +179,31 @@ internal class EnumAsSealedBuilder( return ClassName(selfClassName.packageName, selfClassName.simpleName, targetName.escapeKotlinReservedWordInSealedClass()) } - private fun unknownValueClassName(): ClassName { + private fun unknownValueInterfaceName(): ClassName { return ClassName(selfClassName.packageName, selfClassName.simpleName, "UNKNOWN__") } + private fun unknownValueClassName(): ClassName { + return ClassName(selfClassName.packageName, "UNKNOWN__${selfClassName.simpleName}") + } + private val unknownValuePrimaryConstructorSpec = FunSpec.constructorBuilder() - .addAnnotation(KotlinSymbols.ApolloEnumConstructor) .addParameter("rawValue", KotlinSymbols.String) .build() - private val primaryConstructorWithOverriddenParamSpec = - FunSpec.constructorBuilder() - .addParameter("rawValue", KotlinSymbols.String) + private val unknownValueRawValuePropertySpec = + PropertySpec.builder("rawValue", KotlinSymbols.String) + .addModifiers(KModifier.OVERRIDE) .build() - private val rawValuePropertySpec = + private val unknownValueRawValuePropertySpecWithInitializer = PropertySpec.builder("rawValue", KotlinSymbols.String) + .addModifiers(KModifier.OVERRIDE) .initializer("rawValue") .build() + private val rawValuePropertySpec = + PropertySpec.builder("rawValue", KotlinSymbols.String) + .build() } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/type/Enum.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/type/Enum.java.expected index 592a99eba45..3eb4c73ab70 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/type/Enum.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/java/operationBased/case_sensitive_enum/type/Enum.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public class Enum { public static EnumType type = new EnumType("Enum", Arrays.asList("north", "North", "NORTH", "SOUTH")); @@ -25,13 +26,17 @@ public class Enum { public String rawValue; - public Enum(String rawValue) { + private Enum(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Enum that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Enum safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "north": return Enum.north; case "North": return Enum.North; case "NORTH": return Enum.NORTH; @@ -44,44 +49,25 @@ public class Enum { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Enum { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/kotlin/responseBased/case_sensitive_enum/type/Enum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/kotlin/responseBased/case_sensitive_enum/type/Enum.kt.expected index b29f4869e76..545358ff13c 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/kotlin/responseBased/case_sensitive_enum/type/Enum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/case_sensitive_enum/kotlin/responseBased/case_sensitive_enum/type/Enum.kt.expected @@ -50,6 +50,11 @@ public enum class Enum( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Enum] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Enum = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/type/Episode.java.expected index 0cc2efb3cb2..2cb7461ef7e 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/java/operationBased/deprecation/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public class Episode { public static EnumType type = new EnumType("Episode", Arrays.asList("JEDI", "CLONES")); @@ -21,13 +22,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "JEDI": return Episode.JEDI; case "CLONES": return Episode.CLONES; default: return new Episode.UNKNOWN__(rawValue); @@ -38,44 +43,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/kotlin/responseBased/deprecation/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/kotlin/responseBased/deprecation/type/Episode.kt.expected index bd9185d54c1..2f7674c2f41 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/kotlin/responseBased/deprecation/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/deprecation/kotlin/responseBased/deprecation/type/Episode.kt.expected @@ -45,6 +45,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/Gravity.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/Gravity.java.expected index 94a08711858..61cad078d99 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/Gravity.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/Gravity.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public class Gravity { public static EnumType type = new EnumType("Gravity", Arrays.asList("TOP", "CENTER", "BOTTOM", "bottom", "is", "type", "String")); @@ -31,13 +32,17 @@ public class Gravity { public String rawValue; - public Gravity(String rawValue) { + private Gravity(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Gravity that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Gravity safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "TOP": return Gravity.TOP; case "CENTER": return Gravity.CENTER; case "BOTTOM": return Gravity.BOTTOM; @@ -53,44 +58,25 @@ public class Gravity { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Gravity { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/GravityAsEnum.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/GravityAsEnum.java.expected index 471e8249179..54a0a17db1a 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/GravityAsEnum.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/java/operationBased/enum_field/type/GravityAsEnum.java.expected @@ -10,6 +10,7 @@ import java.lang.Deprecated; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public enum GravityAsEnum { TOP("TOP"), @@ -55,9 +56,13 @@ public enum GravityAsEnum { this.rawValue = rawValue; } + /** + * Returns the GravityAsEnum that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static GravityAsEnum safeValueOf(String rawValue) { - switch (rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "TOP": return GravityAsEnum.TOP; case "CENTER": return GravityAsEnum.CENTER; case "BOTTOM": return GravityAsEnum.BOTTOM; diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected index e33d6924c84..375a20a3c40 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected @@ -55,6 +55,11 @@ public enum class Gravity( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Gravity] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: kotlin.String): Gravity = entries.find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected index e0a1c12aa38..04953d73ab9 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected @@ -69,6 +69,11 @@ public enum class GravityAsEnum( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [GravityAsEnum] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: kotlin.String): GravityAsEnum = entries.find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/type/Enum.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/type/Enum.java.expected index 2321e89103f..69f5c160625 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/type/Enum.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/java/operationBased/enums_as_sealed/type/Enum.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public class Enum { public static EnumType type = new EnumType("Enum", Arrays.asList("north", "North", "NORTH", "SOUTH", "type")); @@ -27,13 +28,17 @@ public class Enum { public String rawValue; - public Enum(String rawValue) { + private Enum(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Enum that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Enum safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "north": return Enum.north; case "North": return Enum.North; case "NORTH": return Enum.NORTH; @@ -47,44 +52,25 @@ public class Enum { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Enum { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/kotlin/responseBased/enums_as_sealed/type/Enum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/kotlin/responseBased/enums_as_sealed/type/Enum.kt.expected index b1e48c7a334..e01dbd09ef5 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/kotlin/responseBased/enums_as_sealed/type/Enum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enums_as_sealed/kotlin/responseBased/enums_as_sealed/type/Enum.kt.expected @@ -5,7 +5,6 @@ // package com.example.enums_as_sealed.type -import com.apollographql.apollo3.annotations.ApolloEnumConstructor import com.apollographql.apollo3.api.EnumType import kotlin.Any import kotlin.Array @@ -15,14 +14,16 @@ import kotlin.Int import kotlin.String import kotlin.Suppress -public sealed class Enum( - public val rawValue: String, -) { +public sealed interface Enum { + public val rawValue: String + public companion object { public val type: EnumType = EnumType("Enum", listOf("north", "North", "NORTH", "SOUTH", "type")) /** * Returns the [Enum] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. */ @Suppress("DEPRECATION") public fun safeValueOf(rawValue: String): Enum = when(rawValue) { @@ -31,7 +32,7 @@ public sealed class Enum( "NORTH" -> NORTH "SOUTH" -> SOUTH "type" -> type_ - else -> @OptIn(ApolloEnumConstructor::class) UNKNOWN__(rawValue) + else -> UNKNOWN__Enum(rawValue) } /** @@ -47,32 +48,44 @@ public sealed class Enum( } @Deprecated(message = "No longer supported") - public object north : Enum(rawValue = "north") + public object north : Enum { + override val rawValue: String = "north" + } @Deprecated(message = "No longer supported") - public object North : Enum(rawValue = "North") + public object North : Enum { + override val rawValue: String = "North" + } - public object NORTH : Enum(rawValue = "NORTH") + public object NORTH : Enum { + override val rawValue: String = "NORTH" + } - public object SOUTH : Enum(rawValue = "SOUTH") + public object SOUTH : Enum { + override val rawValue: String = "SOUTH" + } - public object type_ : Enum(rawValue = "type") + public object type_ : Enum { + override val rawValue: String = "type" + } /** * An enum value that wasn't known at compile time. - * Constructor is annotated with [ApolloEnumConstructor] to prevent instantiation outside of this - * file. */ - public class UNKNOWN__ @ApolloEnumConstructor constructor( - rawValue: String, - ) : Enum(rawValue = rawValue) { - override fun equals(other: Any?): Boolean { - if (other !is UNKNOWN__) return false - return this.rawValue == other.rawValue - } - - override fun hashCode(): Int = this.rawValue.hashCode() + public interface UNKNOWN__ : Enum { + override val rawValue: String + } +} - override fun toString(): String = "UNKNOWN__($rawValue)" +private class UNKNOWN__Enum( + override val rawValue: String, +) : Enum.UNKNOWN__ { + override fun equals(other: Any?): Boolean { + if (other !is UNKNOWN__Enum) return false + return this.rawValue == other.rawValue } + + override fun hashCode(): Int = this.rawValue.hashCode() + + override fun toString(): String = "UNKNOWN__($rawValue)" } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/type/Episode.java.expected index 5d61fe3e641..ee2489dd157 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/java/operationBased/fragment_with_inline_fragment/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/operationBased/fragment_with_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/operationBased/fragment_with_inline_fragment/type/Episode.kt.expected index 52152a99f29..72186515573 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/operationBased/fragment_with_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/operationBased/fragment_with_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/responseBased/fragment_with_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/responseBased/fragment_with_inline_fragment/type/Episode.kt.expected index 52152a99f29..72186515573 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/responseBased/fragment_with_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/fragment_with_inline_fragment/kotlin/responseBased/fragment_with_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/type/hero_type.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/type/hero_type.java.expected index 16571bcd450..0a79a39075f 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/type/hero_type.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/java/operationBased/hero_details/type/hero_type.java.expected @@ -10,6 +10,7 @@ import java.lang.Object; import java.lang.Override; import java.lang.String; import java.util.Arrays; +import java.util.Objects; /** * Lower case enum type name @@ -23,12 +24,16 @@ public class Hero_type { public String rawValue; - public Hero_type(String rawValue) { + private Hero_type(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the hero_type that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ public static Hero_type safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "human": return Hero_type.human; case "droid": return Hero_type.droid; default: return new Hero_type.UNKNOWN__(rawValue); @@ -39,44 +44,25 @@ public class Hero_type { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Hero_type { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/kotlin/responseBased/hero_details/type/hero_type.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/kotlin/responseBased/hero_details/type/hero_type.kt.expected index 13b82eeddb7..10c01a9daf7 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/kotlin/responseBased/hero_details/type/hero_type.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_details/kotlin/responseBased/hero_details/type/hero_type.kt.expected @@ -45,6 +45,11 @@ public enum class Hero_type( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Hero_type] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Hero_type = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/type/Episode.java.expected index 04312b6bbcf..74c98f17fd0 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/java/operationBased/hero_name_query_long_name/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/kotlin/responseBased/hero_name_query_long_name/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/kotlin/responseBased/hero_name_query_long_name/type/Episode.kt.expected index 11bde9141bc..bf470efda6c 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/kotlin/responseBased/hero_name_query_long_name/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_name_query_long_name/kotlin/responseBased/hero_name_query_long_name/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/type/Episode.java.expected index cd08aef2eed..5cbb0c0fca0 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/java/operationBased/hero_with_review/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/kotlin/responseBased/hero_with_review/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/kotlin/responseBased/hero_with_review/type/Episode.kt.expected index 7bc61f60096..83d113c0abf 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/kotlin/responseBased/hero_with_review/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/hero_with_review/kotlin/responseBased/hero_with_review/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/type/Race.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/type/Race.java.expected index 13348a416cd..3489d6ceb70 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/type/Race.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/java/operationBased/inline_fragment_intersection/type/Race.java.expected @@ -10,6 +10,7 @@ import java.lang.Object; import java.lang.Override; import java.lang.String; import java.util.Arrays; +import java.util.Objects; public class Race { public static EnumType type = new EnumType("Race", Arrays.asList("WOOKIE", "GUMGAN", "EWOK")); @@ -22,12 +23,16 @@ public class Race { public String rawValue; - public Race(String rawValue) { + private Race(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Race that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ public static Race safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "WOOKIE": return Race.WOOKIE; case "GUMGAN": return Race.GUMGAN; case "EWOK": return Race.EWOK; @@ -39,44 +44,25 @@ public class Race { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Race { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/operationBased/inline_fragment_intersection/type/Race.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/operationBased/inline_fragment_intersection/type/Race.kt.expected index cc3843383bd..0c007889015 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/operationBased/inline_fragment_intersection/type/Race.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/operationBased/inline_fragment_intersection/type/Race.kt.expected @@ -44,6 +44,11 @@ public enum class Race( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Race] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Race = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/responseBased/inline_fragment_intersection/type/Race.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/responseBased/inline_fragment_intersection/type/Race.kt.expected index cc3843383bd..0c007889015 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/responseBased/inline_fragment_intersection/type/Race.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragment_intersection/kotlin/responseBased/inline_fragment_intersection/type/Race.kt.expected @@ -44,6 +44,11 @@ public enum class Race( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Race] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Race = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/type/Episode.java.expected index 991bc84fa25..e56626e1f10 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/java/operationBased/inline_fragments_with_friends/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/operationBased/inline_fragments_with_friends/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/operationBased/inline_fragments_with_friends/type/Episode.kt.expected index 39e23f54637..4dbce125c90 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/operationBased/inline_fragments_with_friends/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/operationBased/inline_fragments_with_friends/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/responseBased/inline_fragments_with_friends/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/responseBased/inline_fragments_with_friends/type/Episode.kt.expected index 39e23f54637..4dbce125c90 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/responseBased/inline_fragments_with_friends/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/inline_fragments_with_friends/kotlin/responseBased/inline_fragments_with_friends/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/Episode.java.expected index c6e1444bffa..8b30c428c0a 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/java/operationBased/input_object_type/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/Episode.kt.expected index f460726d1b0..dda92079a63 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_type/kotlin/responseBased/input_object_type/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/type/Episode.java.expected index 477d9f801c1..3da8869a706 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/java/operationBased/input_object_variable_and_argument/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/kotlin/responseBased/input_object_variable_and_argument/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/kotlin/responseBased/input_object_variable_and_argument/type/Episode.kt.expected index 6cf7c520b51..fb0c3790b22 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/kotlin/responseBased/input_object_variable_and_argument/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument/kotlin/responseBased/input_object_variable_and_argument/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/java/operationBased/input_object_variable_and_argument_with_generated_methods/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/java/operationBased/input_object_variable_and_argument_with_generated_methods/type/Episode.java.expected index 8c84fedd899..9beec31de5c 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/java/operationBased/input_object_variable_and_argument_with_generated_methods/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/java/operationBased/input_object_variable_and_argument_with_generated_methods/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/kotlin/responseBased/input_object_variable_and_argument_with_generated_methods/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/kotlin/responseBased/input_object_variable_and_argument_with_generated_methods/type/Episode.kt.expected index ee364c17382..6b697e86b5a 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/kotlin/responseBased/input_object_variable_and_argument_with_generated_methods/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/input_object_variable_and_argument_with_generated_methods/kotlin/responseBased/input_object_variable_and_argument_with_generated_methods/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/type/__TypeKind.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/type/__TypeKind.java.expected index c6392bb2f14..2b3738995fe 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/type/__TypeKind.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/java/operationBased/introspection_query/type/__TypeKind.java.expected @@ -10,6 +10,7 @@ import java.lang.Object; import java.lang.Override; import java.lang.String; import java.util.Arrays; +import java.util.Objects; public class __TypeKind { public static EnumType type = new EnumType("__TypeKind", Arrays.asList("SCALAR", "OBJECT", "INTERFACE", "UNION", "ENUM", "INPUT_OBJECT", "LIST", "NON_NULL")); @@ -32,12 +33,16 @@ public class __TypeKind { public String rawValue; - public __TypeKind(String rawValue) { + private __TypeKind(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the __TypeKind that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ public static __TypeKind safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "SCALAR": return __TypeKind.SCALAR; case "OBJECT": return __TypeKind.OBJECT; case "INTERFACE": return __TypeKind.INTERFACE; @@ -54,44 +59,25 @@ public class __TypeKind { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends __TypeKind { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/kotlin/responseBased/introspection_query/type/__TypeKind.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/kotlin/responseBased/introspection_query/type/__TypeKind.kt.expected index ea015e40ff3..eaa4b0c20de 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/kotlin/responseBased/introspection_query/type/__TypeKind.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/introspection_query/kotlin/responseBased/introspection_query/type/__TypeKind.kt.expected @@ -55,6 +55,11 @@ public enum class __TypeKind( ) public fun knownValues(): Array<__TypeKind> = knownEntries.toTypedArray() + /** + * Returns the [__TypeKind] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): __TypeKind = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/java/operationBased/list_field_clash/type/AmenityCategory.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/java/operationBased/list_field_clash/type/AmenityCategory.java.expected index ab6ab52e2ce..a3be1bf7724 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/java/operationBased/list_field_clash/type/AmenityCategory.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/java/operationBased/list_field_clash/type/AmenityCategory.java.expected @@ -10,6 +10,7 @@ import java.lang.Object; import java.lang.Override; import java.lang.String; import java.util.Arrays; +import java.util.Objects; public class AmenityCategory { public static EnumType type = new EnumType("AmenityCategory", Arrays.asList("Category0", "Category1")); @@ -20,12 +21,16 @@ public class AmenityCategory { public String rawValue; - public AmenityCategory(String rawValue) { + private AmenityCategory(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the AmenityCategory that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ public static AmenityCategory safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "Category0": return AmenityCategory.Category0; case "Category1": return AmenityCategory.Category1; default: return new AmenityCategory.UNKNOWN__(rawValue); @@ -36,44 +41,25 @@ public class AmenityCategory { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends AmenityCategory { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/kotlin/responseBased/list_field_clash/type/AmenityCategory.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/kotlin/responseBased/list_field_clash/type/AmenityCategory.kt.expected index 56361641878..d3d26b091b4 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/kotlin/responseBased/list_field_clash/type/AmenityCategory.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/list_field_clash/kotlin/responseBased/list_field_clash/type/AmenityCategory.kt.expected @@ -42,6 +42,11 @@ public enum class AmenityCategory( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [AmenityCategory] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): AmenityCategory = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/measurements b/libraries/apollo-compiler/src/test/graphql/com/example/measurements index 546fb3d603f..c2dcd19146a 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/measurements +++ b/libraries/apollo-compiler/src/test/graphql/com/example/measurements @@ -2,92 +2,92 @@ // If you updated the codegen and test fixtures, you should commit this file too. Test: Total LOC: -aggregate-all 204879 -aggregate-kotlin-responseBased 65795 -aggregate-kotlin-operationBased 42408 +aggregate-all 204708 +aggregate-kotlin-responseBased 65938 +aggregate-kotlin-operationBased 42453 aggregate-kotlin-compat 0 -aggregate-java-operationBased 96676 +aggregate-java-operationBased 96317 java-operationBased-fragments_with_defer_and_include_directives 5600 kotlin-operationBased-fragments_with_defer_and_include_directives 3488 java-operationBased-data_builders 3031 -java-operationBased-mutation_create_review 2435 -kotlin-responseBased-fragment_with_inline_fragment 2422 +kotlin-responseBased-fragment_with_inline_fragment 2427 +java-operationBased-mutation_create_review 2421 kotlin-responseBased-data_builders 2355 -java-operationBased-fragment_with_inline_fragment 2261 +java-operationBased-fragment_with_inline_fragment 2247 kotlin-operationBased-data_builders 2004 java-operationBased-nested_named_fragments 1910 java-operationBased-fragment_spread_with_include_directive 1667 -java-operationBased-union_inline_fragments 1666 +java-operationBased-union_inline_fragments 1652 kotlin-responseBased-nested_named_fragments 1643 -java-operationBased-unique_type_name 1643 -java-operationBased-inline_fragment_intersection 1637 -java-operationBased-input_object_type 1625 -java-operationBased-mutation_create_review_semantic_naming 1609 +java-operationBased-unique_type_name 1629 +java-operationBased-inline_fragment_intersection 1623 +java-operationBased-input_object_type 1611 java-operationBased-root_query_fragment_with_nested_fragments 1607 +java-operationBased-mutation_create_review_semantic_naming 1595 java-operationBased-simple_fragment 1505 java-operationBased-named_fragment_delegate 1493 -kotlin-responseBased-mutation_create_review 1454 +kotlin-responseBased-mutation_create_review 1459 java-operationBased-named_fragment_with_variables 1405 kotlin-responseBased-named_fragment_delegate 1371 -kotlin-responseBased-unique_type_name 1354 -java-operationBased-nested_conditional_inline 1344 +kotlin-responseBased-unique_type_name 1359 +java-operationBased-nested_conditional_inline 1330 java-operationBased-fragment_used_twice 1305 -kotlin-operationBased-fragment_with_inline_fragment 1297 +kotlin-operationBased-fragment_with_inline_fragment 1302 java-operationBased-multiple_fragments 1294 kotlin-responseBased-root_query_fragment_with_nested_fragments 1287 -kotlin-responseBased-input_object_type 1278 +kotlin-responseBased-input_object_type 1283 java-operationBased-nested_field_with_multiple_fieldsets 1271 kotlin-operationBased-nested_named_fragments 1269 -kotlin-responseBased-inline_fragment_intersection 1245 +kotlin-responseBased-inline_fragment_intersection 1250 java-operationBased-two_heroes_with_friends 1241 java-operationBased-inline_fragment_merge_fields 1229 kotlin-responseBased-simple_fragment 1195 -java-operationBased-named_fragment_inside_inline_fragment 1186 java-operationBased-fragments_with_type_condition 1183 -java-operationBased-target_name 1168 +java-operationBased-named_fragment_inside_inline_fragment 1172 +kotlin-operationBased-inline_fragment_intersection 1159 kotlin-responseBased-fragment_used_twice 1157 -kotlin-operationBased-inline_fragment_intersection 1154 java-operationBased-java_jetbrains_annotations 1154 +java-operationBased-target_name 1154 +kotlin-operationBased-union_inline_fragments 1152 +kotlin-responseBased-union_inline_fragments 1152 java-operationBased-java_android_annotations 1151 java-operationBased-java_jsr305_annotations 1151 -kotlin-operationBased-union_inline_fragments 1147 -kotlin-responseBased-union_inline_fragments 1147 java-operationBased-java_guava_optionals 1135 java-operationBased-java_java_optionals 1135 java-operationBased-java_apollo_optionals 1134 -java-operationBased-root_query_inline_fragment 1122 kotlin-operationBased-fragment_spread_with_include_directive 1121 -kotlin-operationBased-unique_type_name 1109 +kotlin-operationBased-unique_type_name 1114 +java-operationBased-root_query_inline_fragment 1108 kotlin-responseBased-fragments_with_type_condition 1102 -kotlin-responseBased-nested_conditional_inline 1085 +kotlin-responseBased-nested_conditional_inline 1090 java-operationBased-java_primitive_types 1077 kotlin-responseBased-multiple_fragments 1074 kotlin-responseBased-named_fragment_with_variables 1067 java-operationBased-simple_fragment_with_inline_fragments 1066 kotlin-operationBased-root_query_fragment_with_nested_fragments 1065 -java-operationBased-inline_fragments_with_friends 1056 java-operationBased-fragment_spread_with_nested_fields 1054 kotlin-responseBased-simple_fragment_with_inline_fragments 1052 kotlin-operationBased-simple_fragment 1043 +java-operationBased-inline_fragments_with_friends 1042 java-operationBased-operationbased2_ex8 1042 kotlin-operationBased-named_fragment_delegate 1013 java-operationBased-decapitalized_fields 993 java-operationBased-simple_union 975 java-operationBased-fragments_same_type_condition 973 kotlin-responseBased-operationbased2_ex8 961 +kotlin-operationBased-nested_conditional_inline 953 java-operationBased-deprecated_merged_field 950 -kotlin-operationBased-nested_conditional_inline 948 java-operationBased-input_object_oneof 943 -java-operationBased-hero_details 941 java-operationBased-used_arguments 941 java-operationBased-not_all_combinations_are_needed 938 +java-operationBased-hero_details 927 +kotlin-responseBased-mutation_create_review_semantic_naming 923 java-operationBased-simple_inline_fragment 919 -kotlin-responseBased-mutation_create_review_semantic_naming 918 kotlin-operationBased-named_fragment_with_variables 918 java-operationBased-fieldset_with_multiple_super 915 -java-operationBased-introspection_query 915 java-operationBased-inline_fragment_with_include_directive 913 +java-operationBased-introspection_query 901 java-operationBased-union_fragment 898 kotlin-operationBased-fragment_used_twice 893 java-operationBased-inline_fragment_inside_inline_fragment 883 @@ -97,34 +97,34 @@ kotlin-operationBased-multiple_fragments kotlin-responseBased-nested_field_with_multiple_fieldsets 844 java-operationBased-named_fragment_without_implementation 840 kotlin-operationBased-fragments_with_type_condition 833 -kotlin-responseBased-target_name 817 +kotlin-responseBased-target_name 822 kotlin-operationBased-nested_field_with_multiple_fieldsets 814 +kotlin-operationBased-named_fragment_inside_inline_fragment 809 kotlin-responseBased-two_heroes_with_friends 808 java-operationBased-fragment_with_multiple_fieldsets 804 -kotlin-operationBased-named_fragment_inside_inline_fragment 804 java-operationBased-hero_details_semantic_naming 803 kotlin-operationBased-inline_fragment_merge_fields 799 java-operationBased-operationbased2_ex7 798 -java-operationBased-suppressed_warnings 797 -kotlin-operationBased-root_query_inline_fragment 793 -kotlin-responseBased-inline_fragments_with_friends 790 -kotlin-operationBased-target_name 789 +kotlin-operationBased-root_query_inline_fragment 798 +kotlin-responseBased-inline_fragments_with_friends 795 +kotlin-operationBased-target_name 794 +kotlin-responseBased-named_fragment_inside_inline_fragment 790 kotlin-responseBased-deprecated_merged_field 786 -kotlin-responseBased-named_fragment_inside_inline_fragment 785 +java-operationBased-suppressed_warnings 783 java-operationBased-path_vs_flat_accessors 776 +kotlin-responseBased-root_query_inline_fragment 774 java-operationBased-reserved_keywords 772 -kotlin-responseBased-root_query_inline_fragment 769 kotlin-responseBased-simple_union 769 java-operationBased-typename_always_first 754 -kotlin-operationBased-inline_fragments_with_friends 739 +kotlin-operationBased-inline_fragments_with_friends 744 kotlin-responseBased-fragments_same_type_condition 738 -java-operationBased-input_object_variable_and_argument 736 -java-operationBased-input_object_variable_and_argument_with_generated_methods 736 java-operationBased-interface_on_interface 736 +java-operationBased-input_object_variable_and_argument 722 +java-operationBased-input_object_variable_and_argument_with_generated_methods 722 java-operationBased-root_query_fragment 717 kotlin-operationBased-simple_fragment_with_inline_fragments 714 kotlin-operationBased-fragment_spread_with_nested_fields 705 -kotlin-responseBased-input_object_variable_and_argument_with_generated_methods 693 +kotlin-responseBased-input_object_variable_and_argument_with_generated_methods 698 java-operationBased-monomorphic 689 kotlin-operationBased-operationbased2_ex8 685 java-operationBased-interface_always_nested 683 @@ -138,57 +138,57 @@ kotlin-responseBased-java_jetbrains_annotations kotlin-responseBased-java_jsr305_annotations 674 kotlin-operationBased-fragments_same_type_condition 667 java-operationBased-capitalized_fields 666 -java-operationBased-hero_with_review 666 kotlin-operationBased-simple_union 665 java-operationBased-recursive_selection 661 -java-operationBased-deprecation 659 kotlin-responseBased-fragment_with_multiple_fieldsets 659 kotlin-responseBased-test_inline 657 +kotlin-responseBased-hero_details 652 +java-operationBased-hero_with_review 652 kotlin-responseBased-named_fragment_without_implementation 651 kotlin-operationBased-used_arguments 651 kotlin-operationBased-union_fragment 650 kotlin-operationBased-decapitalized_fields 647 -kotlin-responseBased-hero_details 647 kotlin-operationBased-deprecated_merged_field 646 +java-operationBased-deprecation 645 kotlin-operationBased-inline_fragment_inside_inline_fragment 645 -java-operationBased-hero_name_query_long_name 641 kotlin-responseBased-inline_fragment_inside_inline_fragment 639 java-operationBased-field_with_include_directive 638 -java-operationBased-variable_default_value 638 java-operationBased-custom_scalar_type 637 kotlin-operationBased-not_all_combinations_are_needed 637 kotlin-responseBased-java_primitive_types 636 kotlin-responseBased-inline_fragment_merge_fields 629 +java-operationBased-hero_name_query_long_name 627 kotlin-operationBased-inline_fragment_with_include_directive 627 java-operationBased-hero_name 626 +java-operationBased-variable_default_value 624 kotlin-operationBased-fieldset_with_multiple_super 620 +kotlin-responseBased-introspection_query 620 kotlin-operationBased-simple_inline_fragment 618 kotlin-operationBased-named_fragment_without_implementation 616 kotlin-responseBased-operationbased2_ex7 616 -kotlin-responseBased-introspection_query 615 java-operationBased-java8annotation 614 kotlin-responseBased-not_all_combinations_are_needed 612 kotlin-responseBased-simple_inline_fragment 611 kotlin-responseBased-decapitalized_fields 610 +kotlin-responseBased-input_object_variable_and_argument 609 kotlin-responseBased-fieldset_with_multiple_super 607 -java-operationBased-optional 607 -kotlin-responseBased-input_object_variable_and_argument 604 java-operationBased-inline_fragment_for_non_optional_field 602 kotlin-responseBased-reserved_keywords 600 -java-operationBased-enum_field 595 +java-operationBased-optional 593 java-operationBased-two_heroes_unique 591 java-operationBased-inline_fragment_type_coercion 587 +java-operationBased-enum_field 586 kotlin-operationBased-test_inline 581 -java-operationBased-list_field_clash 576 java-operationBased-inline_fragment_simple 573 kotlin-operationBased-reserved_keywords 573 +java-operationBased-list_field_clash 562 kotlin-responseBased-path_vs_flat_accessors 558 -kotlin-responseBased-hero_with_review 551 +kotlin-responseBased-hero_with_review 556 kotlin-responseBased-hero_details_semantic_naming 548 +kotlin-responseBased-suppressed_warnings 547 kotlin-operationBased-fragment_with_multiple_fieldsets 543 java-operationBased-starships 543 kotlin-responseBased-root_query_fragment 542 -kotlin-responseBased-suppressed_warnings 542 kotlin-responseBased-interface_on_interface 541 kotlin-responseBased-input_object_oneof 539 kotlin-responseBased-typename_always_first 539 @@ -198,37 +198,37 @@ kotlin-operationBased-typename_always_first kotlin-operationBased-path_vs_flat_accessors 527 java-operationBased-antlr_tokens 526 java-operationBased-subscriptions 525 +kotlin-responseBased-hero_name_query_long_name 519 kotlin-operationBased-interface_on_interface 515 -kotlin-responseBased-hero_name_query_long_name 514 kotlin-responseBased-hero_name 512 kotlin-responseBased-interface_always_nested 502 kotlin-responseBased-custom_scalar_type 497 +kotlin-responseBased-variable_default_value 493 kotlin-operationBased-root_query_fragment 491 -kotlin-responseBased-variable_default_value 488 -kotlin-responseBased-deprecation 483 +kotlin-responseBased-deprecation 488 +kotlin-responseBased-enum_field 479 java-operationBased-merged_include 478 java-operationBased-operation_id_generator 478 kotlin-responseBased-inline_fragment_for_non_optional_field 477 kotlin-operationBased-monomorphic 475 kotlin-responseBased-monomorphic 475 kotlin-operationBased-interface_always_nested 474 -kotlin-responseBased-enum_field 469 -java-operationBased-enums_as_sealed 465 -java-operationBased-case_sensitive_enum 462 -kotlin-responseBased-optional 460 +kotlin-responseBased-optional 465 java-operationBased-nonnull 457 kotlin-operationBased-hero_name 455 kotlin-operationBased-capitalized_fields 454 kotlin-responseBased-field_with_include_directive 453 +java-operationBased-enums_as_sealed 451 java-operationBased-companion 449 +java-operationBased-case_sensitive_enum 448 kotlin-responseBased-inline_fragment_type_coercion 448 java-operationBased-object 444 kotlin-responseBased-recursive_selection 439 kotlin-operationBased-inline_fragment_for_non_optional_field 434 kotlin-responseBased-inline_fragment_simple 433 kotlin-responseBased-arguments_hardcoded 429 +kotlin-responseBased-list_field_clash 423 kotlin-responseBased-two_heroes_unique 419 -kotlin-responseBased-list_field_clash 418 kotlin-responseBased-capitalized_fields 416 kotlin-operationBased-inline_fragment_type_coercion 413 kotlin-operationBased-inline_fragment_simple 406 @@ -236,12 +236,12 @@ kotlin-responseBased-starships kotlin-responseBased-java8annotation 403 kotlin-responseBased-antlr_tokens 398 kotlin-responseBased-subscriptions 391 -kotlin-responseBased-enums_as_sealed 364 +kotlin-responseBased-enums_as_sealed 377 +kotlin-responseBased-case_sensitive_enum 347 kotlin-responseBased-operation_id_generator 346 kotlin-responseBased-big_query 344 kotlin-responseBased-merged_include 344 java-operationBased-java_hashcode 343 -kotlin-responseBased-case_sensitive_enum 342 kotlin-responseBased-nonnull 328 kotlin-operationBased-companion 321 kotlin-responseBased-object 319 diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/Episode.java.expected index 31170603a60..b8b87a290af 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/java/operationBased/mutation_create_review/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/Episode.kt.expected index bfbc08e09b9..7f31bf51849 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review/kotlin/responseBased/mutation_create_review/type/Episode.kt.expected @@ -71,6 +71,11 @@ internal enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/Episode.java.expected index 515ef40fc30..6d6eb3b8e47 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/java/operationBased/mutation_create_review_semantic_naming/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/Episode.kt.expected index dc124b4e44a..635cb849fb9 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/mutation_create_review_semantic_naming/kotlin/responseBased/mutation_create_review_semantic_naming/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/type/Episode.java.expected index 75668d9bb66..e3edaeb53eb 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/java/operationBased/named_fragment_inside_inline_fragment/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/operationBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/operationBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected index 05c17097db2..a7cd53c9b50 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/operationBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/operationBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/responseBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/responseBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected index 05c17097db2..a7cd53c9b50 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/responseBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/named_fragment_inside_inline_fragment/kotlin/responseBased/named_fragment_inside_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/type/Episode.java.expected index 8d9fe106c83..7d52a0d0981 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/java/operationBased/nested_conditional_inline/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/operationBased/nested_conditional_inline/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/operationBased/nested_conditional_inline/type/Episode.kt.expected index a8636ec63ea..ccca391cf02 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/operationBased/nested_conditional_inline/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/operationBased/nested_conditional_inline/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/nested_conditional_inline/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/nested_conditional_inline/type/Episode.kt.expected index a8636ec63ea..ccca391cf02 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/nested_conditional_inline/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/nested_conditional_inline/kotlin/responseBased/nested_conditional_inline/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/type/Episode.java.expected index d857a98e65b..b174cc3a003 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/optional/java/operationBased/optional/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/optional/kotlin/responseBased/optional/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/optional/kotlin/responseBased/optional/type/Episode.kt.expected index 370ec8951f1..d8e23dc27a9 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/optional/kotlin/responseBased/optional/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/optional/kotlin/responseBased/optional/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/type/Episode.java.expected index dd2f87521f4..cdb6d742617 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/java/operationBased/root_query_inline_fragment/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/operationBased/root_query_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/operationBased/root_query_inline_fragment/type/Episode.kt.expected index cf37874373a..caf879bf6dd 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/operationBased/root_query_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/operationBased/root_query_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/responseBased/root_query_inline_fragment/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/responseBased/root_query_inline_fragment/type/Episode.kt.expected index cf37874373a..caf879bf6dd 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/responseBased/root_query_inline_fragment/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/root_query_inline_fragment/kotlin/responseBased/root_query_inline_fragment/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/java/operationBased/suppressed_warnings/type/Direction.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/java/operationBased/suppressed_warnings/type/Direction.java.expected index ece3ac2613f..b7939885c2f 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/java/operationBased/suppressed_warnings/type/Direction.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/java/operationBased/suppressed_warnings/type/Direction.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; public class Direction { public static EnumType type = new EnumType("Direction", Arrays.asList("South", "North", "East")); @@ -23,13 +24,17 @@ public class Direction { public String rawValue; - public Direction(String rawValue) { + private Direction(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Direction that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Direction safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "South": return Direction.South; case "North": return Direction.North; case "East": return Direction.East; @@ -41,44 +46,25 @@ public class Direction { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Direction { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/kotlin/responseBased/suppressed_warnings/type/Direction.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/kotlin/responseBased/suppressed_warnings/type/Direction.kt.expected index 93f7de18aa1..01eb9589f49 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/kotlin/responseBased/suppressed_warnings/type/Direction.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/suppressed_warnings/kotlin/responseBased/suppressed_warnings/type/Direction.kt.expected @@ -51,6 +51,11 @@ public enum class Direction( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Direction] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Direction = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedEnum.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedEnum.java.expected index 5f1489070fe..686b79a32f5 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedEnum.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/java/operationBased/target_name/type/renamedEnum.java.expected @@ -10,6 +10,7 @@ import java.lang.Object; import java.lang.Override; import java.lang.String; import java.util.Arrays; +import java.util.Objects; public class RenamedEnum { public static EnumType type = new EnumType("ReservedEnum", Arrays.asList("VALUE")); @@ -18,12 +19,16 @@ public class RenamedEnum { public String rawValue; - public RenamedEnum(String rawValue) { + private RenamedEnum(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the ReservedEnum that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ public static RenamedEnum safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "VALUE": return RenamedEnum.VALUE; default: return new RenamedEnum.UNKNOWN__(rawValue); } @@ -33,44 +38,25 @@ public class RenamedEnum { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends RenamedEnum { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/operationBased/target_name/type/renamedEnum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/operationBased/target_name/type/renamedEnum.kt.expected index d474a7907b2..b54cae02646 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/operationBased/target_name/type/renamedEnum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/operationBased/target_name/type/renamedEnum.kt.expected @@ -40,6 +40,11 @@ public enum class RenamedEnum( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [RenamedEnum] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): RenamedEnum = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/responseBased/target_name/type/renamedEnum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/responseBased/target_name/type/renamedEnum.kt.expected index d474a7907b2..b54cae02646 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/responseBased/target_name/type/renamedEnum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/target_name/kotlin/responseBased/target_name/type/renamedEnum.kt.expected @@ -40,6 +40,11 @@ public enum class RenamedEnum( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [RenamedEnum] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): RenamedEnum = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/type/Episode.java.expected index 6b56d6b248d..bd561137530 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/java/operationBased/union_inline_fragments/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/operationBased/union_inline_fragments/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/operationBased/union_inline_fragments/type/Episode.kt.expected index 3d7dbba159e..19ebdf4be6b 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/operationBased/union_inline_fragments/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/operationBased/union_inline_fragments/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/responseBased/union_inline_fragments/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/responseBased/union_inline_fragments/type/Episode.kt.expected index 3d7dbba159e..19ebdf4be6b 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/responseBased/union_inline_fragments/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/union_inline_fragments/kotlin/responseBased/union_inline_fragments/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/type/Episode.java.expected index 34a1a9e4411..b14c92bda7d 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/java/operationBased/unique_type_name/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/operationBased/unique_type_name/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/operationBased/unique_type_name/type/Episode.kt.expected index e725a0b8ace..95f92c82d37 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/operationBased/unique_type_name/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/operationBased/unique_type_name/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/responseBased/unique_type_name/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/responseBased/unique_type_name/type/Episode.kt.expected index e725a0b8ace..95f92c82d37 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/responseBased/unique_type_name/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/unique_type_name/kotlin/responseBased/unique_type_name/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/type/Episode.java.expected b/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/type/Episode.java.expected index c4c11b86e19..54fb688e079 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/type/Episode.java.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/java/operationBased/variable_default_value/type/Episode.java.expected @@ -11,6 +11,7 @@ import java.lang.Override; import java.lang.String; import java.lang.SuppressWarnings; import java.util.Arrays; +import java.util.Objects; /** * The episodes in the Star Wars trilogy @@ -30,13 +31,17 @@ public class Episode { public String rawValue; - public Episode(String rawValue) { + private Episode(String rawValue) { this.rawValue = rawValue; } + /** + * Returns the Episode that represents the specified rawValue. + * Note: unknown values of rawValue will return UNKNOWN__. You may want to update your schema instead of calling this method directly. + */ @SuppressWarnings("deprecation") public static Episode safeValueOf(String rawValue) { - switch(rawValue) { + switch (Objects.requireNonNull(rawValue)) { case "NEWHOPE": return Episode.NEWHOPE; case "EMPIRE": return Episode.EMPIRE; case "JEDI": return Episode.JEDI; @@ -50,44 +55,25 @@ public class Episode { * An enum value that wasn't known at compile time. */ public static class UNKNOWN__ extends Episode { - private transient volatile int $hashCode; - - private transient volatile boolean $hashCodeMemoized; - - private transient volatile String $toString; - - public UNKNOWN__(String rawValue) { + private UNKNOWN__(String rawValue) { super(rawValue); } @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } - if (o instanceof UNKNOWN__) { - return true; - } - return false; + public boolean equals(Object other) { + if (this == other) return true; + if (!(other instanceof UNKNOWN__)) return false; + return rawValue.equals(((UNKNOWN__) other).rawValue); } @Override public int hashCode() { - if (!$hashCodeMemoized) { - int __h = 1; - $hashCode = __h; - $hashCodeMemoized = true; - } - return $hashCode; + return rawValue.hashCode(); } @Override public String toString() { - if ($toString == null) { - $toString = "UNKNOWN__{" - + "}"; - } - return $toString; + return "UNKNOWN__(" + rawValue + ")"; } } } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/kotlin/responseBased/variable_default_value/type/Episode.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/kotlin/responseBased/variable_default_value/type/Episode.kt.expected index a64f9c51c55..cbdebe68c53 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/kotlin/responseBased/variable_default_value/type/Episode.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/variable_default_value/kotlin/responseBased/variable_default_value/type/Episode.kt.expected @@ -71,6 +71,11 @@ public enum class Episode( ) public fun knownValues(): Array = knownEntries.toTypedArray() + /** + * Returns the [Episode] that represents the specified [rawValue]. + * Note: unknown values of [rawValue] will return [UNKNOWN__]. You may want to update your + * schema instead of calling this function directly. + */ public fun safeValueOf(rawValue: String): Episode = values().find { it.rawValue == rawValue } ?: UNKNOWN__ } diff --git a/tests/enums/src/test/kotlin/test/EnumsTest.kt b/tests/enums/src/test/kotlin/test/EnumsTest.kt index 4b5606d5647..7c1077da4f2 100644 --- a/tests/enums/src/test/kotlin/test/EnumsTest.kt +++ b/tests/enums/src/test/kotlin/test/EnumsTest.kt @@ -7,6 +7,9 @@ import enums.kotlin15.type.FooSealed import enums.kotlin15.type.Gravity import org.junit.Test import kotlin.test.assertEquals +import kotlin.test.assertFails +import kotlin.test.assertIs +import kotlin.test.assertNotEquals class EnumsTest { @Test @@ -31,7 +34,7 @@ class EnumsTest { assertEquals(Gravity.TOP, Gravity.safeValueOf("TOP")) @Suppress("DEPRECATION") assertEquals(Gravity.top2, Gravity.safeValueOf("top2")) - assertEquals(Gravity.UNKNOWN__("newGravity"), Gravity.safeValueOf("newGravity")) + assertIs(Gravity.safeValueOf("newGravity")) assertEquals(Gravity.name, Gravity.safeValueOf("name")) assertEquals(Gravity.ordinal, Gravity.safeValueOf("ordinal")) assertEquals(Gravity.type__, Gravity.safeValueOf("type")) @@ -48,17 +51,31 @@ class EnumsTest { assertEquals(enums.java.type.Direction.ordinal, enums.java.type.Direction.safeValueOf("ordinal")) assertEquals(enums.java.type.Direction.type__, enums.java.type.Direction.safeValueOf("type")) assertEquals(enums.java.type.Direction.Companion, enums.java.type.Direction.safeValueOf("Companion")) + assertIs( + assertFails { + enums.java.type.Direction.safeValueOf(null) + } + ) } @Test fun javaClasses() { assertEquals(enums.java.type.Gravity.TOP, enums.java.type.Gravity.safeValueOf("TOP")) assertEquals(enums.java.type.Gravity.top2, enums.java.type.Gravity.safeValueOf("top2")) - assertEquals(enums.java.type.Gravity.UNKNOWN__("newGravity"), enums.java.type.Gravity.safeValueOf("newGravity")) + val unknown = enums.java.type.Gravity.safeValueOf("newGravity") + assertEquals(enums.java.type.Gravity.UNKNOWN__::class.java, unknown::class.java) + assertEquals("newGravity", unknown.rawValue) + assertEquals(enums.java.type.Gravity.safeValueOf("newGravity"), unknown) + assertNotEquals(enums.java.type.Gravity.safeValueOf("newGravity2"), unknown) assertEquals(enums.java.type.Gravity.name, enums.java.type.Gravity.safeValueOf("name")) assertEquals(enums.java.type.Gravity.ordinal, enums.java.type.Gravity.safeValueOf("ordinal")) assertEquals(enums.java.type.Gravity.type__, enums.java.type.Gravity.safeValueOf("type")) assertEquals(enums.java.type.Gravity.Companion, enums.java.type.Gravity.safeValueOf("Companion")) + assertIs( + assertFails { + enums.java.type.Gravity.safeValueOf(null) + } + ) } diff --git a/tests/integration-tests/src/commonTest/kotlin/test/EnumTest.kt b/tests/integration-tests/src/commonTest/kotlin/test/EnumTest.kt index b9bd9eb3068..e9c203c2103 100644 --- a/tests/integration-tests/src/commonTest/kotlin/test/EnumTest.kt +++ b/tests/integration-tests/src/commonTest/kotlin/test/EnumTest.kt @@ -3,14 +3,12 @@ package test import com.apollographql.apollo3.integration.normalizer.type.Episode import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertIs class EnumTest { @Test fun safeValueOf() { assertEquals(Episode.EMPIRE, Episode.safeValueOf("EMPIRE")) - - // Note: Episode is generated as a sealed class (sealedClassesForEnumsMatching) for this - // to work both with Kotlin and Java codegens - assertEquals(Episode.UNKNOWN__("NEW_EPISODE"), Episode.safeValueOf("NEW_EPISODE")) + assertIs(Episode.safeValueOf("NEW_EPISODE")) } }