Internal change

PiperOrigin-RevId: 667664794
pull/17883/head
Protobuf Team Bot 3 months ago committed by Copybara-Service
parent 0ed61f0b15
commit 673a892bd9
  1. 11
      java/kotlin-lite/src/main/kotlin/com/google/protobuf/ExtendableMessageLiteExtensions.kt
  2. 72
      java/kotlin-lite/src/test/kotlin/com/google/protobuf/Proto2LiteTest.kt
  3. 11
      java/kotlin/src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt
  4. 2
      java/kotlin/src/main/kotlin/com/google/protobuf/OnlyForUseByGeneratedProtoCode.kt
  5. 2
      java/kotlin/src/test/kotlin/com/google/protobuf/DslListTest.kt
  6. 2
      java/kotlin/src/test/kotlin/com/google/protobuf/DslMapTest.kt
  7. 16
      java/kotlin/src/test/kotlin/com/google/protobuf/ExtensionListTest.kt
  8. 30
      java/kotlin/src/test/kotlin/com/google/protobuf/Proto2Test.kt
  9. 10
      java/kotlin/src/test/kotlin/com/google/protobuf/Proto3Test.kt
  10. 4
      java/kotlin/src/test/proto/com/google/protobuf/multiple_files_proto3.proto

@ -37,19 +37,20 @@ import com.google.protobuf.GeneratedMessageLite
operator fun <
M : GeneratedMessageLite.ExtendableMessage<M, *>,
MOrBT : GeneratedMessageLite.ExtendableMessageOrBuilder<M, *>,
T : Any> MOrBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
T : Any,
> MOrBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
/** Sets the current value of the proto extension in this builder. */
operator fun <
M : GeneratedMessageLite.ExtendableMessage<M, B>,
B : GeneratedMessageLite.ExtendableBuilder<M, B>,
T : Any> B.set(extension: ExtensionLite<M, T>, value: T) {
T : Any,
> B.set(extension: ExtensionLite<M, T>, value: T) {
setExtension(extension, value)
}
/** Returns true if the specified extension is set. */
operator fun <
M : GeneratedMessageLite.ExtendableMessage<M, *>,
MorBT : GeneratedMessageLite.ExtendableMessageOrBuilder<M, *>> MorBT.contains(
extension: ExtensionLite<M, *>
): Boolean = hasExtension(extension)
MorBT : GeneratedMessageLite.ExtendableMessageOrBuilder<M, *>,
> MorBT.contains(extension: ExtensionLite<M, *>): Boolean = hasExtension(extension)

@ -155,7 +155,7 @@ class Proto2LiteTest {
.isEqualTo(TestUtilLite.getAllLiteSetBuilder().build())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testGetters() {
testAllTypesLite {
@ -176,7 +176,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testDefaultGetters() {
testAllTypesLite {
@ -187,7 +187,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testRepeatedGettersAndSetters() {
testAllTypesLite {
@ -208,20 +208,20 @@ class Proto2LiteTest {
repeatedGroup.addAll(
listOf(
TestAllTypesLiteKt.repeatedGroup { a = 1 },
TestAllTypesLiteKt.repeatedGroup { a = 2 }
TestAllTypesLiteKt.repeatedGroup { a = 2 },
)
)
assertThat(repeatedGroup)
.isEqualTo(
listOf(
TestAllTypesLiteKt.repeatedGroup { a = 1 },
TestAllTypesLiteKt.repeatedGroup { a = 2 }
TestAllTypesLiteKt.repeatedGroup { a = 2 },
)
)
repeatedGroup +=
listOf(
TestAllTypesLiteKt.repeatedGroup { a = 3 },
TestAllTypesLiteKt.repeatedGroup { a = 4 }
TestAllTypesLiteKt.repeatedGroup { a = 4 },
)
assertThat(repeatedGroup)
.isEqualTo(
@ -229,7 +229,7 @@ class Proto2LiteTest {
TestAllTypesLiteKt.repeatedGroup { a = 1 },
TestAllTypesLiteKt.repeatedGroup { a = 2 },
TestAllTypesLiteKt.repeatedGroup { a = 3 },
TestAllTypesLiteKt.repeatedGroup { a = 4 }
TestAllTypesLiteKt.repeatedGroup { a = 4 },
)
)
repeatedGroup[0] = TestAllTypesLiteKt.repeatedGroup { a = 5 }
@ -239,7 +239,7 @@ class Proto2LiteTest {
TestAllTypesLiteKt.repeatedGroup { a = 5 },
TestAllTypesLiteKt.repeatedGroup { a = 2 },
TestAllTypesLiteKt.repeatedGroup { a = 3 },
TestAllTypesLiteKt.repeatedGroup { a = 4 }
TestAllTypesLiteKt.repeatedGroup { a = 4 },
)
)
@ -253,7 +253,7 @@ class Proto2LiteTest {
nestedMessage { bb = 1 },
nestedMessage { bb = 2 },
nestedMessage { bb = 3 },
nestedMessage { bb = 4 }
nestedMessage { bb = 4 },
)
)
repeatedNestedMessage[0] = nestedMessage { bb = 5 }
@ -263,7 +263,7 @@ class Proto2LiteTest {
nestedMessage { bb = 5 },
nestedMessage { bb = 2 },
nestedMessage { bb = 3 },
nestedMessage { bb = 4 }
nestedMessage { bb = 4 },
)
)
@ -278,7 +278,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHazzers() {
testAllTypesLite {
@ -309,7 +309,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testClears() {
testAllTypesLite {
@ -398,36 +398,36 @@ class Proto2LiteTest {
setExtension(UnittestLite.optionalBytesExtensionLite, toBytes("116"))
setExtension(
UnittestLite.optionalGroupExtensionLite,
optionalGroupExtensionLite { a = 117 }
optionalGroupExtensionLite { a = 117 },
)
setExtension(
UnittestLite.optionalNestedMessageExtensionLite,
TestAllTypesLiteKt.nestedMessage { bb = 118 }
TestAllTypesLiteKt.nestedMessage { bb = 118 },
)
setExtension(
UnittestLite.optionalForeignMessageExtensionLite,
foreignMessageLite { c = 119 }
foreignMessageLite { c = 119 },
)
setExtension(
UnittestLite.optionalImportMessageExtensionLite,
ImportMessageLite.newBuilder().setD(120).build()
ImportMessageLite.newBuilder().setD(120).build(),
)
setExtension(
UnittestLite.optionalPublicImportMessageExtensionLite,
PublicImportMessageLite.newBuilder().setE(126).build()
PublicImportMessageLite.newBuilder().setE(126).build(),
)
setExtension(
UnittestLite.optionalLazyMessageExtensionLite,
TestAllTypesLiteKt.nestedMessage { bb = 127 }
TestAllTypesLiteKt.nestedMessage { bb = 127 },
)
setExtension(
UnittestLite.optionalUnverifiedLazyMessageExtensionLite,
TestAllTypesLiteKt.nestedMessage { bb = 128 }
TestAllTypesLiteKt.nestedMessage { bb = 128 },
)
setExtension(UnittestLite.optionalNestedEnumExtensionLite, NestedEnum.BAZ)
setExtension(
UnittestLite.optionalForeignEnumExtensionLite,
ForeignEnumLite.FOREIGN_LITE_BAZ
ForeignEnumLite.FOREIGN_LITE_BAZ,
)
setExtension(UnittestLite.optionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
setExtension(UnittestLite.optionalStringPieceExtensionLite, "124")
@ -521,7 +521,7 @@ class Proto2LiteTest {
.isEqualTo(TestUtilLite.getAllLiteExtensionsSet())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionGetters() {
testAllExtensionsLite {
@ -545,7 +545,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testRepeatedExtensionGettersAndSetters() {
testAllExtensionsLite {
@ -580,7 +580,7 @@ class Proto2LiteTest {
repeatedGroupExtensionLite { a = 1 },
repeatedGroupExtensionLite { a = 2 },
repeatedGroupExtensionLite { a = 3 },
repeatedGroupExtensionLite { a = 4 }
repeatedGroupExtensionLite { a = 4 },
)
)
this[UnittestLite.repeatedGroupExtensionLite][0] = repeatedGroupExtensionLite { a = 5 }
@ -590,7 +590,7 @@ class Proto2LiteTest {
repeatedGroupExtensionLite { a = 5 },
repeatedGroupExtensionLite { a = 2 },
repeatedGroupExtensionLite { a = 3 },
repeatedGroupExtensionLite { a = 4 }
repeatedGroupExtensionLite { a = 4 },
)
)
@ -607,7 +607,7 @@ class Proto2LiteTest {
nestedMessage { bb = 1 },
nestedMessage { bb = 2 },
nestedMessage { bb = 3 },
nestedMessage { bb = 4 }
nestedMessage { bb = 4 },
)
)
this[UnittestLite.repeatedNestedMessageExtensionLite][0] = nestedMessage { bb = 5 }
@ -617,7 +617,7 @@ class Proto2LiteTest {
nestedMessage { bb = 5 },
nestedMessage { bb = 2 },
nestedMessage { bb = 3 },
nestedMessage { bb = 4 }
nestedMessage { bb = 4 },
)
)
@ -635,7 +635,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionContains() {
testAllExtensionsLite {
@ -667,7 +667,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionClears() {
testAllExtensionsLite {
@ -756,7 +756,7 @@ class Proto2LiteTest {
)
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapGettersAndSetters() {
testMapLite {
@ -788,7 +788,7 @@ class Proto2LiteTest {
1 to MapEnumLite.MAP_ENUM_FOO_LITE,
2 to MapEnumLite.MAP_ENUM_BAR_LITE,
3 to MapEnumLite.MAP_ENUM_BAZ_LITE,
4 to MapEnumLite.MAP_ENUM_FOO_LITE
4 to MapEnumLite.MAP_ENUM_FOO_LITE,
)
)
@ -806,13 +806,13 @@ class Proto2LiteTest {
1 to foreignMessageLite { c = 1 },
2 to foreignMessageLite { c = 2 },
3 to foreignMessageLite { c = 3 },
4 to foreignMessageLite { c = 4 }
4 to foreignMessageLite { c = 4 },
)
)
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapRemove() {
testMapLite {
@ -838,7 +838,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapClear() {
testMapLite {
@ -920,7 +920,7 @@ class Proto2LiteTest {
assertThat(interface_ {}).isEqualTo(Interface.newBuilder().build())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordGettersAndSetters() {
hardKeywordsAllTypesProto2 {
@ -950,7 +950,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordHazzers() {
hardKeywordsAllTypesProto2 {
@ -965,7 +965,7 @@ class Proto2LiteTest {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordClears() {
hardKeywordsAllTypesProto2 {

@ -37,7 +37,8 @@ import com.google.protobuf.GeneratedMessage
operator fun <
M : GeneratedMessage.ExtendableMessage<M>,
B : GeneratedMessage.ExtendableBuilder<M, B>,
T : Any> B.set(extension: ExtensionLite<M, T>, value: T) {
T : Any,
> B.set(extension: ExtensionLite<M, T>, value: T) {
setExtension(extension, value)
}
@ -45,11 +46,11 @@ operator fun <
operator fun <
M : GeneratedMessage.ExtendableMessage<M>,
MorBT : GeneratedMessage.ExtendableMessageOrBuilder<M>,
T : Any> MorBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
T : Any,
> MorBT.get(extension: ExtensionLite<M, T>): T = getExtension(extension)
/** Returns true if the specified extension is set on this builder. */
operator fun <
M : GeneratedMessage.ExtendableMessage<M>,
MorBT : GeneratedMessage.ExtendableMessageOrBuilder<M>> MorBT.contains(
extension: ExtensionLite<M, *>
): Boolean = hasExtension(extension)
MorBT : GeneratedMessage.ExtendableMessageOrBuilder<M>,
> MorBT.contains(extension: ExtensionLite<M, *>): Boolean = hasExtension(extension)

@ -41,7 +41,7 @@ package com.google.protobuf.kotlin
This API is only intended for use by generated protobuf code, the code generator, and their own
tests. If this does not describe your code, you should not be using this API.
""",
level = RequiresOptIn.Level.ERROR
level = RequiresOptIn.Level.ERROR,
)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CONSTRUCTOR, AnnotationTarget.ANNOTATION_CLASS)

@ -90,7 +90,7 @@ class DslListTest {
.addEqualityGroup(
DslList<Int, DummyProxy>(emptyList()),
DslList<String, DummyProxy>(emptyList()),
emptyList<Int>()
emptyList<Int>(),
)
.testEquals()
}

@ -147,7 +147,7 @@ class DslMapTest {
.addEqualityGroup(
DslMap<Int, Int, DummyProxy>(emptyMap()),
DslMap<String, String, DummyProxy>(emptyMap()),
emptyMap<Int, Int>()
emptyMap<Int, Int>(),
)
.testEquals()
}

@ -45,7 +45,7 @@ class ExtensionListTest {
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(
TestProto.repeatedExtension,
mutableListOf(1, 2, 3)
mutableListOf(1, 2, 3),
)
assertThat(extensionList is MutableList<*>).isFalse()
}
@ -56,7 +56,7 @@ class ExtensionListTest {
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(
TestProto.repeatedExtension,
mutableListOf(1, 2, 3)
mutableListOf(1, 2, 3),
)
val extensionListAsJavaUtil = extensionList as java.util.List<Int>
assertFailsWith<UnsupportedOperationException> { extensionListAsJavaUtil.add(4) }
@ -68,7 +68,7 @@ class ExtensionListTest {
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(
TestProto.repeatedExtension,
mutableListOf(1, 2, 3)
mutableListOf(1, 2, 3),
)
val iterator = extensionList.iterator() as java.util.Iterator<Int>
iterator.next()
@ -82,7 +82,7 @@ class ExtensionListTest {
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(
TestProto.repeatedExtension,
mutableListOf(1, 2, 3)
mutableListOf(1, 2, 3),
)
val iterator = extensionList.listIterator() as java.util.ListIterator<Int>
iterator.next()
@ -96,7 +96,7 @@ class ExtensionListTest {
val extensionList =
ExtensionList<Int, ExampleExtensibleMessage>(
TestProto.repeatedExtension,
mutableListOf(1, 2, 3)
mutableListOf(1, 2, 3),
)
val iterator = extensionList.listIterator(1) as java.util.ListIterator<Int>
iterator.next()
@ -119,15 +119,15 @@ class ExtensionListTest {
.addEqualityGroup(
ExtensionList<Int, ExampleExtensibleMessage>(TestProto.repeatedExtension, listOf(1, 2)),
ExtensionList<Int, ExampleExtensibleMessage>(TestProto.differentExtension, listOf(1, 2)),
listOf(1, 2)
listOf(1, 2),
)
.addEqualityGroup(
ExtensionList<Int, ExampleExtensibleMessage>(TestProto.repeatedExtension, listOf(2, 2)),
listOf(2, 2)
listOf(2, 2),
)
.addEqualityGroup(
ExtensionList<Int, ExampleExtensibleMessage>(TestProto.repeatedExtension, emptyList()),
emptyList<Int>()
emptyList<Int>(),
)
.testEquals()
}

@ -162,7 +162,7 @@ class Proto2Test {
.isEqualTo(TestUtil.getAllSetBuilder().build())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testGetters() {
testAllTypes {
@ -183,7 +183,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testDefaultGetters() {
testAllTypes {
@ -194,7 +194,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testRepeatedGettersAndSetters() {
testAllTypes {
@ -276,7 +276,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHazzers() {
testAllTypes {
@ -307,7 +307,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testClears() {
testAllTypes {
@ -496,7 +496,7 @@ class Proto2Test {
.isEqualTo(TestUtil.getAllExtensionsSet())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionGetters() {
testAllExtensions {
@ -519,7 +519,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testRepeatedExtensionGettersAndSetters() {
testAllExtensions {
@ -600,7 +600,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionContains() {
testAllExtensions {
@ -631,7 +631,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testExtensionClears() {
testAllExtensions {
@ -713,7 +713,7 @@ class Proto2Test {
)
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapGettersAndSetters() {
val intMap = testIntIntMap {
@ -765,7 +765,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapRemove() {
val intMap = testIntIntMap {
@ -793,7 +793,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testMapClear() {
val intMap = testIntIntMap {
@ -887,7 +887,7 @@ class Proto2Test {
assertThat(interface_ {}).isEqualTo(Interface.newBuilder().build())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordGettersAndSetters() {
hardKeywordsAllTypesProto2 {
@ -917,7 +917,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordHazzers() {
hardKeywordsAllTypesProto2 {
@ -932,7 +932,7 @@ class Proto2Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordClears() {
hardKeywordsAllTypesProto2 {

@ -31,7 +31,7 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
class Proto3Test {
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testGettersAndSetters() {
testAllTypes {
@ -53,7 +53,7 @@ class Proto3Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testRepeatedGettersAndSetters() {
testAllTypes {
@ -253,7 +253,7 @@ class Proto3Test {
assertThat(class_ {}).isEqualTo(Class.newBuilder().build())
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordGettersAndSetters() {
hardKeywordsAllTypesProto3 {
@ -286,7 +286,7 @@ class Proto3Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordHazzers() {
hardKeywordsAllTypesProto3 {
@ -304,7 +304,7 @@ class Proto3Test {
}
}
@Suppress("CheckResult")
@Suppress("CheckReturnValue")
@Test
fun testHardKeywordClears() {
hardKeywordsAllTypesProto3 {

@ -12,7 +12,9 @@ package protobuf.kotlin.generator;
option java_package = "com.google.protobuf.kotlin.generator";
option java_multiple_files = true;
enum NestedEnum { FOO = 0; }
enum NestedEnum {
FOO = 0;
}
message MultipleFilesMessageA {}

Loading…
Cancel
Save