From cba090367e7ff0771cdb3e53ebb9eb6f80b89c5f Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Thu, 13 Aug 2026 19:02:02 -0700 Subject: [PATCH] Internal change. PiperOrigin-RevId: 964417298 --- .../kotlin/com/google/protobuf/DslList.kt | 25 +-------------- .../com/google/protobuf/ExtensionList.kt | 32 ++----------------- .../kotlin/com/google/protobuf/DslListTest.kt | 26 --------------- .../com/google/protobuf/ExtensionListTest.kt | 28 ---------------- src/google/protobuf/compiler/kotlin/field.cc | 16 +++++----- .../protobuf/compiler/kotlin/message.cc | 5 ++- 6 files changed, 13 insertions(+), 119 deletions(-) diff --git a/java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt b/java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt index 7794073422..1e144a15c3 100644 --- a/java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt +++ b/java/kotlin/src/main/kotlin/com/google/protobuf/DslList.kt @@ -41,30 +41,7 @@ package com.google.protobuf.kotlin @Suppress("unused") // the unused type parameter class DslList @OnlyForUseByGeneratedProtoCode -constructor(private val delegateSupplier: () -> List) : List { - @OnlyForUseByGeneratedProtoCode - constructor(delegate: List) : this({ delegate }) - - private val delegate: List - get() = delegateSupplier() - - override val size: Int - get() = delegate.size - - override fun isEmpty(): Boolean = delegate.isEmpty() - - override fun contains(element: E): Boolean = delegate.contains(element) - - override fun containsAll(elements: Collection): Boolean = delegate.containsAll(elements) - - override fun get(index: Int): E = delegate[index] - - override fun indexOf(element: E): Int = delegate.indexOf(element) - - override fun lastIndexOf(element: E): Int = delegate.lastIndexOf(element) - - override fun subList(fromIndex: Int, toIndex: Int): List = delegate.subList(fromIndex, toIndex) - +constructor(private val delegate: List) : List by delegate { override fun iterator(): Iterator = UnmodifiableIterator(delegate.iterator()) override fun listIterator(): ListIterator = UnmodifiableListIterator(delegate.listIterator()) diff --git a/java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt b/java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt index b4af0b86c1..206c19f1c3 100644 --- a/java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt +++ b/java/kotlin/src/main/kotlin/com/google/protobuf/ExtensionList.kt @@ -40,36 +40,8 @@ import com.google.protobuf.MessageLite */ class ExtensionList @OnlyForUseByGeneratedProtoCode -constructor( - val extension: ExtensionLite>, - private val delegateSupplier: () -> List, -) : List { - @OnlyForUseByGeneratedProtoCode - constructor( - extension: ExtensionLite>, - delegate: List, - ) : this(extension, { delegate }) - - private val delegate: List - get() = delegateSupplier() - - override val size: Int - get() = delegate.size - - override fun isEmpty(): Boolean = delegate.isEmpty() - - override fun contains(element: E): Boolean = delegate.contains(element) - - override fun containsAll(elements: Collection): Boolean = delegate.containsAll(elements) - - override fun get(index: Int): E = delegate[index] - - override fun indexOf(element: E): Int = delegate.indexOf(element) - - override fun lastIndexOf(element: E): Int = delegate.lastIndexOf(element) - - override fun subList(fromIndex: Int, toIndex: Int): List = delegate.subList(fromIndex, toIndex) - +constructor(val extension: ExtensionLite>, private val delegate: List) : + List by delegate { override fun iterator(): Iterator = UnmodifiableIterator(delegate.iterator()) override fun listIterator(): ListIterator = UnmodifiableListIterator(delegate.listIterator()) diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt index 25851955f4..29e5cae6ba 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt @@ -94,30 +94,4 @@ class DslListTest { ) .testEquals() } - - @Test - fun supplierNotInvokedOnConstruction() { - var supplierCalled = false - val dslList = DslList { - supplierCalled = true - listOf(1, 2, 3) - } - assertThat(supplierCalled).isFalse() - assertThat(dslList).containsExactly(1, 2, 3).inOrder() - assertThat(supplierCalled).isTrue() - } - - @Test - fun supplierCalledOnEveryReadOperation() { - var callCount = 0 - val dslList = DslList { - callCount++ - listOf(callCount) - } - assertThat(callCount).isEqualTo(0) - assertThat(dslList.size).isEqualTo(1) - assertThat(callCount).isEqualTo(1) - assertThat(dslList[0]).isEqualTo(2) - assertThat(callCount).isEqualTo(2) - } } diff --git a/java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt b/java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt index 32ebace05e..9a949e9148 100644 --- a/java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt +++ b/java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt @@ -131,32 +131,4 @@ class ExtensionListTest { ) .testEquals() } - - @Test - fun supplierNotInvokedOnConstruction() { - var supplierCalled = false - val extensionList = - ExtensionList(TestProto.repeatedExtension) { - supplierCalled = true - listOf(1, 2, 3) - } - assertThat(supplierCalled).isFalse() - assertThat(extensionList).containsExactly(1, 2, 3).inOrder() - assertThat(supplierCalled).isTrue() - } - - @Test - fun supplierCalledOnEveryReadOperation() { - var callCount = 0 - val extensionList = - ExtensionList(TestProto.repeatedExtension) { - callCount++ - listOf(callCount) - } - assertThat(callCount).isEqualTo(0) - assertThat(extensionList.size).isEqualTo(1) - assertThat(callCount).isEqualTo(1) - assertThat(extensionList[0]).isEqualTo(2) - assertThat(callCount).isEqualTo(2) - } } diff --git a/src/google/protobuf/compiler/kotlin/field.cc b/src/google/protobuf/compiler/kotlin/field.cc index 68f639e68f..a0344db5ae 100644 --- a/src/google/protobuf/compiler/kotlin/field.cc +++ b/src/google/protobuf/compiler/kotlin/field.cc @@ -162,9 +162,9 @@ void FieldGenerator::GenerateRepeatedPritimiveField( "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" "$ jvm_synthetic$" - " get() = com.google.protobuf.kotlin.DslList {\n" + " get() = com.google.protobuf.kotlin.DslList(\n" " $kt_dsl_builder$.${$$kt_property_name$List$}$\n" - " }\n"); + " )\n"); java::WriteFieldAccessorDocComment(printer, descriptor_, java::LIST_ADDER, context_->options(), /* builder */ false, @@ -343,9 +343,9 @@ void FieldGenerator::GenerateRepeatedMessageField(io::Printer* printer) const { "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" "$ jvm_synthetic$" - " get() = com.google.protobuf.kotlin.DslList {\n" + " get() = com.google.protobuf.kotlin.DslList(\n" " $kt_dsl_builder$.${$$kt_property_name$List$}$\n" - " }\n"); + " )\n"); java::WriteFieldAccessorDocComment(printer, descriptor_, java::LIST_ADDER, context_->options(), /* builder */ false, @@ -516,9 +516,9 @@ void FieldGenerator::GenerateRepeatedStringField(io::Printer* printer) const { "\n" "@kotlin.OptIn" "(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n" - " get() = com.google.protobuf.kotlin.DslList {\n" + " get() = com.google.protobuf.kotlin.DslList(\n" " $kt_dsl_builder$.${$$kt_property_name$List$}$\n" - " }\n"); + " )\n"); // List.add(String) java::WriteFieldAccessorDocComment(printer, descriptor_, java::LIST_ADDER, @@ -718,9 +718,9 @@ void FieldGenerator::GenerateRepeatedEnumField(io::Printer* printer) const { "com.google.protobuf.kotlin.DslList" "<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>\n" "$ jvm_synthetic$" - " get() = com.google.protobuf.kotlin.DslList {\n" + " get() = com.google.protobuf.kotlin.DslList(\n" " $kt_dsl_builder$.${$$kt_property_name$List$}$\n" - " }\n"); + " )\n"); java::WriteFieldAccessorDocComment(printer, descriptor_, java::LIST_ADDER, context_->options(), /* builder */ false, diff --git a/src/google/protobuf/compiler/kotlin/message.cc b/src/google/protobuf/compiler/kotlin/message.cc index c6d67da18a..088f50c69d 100644 --- a/src/google/protobuf/compiler/kotlin/message.cc +++ b/src/google/protobuf/compiler/kotlin/message.cc @@ -289,9 +289,8 @@ void MessageGenerator::GenerateExtensions(io::Printer* printer) const { " extension: com.google.protobuf.ExtensionLite<$message$, " "kotlin.collections.List>\n" "): com.google.protobuf.kotlin.ExtensionList {\n" - " return com.google.protobuf.kotlin.ExtensionList(extension) {\n" - " _builder.getExtension(extension)\n" - " }\n" + " return com.google.protobuf.kotlin.ExtensionList(extension, " + "_builder.getExtension(extension))\n" "}\n\n"); }