pull/9494/head
Deanna Garcia 3 years ago
parent c946f0bb70
commit e760984a59
  1. 16
      BUILD
  2. 15
      java/kotlin/BUILD
  3. 6
      protobuf_deps.bzl
  4. 22
      src/google/protobuf/compiler/java/java_message.cc
  5. 12
      src/google/protobuf/compiler/java/java_message_field.cc
  6. 12
      src/google/protobuf/compiler/java/java_message_field_lite.cc
  7. 16
      src/google/protobuf/compiler/java/java_message_lite.cc

16
BUILD

@ -1485,6 +1485,7 @@ genrule(
outs = [
"TestAllTypesKt.kt",
"ForeignMessageKt.kt",
"Int32MessageKt.kt",
"TestAllExtensionsKt.kt",
"TestEmptyMessageKt.kt",
"TestEmptyMessageWithExtensionsKt.kt",
@ -1505,6 +1506,8 @@ genrule(
"$(location TestAllTypesKt.kt) && " +
"cp $(@D)/protobuf_unittest/ForeignMessageKt.kt " +
"$(location ForeignMessageKt.kt) && " +
"cp $(@D)/protobuf_unittest/Int32MessageKt.kt " +
"$(location Int32MessageKt.kt) && " +
"cp $(@D)/protobuf_unittest/TestAllExtensionsKt.kt " +
"$(location TestAllExtensionsKt.kt) && " +
"cp $(@D)/protobuf_unittest/TestEmptyMessageKt.kt " +
@ -1568,3 +1571,16 @@ genrule(
tools = ["//:protoc"],
)
genrule(
name = "gen_kotlin_any",
srcs = ["src/google/protobuf/any.proto"],
outs = ["AnyKt.kt"],
visibility = ["//java:__subpackages__"],
cmd = "$(location //:protoc) " +
"--kotlin_out=shared,immutable:$(@D) -Isrc/ " +
"$(location src/google/protobuf/any.proto) && " +
"cp $(@D)/com/google/protobuf/AnyKt.kt " +
"$(location AnyKt.kt)",
tools = ["//:protoc"],
)

@ -1,5 +1,6 @@
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_jvm_external//:kt_defs.bzl", "kt_jvm_export")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf_version.bzl", "PROTOBUF_VERSION")
@ -35,7 +36,10 @@ kt_jvm_library(
kt_jvm_library(
name = "full_extensions",
srcs = ["src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt"],
srcs = [
"src/main/kotlin/com/google/protobuf/Anies.kt",
"src/main/kotlin/com/google/protobuf/ExtendableMessageExtensions.kt",
],
deps = ["//java/core"],
)
@ -106,11 +110,15 @@ java_test(
kt_jvm_library(
name = "test_extensions_library",
srcs = ["src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt"],
srcs = [
"src/test/kotlin/com/google/protobuf/AniesTest.kt",
"src/test/kotlin/com/google/protobuf/ExtendableMessageExtensionsTest.kt",
],
deps = [
":example_extensible_message_java_proto",
":full_extensions",
"//java/lite",
"//java/core:core",
":kotlin_unittest",
":only_for_use_in_proto_generated_code_its_generator_and_tests",
":shared_runtime",
"@com_github_jetbrains_kotlin//:kotlin-test",
@ -221,6 +229,7 @@ kt_jvm_library(
name = "kotlin_unittest",
srcs = [
":gen_evil_names_proto2",
"//:gen_kotlin_any",
"//:gen_kotlin_unittest",
],
deps = [

@ -70,9 +70,9 @@ def protobuf_deps():
if not native.existing_rule("rules_jvm_external"):
http_archive(
name = "rules_jvm_external",
sha256 = "f36441aa876c4f6427bfb2d1f2d723b48e9d930b62662bf723ddfb8fc80f0140",
strip_prefix = "rules_jvm_external-4.1",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/4.1.zip"],
sha256 = "744bd7436f63af7e9872948773b8b106016dc164acb3960b4963f86754532ee7",
strip_prefix = "rules_jvm_external-906875b0d5eaaf61a8ca2c9c3835bde6f435d011",
urls = ["https://github.com/bazelbuild/rules_jvm_external/archive/906875b0d5eaaf61a8ca2c9c3835bde6f435d011.zip"],
)
if not native.existing_rule("rules_pkg"):

@ -1526,7 +1526,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@Suppress(\"UNCHECKED_CAST\")\n"
"@kotlin.jvm.JvmSynthetic\n"
"public operator fun <T> get(extension: "
"public operator fun <T : Any> get(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>): T {\n"
" return if (extension.isRepeated) {\n"
" get(extension as com.google.protobuf.ExtensionLite<$message$, "
@ -1542,7 +1542,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
"public operator fun <E> get(\n"
"public operator fun <E : Any> get(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
"): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
" return com.google.protobuf.kotlin.ExtensionList(extension, "
@ -1571,7 +1571,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.PublishedApi\n"
"internal fun <T> setExtension(extension: "
"internal fun <T : Any> setExtension(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>, "
"value: T) {\n"
" _builder.setExtension(extension, value)\n"
@ -1585,7 +1585,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
" setExtension(extension, value)\n"
" setExtension(extension, value!!)\n"
"}\n\n",
"message", message_name);
@ -1597,7 +1597,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
"com.google.protobuf.ByteString>,\n"
" value: com.google.protobuf.ByteString\n"
") {\n"
" setExtension(extension, value)\n"
" setExtension(extension, value!!)\n"
"}\n\n",
"message", message_name);
@ -1608,13 +1608,13 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
" extension: com.google.protobuf.ExtensionLite<$message$, T>,\n"
" value: T\n"
") {\n"
" setExtension(extension, value)\n"
" setExtension(extension, value!!)\n"
"}\n\n",
"message", message_name);
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"public fun <E : Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.add(value: E) {\n"
" _builder.addExtension(this.extension, value)\n"
"}\n\n",
@ -1623,7 +1623,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"public inline operator fun <E> "
"public inline operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@ -1633,7 +1633,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public fun <E> com.google.protobuf.kotlin.ExtensionList<E, "
"public fun <E : Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.addAll(values: Iterable<E>) {\n"
" for (value in values) {\n"
" add(value)\n"
@ -1644,7 +1644,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"public inline operator fun <E> "
"public inline operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@ -1654,7 +1654,7 @@ void ImmutableMessageGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public operator fun <E> "
"public operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.set(index: Int, value: "
"E) {\n"

@ -1438,7 +1438,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ false);
@ -1450,7 +1450,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ false);
@ -1461,7 +1461,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ false);
@ -1474,7 +1474,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
/* builder */ false);
@ -1486,7 +1486,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ false);
@ -1497,7 +1497,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}");
"}\n\n");
}
} // namespace java

