Internal change.

PiperOrigin-RevId: 964417298
This commit is contained in:
Protobuf Team Bot 2026-08-13 19:02:02 -07:00 committed by Copybara-Service
parent 42ceed172e
commit cba090367e
6 changed files with 13 additions and 119 deletions

View file

@ -41,30 +41,7 @@ package com.google.protobuf.kotlin
@Suppress("unused") // the unused type parameter
class DslList<E, P : DslProxy>
@OnlyForUseByGeneratedProtoCode
constructor(private val delegateSupplier: () -> List<E>) : List<E> {
@OnlyForUseByGeneratedProtoCode
constructor(delegate: List<E>) : this({ delegate })
private val delegate: List<E>
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<E>): 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<E> = delegate.subList(fromIndex, toIndex)
constructor(private val delegate: List<E>) : List<E> by delegate {
override fun iterator(): Iterator<E> = UnmodifiableIterator(delegate.iterator())
override fun listIterator(): ListIterator<E> = UnmodifiableListIterator(delegate.listIterator())

View file

@ -40,36 +40,8 @@ import com.google.protobuf.MessageLite
*/
class ExtensionList<E, M : MessageLite>
@OnlyForUseByGeneratedProtoCode
constructor(
val extension: ExtensionLite<M, List<E>>,
private val delegateSupplier: () -> List<E>,
) : List<E> {
@OnlyForUseByGeneratedProtoCode
constructor(
extension: ExtensionLite<M, List<E>>,
delegate: List<E>,
) : this(extension, { delegate })
private val delegate: List<E>
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<E>): 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<E> = delegate.subList(fromIndex, toIndex)
constructor(val extension: ExtensionLite<M, List<E>>, private val delegate: List<E>) :
List<E> by delegate {
override fun iterator(): Iterator<E> = UnmodifiableIterator(delegate.iterator())
override fun listIterator(): ListIterator<E> = UnmodifiableListIterator(delegate.listIterator())

View file

@ -94,30 +94,4 @@ class DslListTest {
)
.testEquals()
}
@Test
fun supplierNotInvokedOnConstruction() {
var supplierCalled = false
val dslList = DslList<Int, DummyProxy> {
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<Int, DummyProxy> {
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)
}
}

View file

@ -131,32 +131,4 @@ class ExtensionListTest {
)
.testEquals()
}
@Test
fun supplierNotInvokedOnConstruction() {
var supplierCalled = false
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(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<Int, ExampleExtensibleMessage>(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)
}
}