diff --git a/wire-golden-files/src/main/kotlin/squareup/wire/alltypes/AllTypes.kt b/wire-golden-files/src/main/kotlin/squareup/wire/alltypes/AllTypes.kt index 5f42778d51..e68ae208b5 100644 --- a/wire-golden-files/src/main/kotlin/squareup/wire/alltypes/AllTypes.kt +++ b/wire-golden-files/src/main/kotlin/squareup/wire/alltypes/AllTypes.kt @@ -808,7 +808,7 @@ public class AllTypes private constructor( @field:WireField( tag = 601, - adapter = "com.squareup.wire.ProtoAdapter#INT32", + adapter = "com.squareup.wire.ProtoAdapter#INT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 85, ) @@ -817,7 +817,7 @@ public class AllTypes private constructor( @field:WireField( tag = 602, - adapter = "com.squareup.wire.ProtoAdapter#UINT32", + adapter = "com.squareup.wire.ProtoAdapter#UINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 86, ) @@ -826,7 +826,7 @@ public class AllTypes private constructor( @field:WireField( tag = 603, - adapter = "com.squareup.wire.ProtoAdapter#SINT32", + adapter = "com.squareup.wire.ProtoAdapter#SINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 87, ) @@ -835,7 +835,7 @@ public class AllTypes private constructor( @field:WireField( tag = 604, - adapter = "com.squareup.wire.ProtoAdapter#FIXED32", + adapter = "com.squareup.wire.ProtoAdapter#FIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 88, ) @@ -844,7 +844,7 @@ public class AllTypes private constructor( @field:WireField( tag = 605, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED32", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 89, ) @@ -853,7 +853,7 @@ public class AllTypes private constructor( @field:WireField( tag = 606, - adapter = "com.squareup.wire.ProtoAdapter#INT64", + adapter = "com.squareup.wire.ProtoAdapter#INT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 90, ) @@ -862,7 +862,7 @@ public class AllTypes private constructor( @field:WireField( tag = 607, - adapter = "com.squareup.wire.ProtoAdapter#UINT64", + adapter = "com.squareup.wire.ProtoAdapter#UINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 91, ) @@ -871,7 +871,7 @@ public class AllTypes private constructor( @field:WireField( tag = 608, - adapter = "com.squareup.wire.ProtoAdapter#SINT64", + adapter = "com.squareup.wire.ProtoAdapter#SINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 92, ) @@ -880,7 +880,7 @@ public class AllTypes private constructor( @field:WireField( tag = 609, - adapter = "com.squareup.wire.ProtoAdapter#FIXED64", + adapter = "com.squareup.wire.ProtoAdapter#FIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 93, ) @@ -889,7 +889,7 @@ public class AllTypes private constructor( @field:WireField( tag = 610, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED64", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 94, ) @@ -898,7 +898,7 @@ public class AllTypes private constructor( @field:WireField( tag = 611, - adapter = "com.squareup.wire.ProtoAdapter#FLOAT", + adapter = "com.squareup.wire.ProtoAdapter#FLOAT_ARRAY", label = WireField.Label.PACKED, schemaIndex = 95, ) @@ -907,7 +907,7 @@ public class AllTypes private constructor( @field:WireField( tag = 612, - adapter = "com.squareup.wire.ProtoAdapter#DOUBLE", + adapter = "com.squareup.wire.ProtoAdapter#DOUBLE_ARRAY", label = WireField.Label.PACKED, schemaIndex = 96, ) diff --git a/wire-golden-files/src/main/kotlin/squareup/wire/repeateddata/ParameterValueWithArray.kt b/wire-golden-files/src/main/kotlin/squareup/wire/repeateddata/ParameterValueWithArray.kt index c9a407d150..ed26ec33c5 100644 --- a/wire-golden-files/src/main/kotlin/squareup/wire/repeateddata/ParameterValueWithArray.kt +++ b/wire-golden-files/src/main/kotlin/squareup/wire/repeateddata/ParameterValueWithArray.kt @@ -29,7 +29,7 @@ import okio.ByteString public class ParameterValueWithArray( @field:WireField( tag = 1, - adapter = "com.squareup.wire.ProtoAdapter#FLOAT", + adapter = "com.squareup.wire.ProtoAdapter#FLOAT_ARRAY", label = WireField.Label.PACKED, declaredName = "data", schemaIndex = 0, diff --git a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java index 66870453fa..31f7a22208 100644 --- a/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java +++ b/wire-java-generator/src/main/java/com/squareup/wire/java/JavaGenerator.java @@ -1606,7 +1606,7 @@ private AnnotationSpec wireFieldAnnotation( } private String adapterString(ProtoType type) { - String builtInAdapterString = builtInAdapterString(type); + String builtInAdapterString = builtInAdapterString(type, false); if (builtInAdapterString != null) { return builtInAdapterString; } diff --git a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt index 0d4a2ed3f1..07d67feec8 100644 --- a/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt +++ b/wire-kotlin-generator/src/main/java/com/squareup/wire/kotlin/KotlinGenerator.kt @@ -1258,7 +1258,7 @@ class KotlinGenerator private constructor( addMember("keyAdapter = %S", field.type!!.keyType!!.adapterString()) addMember("adapter = %S", field.type!!.valueType!!.adapterString()) } else { - addMember("adapter = %S", field.type!!.adapterString()) + addMember("adapter = %S", field.type!!.adapterString(field.useArray)) } } .apply { @@ -2169,13 +2169,13 @@ class KotlinGenerator private constructor( } } - private fun ProtoType.adapterString(): String { + private fun ProtoType.adapterString(useArray: Boolean = false): String { val adapterConstant = profile.getAdapter(this) if (adapterConstant != null) { return "${adapterConstant.javaClassName.reflectionName()}#${adapterConstant.memberName}" } - val builtInAdapterString = builtInAdapterString(this) + val builtInAdapterString = builtInAdapterString(this, useArray) if (builtInAdapterString != null) return builtInAdapterString return (typeName as ClassName).reflectionName() + "#ADAPTER" diff --git a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt index 5dbda7c3b0..73c6852fdf 100644 --- a/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt +++ b/wire-kotlin-generator/src/test/java/com/squareup/wire/kotlin/KotlinGeneratorTest.kt @@ -1579,7 +1579,7 @@ class KotlinGeneratorTest { |import "wire/extensions.proto"; | |message Person { - | repeated float info = 1 [packed = true, (wire.use_array) = true]; + | repeated float info = 1 [packed = true, (wire.use_array) = true]; |} | """.trimMargin(), diff --git a/wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/kotlin/buildersonly/builders_only_message.proto b/wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/kotlin/buildersonly/builders_only_message.proto index 342cb487ad..9905606f83 100644 --- a/wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/kotlin/buildersonly/builders_only_message.proto +++ b/wire-protoc-compatibility-tests/src/main/proto/squareup/proto2/kotlin/buildersonly/builders_only_message.proto @@ -27,7 +27,7 @@ message BuildersOnlyMessage { required int32 data = 2; repeated int32 message = 3; optional NestedMessage nested_message = 4; - repeated int64 int64 = 5 [packed = true, (wire.use_array) = true]; + repeated int64 int64 = 5 [packed = true, (wire.use_array) = false]; map map = 10; oneof oneof { int32 int32 = 15; diff --git a/wire-schema/api/wire-schema.api b/wire-schema/api/wire-schema.api index a3ce331063..cac0e1bc9d 100644 --- a/wire-schema/api/wire-schema.api +++ b/wire-schema/api/wire-schema.api @@ -1019,6 +1019,8 @@ public final class com/squareup/wire/schema/internal/JvmLanguages { public static final fun annotationName (Lcom/squareup/wire/schema/ProtoFile;Lcom/squareup/wire/schema/Field;Lcom/squareup/wire/schema/internal/NameFactory;)Ljava/lang/Object; public static final fun annotationTargetType (Lcom/squareup/wire/schema/Extend;)Ljava/lang/annotation/ElementType; public static final fun builtInAdapterString (Lcom/squareup/wire/schema/ProtoType;)Ljava/lang/String; + public static final fun builtInAdapterString (Lcom/squareup/wire/schema/ProtoType;Z)Ljava/lang/String; + public static synthetic fun builtInAdapterString$default (Lcom/squareup/wire/schema/ProtoType;ZILjava/lang/Object;)Ljava/lang/String; public static final fun eligibleAsAnnotationMember (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Field;)Z public static final fun hasEponymousType (Lcom/squareup/wire/schema/Schema;Lcom/squareup/wire/schema/Field;)Z public static final fun javaPackage (Lcom/squareup/wire/schema/ProtoFile;)Ljava/lang/String; diff --git a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt index 3ebd7cacd9..8068371716 100644 --- a/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt +++ b/wire-schema/src/jvmMain/kotlin/com/squareup/wire/schema/internal/JvmLanguages.kt @@ -37,8 +37,27 @@ import java.util.Locale * one language and other parts in another language. */ -fun builtInAdapterString(type: ProtoType): String? { +@JvmOverloads +fun builtInAdapterString(type: ProtoType, useArray: Boolean = false): String? { if (type.isScalar) { + if (useArray) { + return when (type) { + ProtoType.INT32 -> ProtoAdapter::class.java.name + "#INT32_ARRAY" + ProtoType.UINT32 -> ProtoAdapter::class.java.name + "#UINT32_ARRAY" + ProtoType.SINT32 -> ProtoAdapter::class.java.name + "#SINT32_ARRAY" + ProtoType.FIXED32 -> ProtoAdapter::class.java.name + "#FIXED32_ARRAY" + ProtoType.SFIXED32 -> ProtoAdapter::class.java.name + "#SFIXED32_ARRAY" + ProtoType.INT64 -> ProtoAdapter::class.java.name + "#INT64_ARRAY" + ProtoType.UINT64 -> ProtoAdapter::class.java.name + "#UINT64_ARRAY" + ProtoType.SINT64 -> ProtoAdapter::class.java.name + "#SINT64_ARRAY" + ProtoType.FIXED64 -> ProtoAdapter::class.java.name + "#FIXED64_ARRAY" + ProtoType.SFIXED64 -> ProtoAdapter::class.java.name + "#SFIXED64_ARRAY" + ProtoType.FLOAT -> ProtoAdapter::class.java.name + "#FLOAT_ARRAY" + ProtoType.DOUBLE -> ProtoAdapter::class.java.name + "#DOUBLE_ARRAY" + else -> throw IllegalArgumentException("No Array adapter for $type") + } + } + return "${ProtoAdapter::class.java.name}#${type.toString().uppercase(Locale.US)}" } return when (type) { diff --git a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt index 272e6315a6..4886baae67 100644 --- a/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt +++ b/wire-tests/src/commonTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt @@ -422,84 +422,84 @@ public class AllTypes( map_string_enum: Map = emptyMap(), @field:WireField( tag = 601, - adapter = "com.squareup.wire.ProtoAdapter#INT32", + adapter = "com.squareup.wire.ProtoAdapter#INT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 85, ) public val array_int32: IntArray = intArrayOf(), @field:WireField( tag = 602, - adapter = "com.squareup.wire.ProtoAdapter#UINT32", + adapter = "com.squareup.wire.ProtoAdapter#UINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 86, ) public val array_uint32: IntArray = intArrayOf(), @field:WireField( tag = 603, - adapter = "com.squareup.wire.ProtoAdapter#SINT32", + adapter = "com.squareup.wire.ProtoAdapter#SINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 87, ) public val array_sint32: IntArray = intArrayOf(), @field:WireField( tag = 604, - adapter = "com.squareup.wire.ProtoAdapter#FIXED32", + adapter = "com.squareup.wire.ProtoAdapter#FIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 88, ) public val array_fixed32: IntArray = intArrayOf(), @field:WireField( tag = 605, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED32", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 89, ) public val array_sfixed32: IntArray = intArrayOf(), @field:WireField( tag = 606, - adapter = "com.squareup.wire.ProtoAdapter#INT64", + adapter = "com.squareup.wire.ProtoAdapter#INT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 90, ) public val array_int64: LongArray = longArrayOf(), @field:WireField( tag = 607, - adapter = "com.squareup.wire.ProtoAdapter#UINT64", + adapter = "com.squareup.wire.ProtoAdapter#UINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 91, ) public val array_uint64: LongArray = longArrayOf(), @field:WireField( tag = 608, - adapter = "com.squareup.wire.ProtoAdapter#SINT64", + adapter = "com.squareup.wire.ProtoAdapter#SINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 92, ) public val array_sint64: LongArray = longArrayOf(), @field:WireField( tag = 609, - adapter = "com.squareup.wire.ProtoAdapter#FIXED64", + adapter = "com.squareup.wire.ProtoAdapter#FIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 93, ) public val array_fixed64: LongArray = longArrayOf(), @field:WireField( tag = 610, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED64", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 94, ) public val array_sfixed64: LongArray = longArrayOf(), @field:WireField( tag = 611, - adapter = "com.squareup.wire.ProtoAdapter#FLOAT", + adapter = "com.squareup.wire.ProtoAdapter#FLOAT_ARRAY", label = WireField.Label.PACKED, schemaIndex = 95, ) public val array_float: FloatArray = floatArrayOf(), @field:WireField( tag = 612, - adapter = "com.squareup.wire.ProtoAdapter#DOUBLE", + adapter = "com.squareup.wire.ProtoAdapter#DOUBLE_ARRAY", label = WireField.Label.PACKED, schemaIndex = 96, ) diff --git a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt index f8b21c9af5..841d562191 100644 --- a/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt +++ b/wire-tests/src/jvmKotlinInteropTest/proto-kotlin/com/squareup/wire/protos/kotlin/alltypes/AllTypes.kt @@ -469,7 +469,7 @@ public class AllTypes( map_string_enum: Map = emptyMap(), @field:WireField( tag = 601, - adapter = "com.squareup.wire.ProtoAdapter#INT32", + adapter = "com.squareup.wire.ProtoAdapter#INT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 85, ) @@ -477,7 +477,7 @@ public class AllTypes( public val array_int32: IntArray = intArrayOf(), @field:WireField( tag = 602, - adapter = "com.squareup.wire.ProtoAdapter#UINT32", + adapter = "com.squareup.wire.ProtoAdapter#UINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 86, ) @@ -485,7 +485,7 @@ public class AllTypes( public val array_uint32: IntArray = intArrayOf(), @field:WireField( tag = 603, - adapter = "com.squareup.wire.ProtoAdapter#SINT32", + adapter = "com.squareup.wire.ProtoAdapter#SINT32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 87, ) @@ -493,7 +493,7 @@ public class AllTypes( public val array_sint32: IntArray = intArrayOf(), @field:WireField( tag = 604, - adapter = "com.squareup.wire.ProtoAdapter#FIXED32", + adapter = "com.squareup.wire.ProtoAdapter#FIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 88, ) @@ -501,7 +501,7 @@ public class AllTypes( public val array_fixed32: IntArray = intArrayOf(), @field:WireField( tag = 605, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED32", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED32_ARRAY", label = WireField.Label.PACKED, schemaIndex = 89, ) @@ -509,7 +509,7 @@ public class AllTypes( public val array_sfixed32: IntArray = intArrayOf(), @field:WireField( tag = 606, - adapter = "com.squareup.wire.ProtoAdapter#INT64", + adapter = "com.squareup.wire.ProtoAdapter#INT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 90, ) @@ -517,7 +517,7 @@ public class AllTypes( public val array_int64: LongArray = longArrayOf(), @field:WireField( tag = 607, - adapter = "com.squareup.wire.ProtoAdapter#UINT64", + adapter = "com.squareup.wire.ProtoAdapter#UINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 91, ) @@ -525,7 +525,7 @@ public class AllTypes( public val array_uint64: LongArray = longArrayOf(), @field:WireField( tag = 608, - adapter = "com.squareup.wire.ProtoAdapter#SINT64", + adapter = "com.squareup.wire.ProtoAdapter#SINT64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 92, ) @@ -533,7 +533,7 @@ public class AllTypes( public val array_sint64: LongArray = longArrayOf(), @field:WireField( tag = 609, - adapter = "com.squareup.wire.ProtoAdapter#FIXED64", + adapter = "com.squareup.wire.ProtoAdapter#FIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 93, ) @@ -541,7 +541,7 @@ public class AllTypes( public val array_fixed64: LongArray = longArrayOf(), @field:WireField( tag = 610, - adapter = "com.squareup.wire.ProtoAdapter#SFIXED64", + adapter = "com.squareup.wire.ProtoAdapter#SFIXED64_ARRAY", label = WireField.Label.PACKED, schemaIndex = 94, ) @@ -549,7 +549,7 @@ public class AllTypes( public val array_sfixed64: LongArray = longArrayOf(), @field:WireField( tag = 611, - adapter = "com.squareup.wire.ProtoAdapter#FLOAT", + adapter = "com.squareup.wire.ProtoAdapter#FLOAT_ARRAY", label = WireField.Label.PACKED, schemaIndex = 95, ) @@ -557,7 +557,7 @@ public class AllTypes( public val array_float: FloatArray = floatArrayOf(), @field:WireField( tag = 612, - adapter = "com.squareup.wire.ProtoAdapter#DOUBLE", + adapter = "com.squareup.wire.ProtoAdapter#DOUBLE_ARRAY", label = WireField.Label.PACKED, schemaIndex = 96, )