@ -825,7 +825,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"add(value: $kt_type$) {\n"
" $kt_dsl_builder$.${$add$capitalized_name$$}$(value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ false);
@ -837,7 +837,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(value: $kt_type$) {\n"
" add(value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ false);
@ -848,7 +848,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"addAll(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" $kt_dsl_builder$.${$addAll$capitalized_name$$}$(values)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ false);
@ -861,7 +861,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"plusAssign(values: kotlin.collections.Iterable<$kt_type$>) {\n"
" addAll(values)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, LIST_INDEXED_SETTER,
/* builder */ false);
@ -873,7 +873,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"set(index: kotlin.Int, value: $kt_type$) {\n"
" $kt_dsl_builder$.${$set$capitalized_name$$}$(index, value)\n"
"}");
"}\n");
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ false);
@ -884,7 +884,7 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateKotlinDslMembers(
"<$kt_type$, ${$$kt_capitalized_name$Proxy$}$>."
"clear() {\n"
" $kt_dsl_builder$.${$clear$capitalized_name$$}$()\n"
"}");
"}\n");
}
} // namespace java

@ -847,7 +847,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@Suppress(\"UNCHECKED_CAST\")\n"
"@kotlin.jvm.JvmSynthetic\n"
"public operator fun <T> get(extension: "
"public operator fun <T : Any> get(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>): T {\n"
" return if (extension.isRepeated) {\n"
" get(extension as com.google.protobuf.ExtensionLite<$message$, "
@ -863,7 +863,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
"@kotlin.OptIn"
"(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)\n"
"@kotlin.jvm.JvmName(\"-getRepeatedExtension\")\n"
"public operator fun <E> get(\n"
"public operator fun <E : Any> get(\n"
" extension: com.google.protobuf.ExtensionLite<$message$, List<E>>\n"
"): com.google.protobuf.kotlin.ExtensionList<E, $message$> {\n"
" return com.google.protobuf.kotlin.ExtensionList(extension, "
@ -892,7 +892,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@kotlin.PublishedApi\n"
"internal fun <T> setExtension(extension: "
"internal fun <T : Any> setExtension(extension: "
"com.google.protobuf.ExtensionLite<$message$, T>, "
"value: T) {\n"
" _builder.setExtension(extension, value)\n"
@ -935,7 +935,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public fun<E> com.google.protobuf.kotlin.ExtensionList<E, "
"public fun<E : Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.add(value: E) {\n"
" _builder.addExtension(this.extension, value)\n"
"}\n\n",
@ -944,7 +944,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"public inline operator fun <E> "
"public inline operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign"
"(value: E) {\n"
@ -954,7 +954,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public fun<E> com.google.protobuf.kotlin.ExtensionList<E, "
"public fun<E : Any> com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.addAll(values: Iterable<E>) {\n"
" for (value in values) {\n"
" add(value)\n"
@ -965,7 +965,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"@Suppress(\"NOTHING_TO_INLINE\")\n"
"public inline operator fun <E> "
"public inline operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.plusAssign(values: "
"Iterable<E>) {\n"
@ -975,7 +975,7 @@ void ImmutableMessageLiteGenerator::GenerateKotlinExtensions(
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"public operator fun <E> "
"public operator fun <E : Any> "
"com.google.protobuf.kotlin.ExtensionList<E, "
"$message$>.set(index: Int, value: "
"E) {\n"

Loading…
Cancel
Save