Merge pull request #10399 from mkruskal-google/sync-stage

Integrate from Piper for C++, Java, and Python
pull/10402/head
Mike Kruskal 2 years ago committed by GitHub
commit 043cb56c00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      BUILD.bazel
  2. 2
      benchmarks/BUILD.bazel
  3. 2
      benchmarks/cpp/cpp_benchmark.cc
  4. 12
      benchmarks/datasets/BUILD.bazel
  5. 4
      benchmarks/datasets/google_message1/proto2/BUILD.bazel
  6. 2
      benchmarks/datasets/google_message1/proto3/BUILD.bazel
  7. 4
      benchmarks/datasets/google_message2/BUILD.bazel
  8. 2
      benchmarks/datasets/google_message3/BUILD.bazel
  9. 2
      benchmarks/datasets/google_message4/BUILD.bazel
  10. 4
      benchmarks/internal.bzl
  11. 6
      benchmarks/java/BUILD.bazel
  12. 26
      benchmarks/php/BUILD.bazel
  13. 24
      benchmarks/python/BUILD.bazel
  14. 16
      benchmarks/python/py_benchmark.py
  15. 8
      benchmarks/util/BUILD.bazel
  16. 14
      benchmarks/util/compatibility.bzl
  17. 4
      benchmarks/util/proto3_data_stripper.cc
  18. 19
      benchmarks/util/protoc-gen-proto2_to_proto3.cc
  19. 4
      benchmarks/util/result_parser.py
  20. 18
      build_defs/arch_tests.bzl
  21. 28
      build_defs/internal_shell.bzl
  22. 78
      conformance/BUILD.bazel
  23. 1
      conformance/conformance_cpp.cc
  24. 2
      conformance/conformance_python.py
  25. 2
      conformance/conformance_test.cc
  26. 2
      conformance/conformance_test.h
  27. 2
      conformance/conformance_test_runner.cc
  28. 2
      conformance/defs.bzl
  29. 2
      generate_descriptor_proto.sh
  30. 6
      java/internal/BUILD.bazel
  31. 1
      java/kotlin/BUILD.bazel
  32. 5
      java/kotlin/pom.xml
  33. 4
      maven_install.json
  34. 8
      pkg/BUILD.bazel
  35. 2
      protobuf_deps.bzl
  36. 31
      python/BUILD.bazel
  37. 13
      python/python_version.py
  38. 3
      python/setup.py
  39. 19
      src/google/protobuf/BUILD.bazel
  40. 2
      src/google/protobuf/compiler/BUILD.bazel
  41. 3
      src/google/protobuf/compiler/command_line_interface_unittest.cc
  42. 2
      src/google/protobuf/compiler/java/context.cc
  43. 1
      src/google/protobuf/compiler/java/doc_comment.h
  44. 19
      src/google/protobuf/compiler/java/enum.cc
  45. 10
      src/google/protobuf/compiler/java/enum_field.cc
  46. 37
      src/google/protobuf/compiler/java/enum_field_lite.cc
  47. 42
      src/google/protobuf/compiler/java/enum_lite.cc
  48. 11
      src/google/protobuf/compiler/java/extension.cc
  49. 10
      src/google/protobuf/compiler/java/extension.h
  50. 6
      src/google/protobuf/compiler/java/extension_lite.cc
  51. 1
      src/google/protobuf/compiler/java/extension_lite.h
  52. 19
      src/google/protobuf/compiler/java/file.cc
  53. 2
      src/google/protobuf/compiler/java/generator.cc
  54. 2
      src/google/protobuf/compiler/java/generator.h
  55. 27
      src/google/protobuf/compiler/java/helpers.cc
  56. 25
      src/google/protobuf/compiler/java/helpers.h
  57. 38
      src/google/protobuf/compiler/java/map_field.cc
  58. 1
      src/google/protobuf/compiler/java/map_field.h
  59. 39
      src/google/protobuf/compiler/java/map_field_lite.cc
  60. 36
      src/google/protobuf/compiler/java/message.cc
  61. 4
      src/google/protobuf/compiler/java/message_builder.cc
  62. 15
      src/google/protobuf/compiler/java/message_field.cc
  63. 1
      src/google/protobuf/compiler/java/message_field.h
  64. 21
      src/google/protobuf/compiler/java/message_field_lite.cc
  65. 2
      src/google/protobuf/compiler/java/message_field_lite.h
  66. 23
      src/google/protobuf/compiler/java/message_lite.cc
  67. 20
      src/google/protobuf/compiler/java/name_resolver.cc
  68. 13
      src/google/protobuf/compiler/java/name_resolver.h
  69. 5
      src/google/protobuf/compiler/java/names.h
  70. 4
      src/google/protobuf/compiler/java/options.h
  71. 17
      src/google/protobuf/compiler/java/primitive_field.cc
  72. 29
      src/google/protobuf/compiler/java/primitive_field_lite.cc
  73. 1
      src/google/protobuf/compiler/java/primitive_field_lite.h
  74. 4
      src/google/protobuf/compiler/java/service.cc
  75. 17
      src/google/protobuf/compiler/java/shared_code_generator.cc
  76. 13
      src/google/protobuf/compiler/java/string_field.cc
  77. 52
      src/google/protobuf/compiler/java/string_field_lite.cc
  78. 2
      src/google/protobuf/compiler/java/string_field_lite.h
  79. 2
      src/google/protobuf/port_def.inc
  80. 1
      src/google/protobuf/port_undef.inc
  81. 1
      src/google/protobuf/stubs/common.cc
  82. 6
      src/google/protobuf/stubs/common.h
  83. 6
      src/google/protobuf/wire_format_lite.h

@ -1,12 +1,11 @@
# Bazel (https://bazel.build/) BUILD file for Protobuf.
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS", "LINK_OPTS", "PROTOC_LINK_OPTS")
load(":protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_ruby_proto_library", "internal_objc_proto_library")
load(":protobuf.bzl", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
licenses(["notice"])
@ -438,9 +437,9 @@ java_lite_proto_library(
internal_objc_proto_library(
name = "test_messages_proto2_objc_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
includes = ["src/google/protobuf"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//objectivec:__subpackages__",
@ -449,10 +448,14 @@ internal_objc_proto_library(
internal_objc_proto_library(
name = "test_messages_proto3_objc_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//objectivec:__subpackages__",
@ -461,10 +464,10 @@ internal_objc_proto_library(
internal_php_proto_library(
name = "test_messages_proto3_php_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
outs = [
"GPBMetadata/TestMessagesProto3.php",
"Protobuf_test_messages/Proto3/EnumOnlyProto3.php",
"Protobuf_test_messages/Proto3/EnumOnlyProto3/PBBool.php",
"Protobuf_test_messages/Proto3/ForeignEnum.php",
@ -474,9 +477,13 @@ internal_php_proto_library(
"Protobuf_test_messages/Proto3/TestAllTypesProto3/AliasedEnum.php",
"Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedEnum.php",
"Protobuf_test_messages/Proto3/TestAllTypesProto3/NestedMessage.php",
"GPBMetadata/TestMessagesProto3.php",
],
testonly = 1,
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
visibility = [
"//conformance:__pkg__",
"//php:__subpackages__",
@ -485,9 +492,9 @@ internal_php_proto_library(
internal_ruby_proto_library(
name = "test_messages_proto2_ruby_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto2.proto"],
includes = ["src/google/protobuf"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",
@ -496,10 +503,14 @@ internal_ruby_proto_library(
internal_ruby_proto_library(
name = "test_messages_proto3_ruby_proto",
testonly = 1,
srcs = ["//src/google/protobuf:test_messages_proto3.proto"],
includes = [
"src/google/protobuf",
# The above must come first.
"src",
],
proto_deps = [":well_known_protos"],
includes = ["src/google/protobuf", "src"],
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//ruby:__subpackages__",

@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library")
load("//:protobuf.bzl", "internal_php_proto_library", "internal_py_proto_library")
################################################################################
# Benchmark Protos

@ -30,6 +30,7 @@
#include <fstream>
#include <iostream>
#include "benchmark/benchmark.h"
#include "benchmarks.pb.h"
#include "benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h"
@ -38,7 +39,6 @@
#include "benchmarks/datasets/google_message3/benchmark_message3.pb.h"
#include "benchmarks/datasets/google_message4/benchmark_message4.pb.h"
#define PREFIX "dataset."
#define SUFFIX ".pb"

@ -90,21 +90,18 @@ py_library(
filegroup(
name = "php_protos",
visibility = [
"//benchmarks:__subpackages__",
],
srcs = [
"//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_php_proto",
"//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_php_proto",
"//benchmarks/datasets/google_message2:benchmark_message2_php_proto",
],
visibility = [
"//benchmarks:__subpackages__",
],
)
filegroup(
name = "csharp_protos",
visibility = [
"//benchmarks:__subpackages__",
],
srcs = [
"//benchmarks/datasets/google_message1/proto2:benchmark_message1_proto2_csharp_proto",
"//benchmarks/datasets/google_message1/proto3:benchmark_message1_proto3_csharp_proto",
@ -112,6 +109,9 @@ filegroup(
"//benchmarks/datasets/google_message3:benchmark_message3_csharp_proto",
"//benchmarks/datasets/google_message4:benchmark_message4_csharp_proto",
],
visibility = [
"//benchmarks:__subpackages__",
],
)
pkg_files(

@ -2,8 +2,8 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//benchmarks/util:compatibility.bzl", "proto3_from_proto2_data", "php_proto3_from_proto2_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
load("//benchmarks/util:compatibility.bzl", "php_proto3_from_proto2_library", "proto3_from_proto2_data")
filegroup(
name = "datasets",

@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_php_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,8 +2,8 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//benchmarks/util:compatibility.bzl", "proto3_from_proto2_data", "php_proto3_from_proto2_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
load("//benchmarks/util:compatibility.bzl", "php_proto3_from_proto2_library", "proto3_from_proto2_data")
filegroup(
name = "datasets",

@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,7 +2,7 @@ load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_proto_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_csharp_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_py_proto_library")
filegroup(
name = "datasets",

@ -2,6 +2,7 @@
PLEASE DO NOT DEPEND ON THE CONTENTS OF THIS FILE, IT IS UNSTABLE.
"""
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
def internal_benchmark_test(
@ -31,7 +32,8 @@ def internal_benchmark_test(
" ".join(env_vars),
binary,
" ".join(args),
" ".join(dataset_labels)),
" ".join(dataset_labels),
),
tags = ["benchmark"],
testonly = 1,
)

@ -1,4 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library", "java_binary")
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//benchmarks:internal.bzl", "internal_benchmark_test")
@ -22,7 +22,6 @@ java_binary(
inline_sh_binary(
name = "java_benchmark",
srcs = ["//benchmarks/datasets"],
tools = [":java_benchmark_jar"],
cmd = """
data_files=""
conf=()
@ -35,7 +34,8 @@ inline_sh_binary(
done
$(rootpath :java_benchmark_jar) com.google.protobuf.ProtoCaliperBenchmark \
-i runtime -DdataFile=$${data_files:0:-1} $${conf[*]}
"""
""",
tools = [":java_benchmark_jar"],
)
# A pre-configured binary using the checked in datasets.

@ -5,58 +5,58 @@ load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
# The benchmark binary which can be run over any dataset.
inline_sh_binary(
name = "php_benchmark",
testonly = 1,
srcs = [
"PhpBenchmark.php",
"autoload.php",
],
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
"//php:source_files",
],
cmd = """
php -d include_path=benchmarks:php/src \\
-d auto_prepend_file=$(rootpath autoload.php) \\
$(rootpath PhpBenchmark.php) $$@
""",
testonly = 1,
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
"//php:source_files",
],
)
# A pre-configured binary using the checked in datasets.
internal_benchmark_test(
name = "php",
args = ["--behavior_prefix='php'"],
binary = ":php_benchmark",
datasets = ["//benchmarks/datasets:proto3_datasets"],
env_vars = ["PROTOBUF_PHP_SRCDIR=php/src"],
args = ["--behavior_prefix='php'"],
)
# The benchmark binary which can be run over any dataset.
inline_sh_binary(
name = "php_c_benchmark",
testonly = 1,
srcs = [
"PhpBenchmark.php",
"//php:extension",
],
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
],
cmd = """
php -d include_path=benchmarks:php/src \\
-dextension=$(rootpath //php:extension) \\
$(rootpath PhpBenchmark.php) $$@
""",
testonly = 1,
deps = [
"//benchmarks:benchmarks_php_proto",
"//benchmarks/datasets:php_protos",
],
)
# A pre-configured binary using the checked in datasets.
internal_benchmark_test(
name = "php_c",
args = ["--behavior_prefix='php_c'"],
binary = ":php_c_benchmark",
datasets = ["//benchmarks/datasets:proto3_datasets"],
env_vars = ["PROTOBUF_PHP_SRCDIR=php/src"],
args = ["--behavior_prefix='php_c'"],
)
pkg_files(

@ -1,37 +1,37 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_python//python:defs.bzl", "py_library", "py_binary")
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//benchmarks:internal.bzl", "internal_benchmark_test")
cc_binary(
name = "libbenchmark_messages.so",
srcs = ["python_benchmark_messages.cc"],
linkshared = True,
linkstatic = True,
visibility = ["//visibility:private"],
deps = [
"@local_config_python//:python_headers",
"//external:python_headers",
"//benchmarks:benchmarks_cc_proto",
"//benchmarks/datasets:cc_protos",
"//external:python_headers",
"@local_config_python//:python_headers",
],
linkshared = True,
linkstatic = True,
visibility = ["//visibility:private"],
)
# The benchmark binary which can be run over any dataset.
py_binary(
name = "python_benchmark",
srcs = ["py_benchmark.py"],
main = "py_benchmark.py",
data = ["libbenchmark_messages.so"],
env = select({
"//python:use_fast_cpp_protos": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
"//conditions:default": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
}),
main = "py_benchmark.py",
deps = [
"//:protobuf_python",
"//benchmarks:benchmarks_py_proto",
"//benchmarks/datasets:py_protos",
],
env = select({
"//python:use_fast_cpp_protos": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
"//conditions:default": {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
}),
)
# Pre-configured binaries using the checked in datasets.
@ -54,10 +54,10 @@ internal_benchmark_test(
# Note: this requires --define=use_fast_cpp_protos=true
internal_benchmark_test(
name = "cpp_generated_code",
args = ["--cpp_generated"],
binary = ":python_benchmark",
datasets = ["//benchmarks/datasets"],
env_vars = ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp"],
args = ["--cpp_generated"],
)
pkg_files(

@ -6,6 +6,12 @@ import math
import argparse
import fnmatch
import json
from benchmarks.datasets.google_message1.proto2 import benchmark_message1_proto2_pb2
from benchmarks.datasets.google_message1.proto3 import benchmark_message1_proto3_pb2
from benchmarks.datasets.google_message2 import benchmark_message2_pb2
from benchmarks.datasets.google_message3 import benchmark_message3_pb2
from benchmarks.datasets.google_message4 import benchmark_message4_pb2
from benchmarks import benchmarks_pb2
parser = argparse.ArgumentParser(description="Python protobuf benchmark")
parser.add_argument("data_files", metavar="dataFile", nargs="+",
@ -27,19 +33,11 @@ args = parser.parse_args()
# for the descriptor can be found in the pool
if args.cpp_generated != "no":
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/.libs" )
from benchmarks.python import libbenchmark_messages
from benchmarks.python import libbenchmark_messages # pylint: disable=unused-import,g-import-not-at-top
sys.path.append( os.path.dirname( os.path.dirname( os.path.abspath(__file__) ) ) + "/tmp" )
# END CPP GENERATED MESSAGE
import benchmarks.datasets.google_message1.proto2.benchmark_message1_proto2_pb2 as benchmark_message1_proto2_pb2
import benchmarks.datasets.google_message1.proto3.benchmark_message1_proto3_pb2 as benchmark_message1_proto3_pb2
import benchmarks.datasets.google_message2.benchmark_message2_pb2 as benchmark_message2_pb2
import benchmarks.datasets.google_message3.benchmark_message3_pb2 as benchmark_message3_pb2
import benchmarks.datasets.google_message4.benchmark_message4_pb2 as benchmark_message4_pb2
import benchmarks.benchmarks_pb2 as benchmarks_pb2
def run_one_test(filename):
data = open(filename, "rb").read()
benchmark_dataset = benchmarks_pb2.BenchmarkDataset()

@ -7,15 +7,15 @@ package(default_visibility = ["//benchmarks:__subpackages__"])
cc_binary(
name = "protoc-gen-proto2_to_proto3",
srcs = [
"schema_proto2_to_proto3_util.h",
"protoc-gen-proto2_to_proto3.cc",
"schema_proto2_to_proto3_util.h",
],
visibility = ["//benchmarks:__subpackages__"],
deps = [
"//:protobuf",
"//src/google/protobuf/compiler:code_generator",
"//benchmarks:benchmarks_cc_proto",
"//src/google/protobuf/compiler:code_generator",
],
visibility = ["//benchmarks:__subpackages__"],
)
cc_binary(
@ -26,8 +26,8 @@ cc_binary(
],
deps = [
"//:protobuf",
"//benchmarks/datasets:cc_protos",
"//benchmarks:benchmarks_cc_proto",
"//benchmarks/datasets:cc_protos",
],
)

@ -22,7 +22,7 @@ def proto3_from_proto2_data(
for src in srcs:
outs.append("proto3/" + src)
out_files.append("$(RULEDIR)/proto3/" + src)
src_files.append("$(rootpath %s)" % src);
src_files.append("$(rootpath %s)" % src)
native.genrule(
name = name + "_genrule",
@ -32,13 +32,15 @@ def proto3_from_proto2_data(
],
outs = outs,
cmd = "$(execpath //benchmarks/util:proto3_data_stripper) %s %s" % (
" ".join(src_files), " ".join(out_files)),
" ".join(src_files),
" ".join(out_files),
),
)
native.filegroup(
name = name,
srcs = outs,
**kwargs,
**kwargs
)
def _proto3_from_proto2_library(
@ -56,7 +58,7 @@ def _proto3_from_proto2_library(
src_files = []
for src in srcs:
outs.append(src + "3")
src_files.append("$(rootpath %s)" % src);
src_files.append("$(rootpath %s)" % src)
native.genrule(
name = name,
@ -74,7 +76,7 @@ def _proto3_from_proto2_library(
--proto2_to_proto3_out=$(GENDIR) \
%s
""" % (" ".join(src_files)),
**kwargs,
**kwargs
)
def php_proto3_from_proto2_library(
@ -99,5 +101,5 @@ def php_proto3_from_proto2_library(
name = name,
srcs = [name + "_genrule"],
outs = outs,
**kwargs,
**kwargs
)

@ -1,3 +1,5 @@
#include <fstream>
#include "benchmarks.pb.h"
#include "benchmarks/datasets/google_message1/proto2/benchmark_message1_proto2.pb.h"
#include "benchmarks/datasets/google_message1/proto3/benchmark_message1_proto3.pb.h"
@ -6,8 +8,6 @@
#include "benchmarks/datasets/google_message4/benchmark_message4.pb.h"
#include "data_proto2_to_proto3_util.h"
#include <fstream>
using google::protobuf::util::Proto3DataStripper;
std::string ReadFile(const std::string& name) {

@ -7,15 +7,15 @@
#include "google/protobuf/compiler/plugin.h"
using google::protobuf::FileDescriptorProto;
using google::protobuf::FileDescriptor;
using google::protobuf::DescriptorPool;
using google::protobuf::FileDescriptor;
using google::protobuf::FileDescriptorProto;
using google::protobuf::io::Printer;
using google::protobuf::util::SchemaGroupStripper;
using google::protobuf::util::EnumScrubber;
using google::protobuf::util::ExtensionStripper;
using google::protobuf::util::FieldScrubber;
using google::protobuf::util::ImportScrubber;
using google::protobuf::util::SchemaGroupStripper;
namespace google {
namespace protobuf {
@ -37,8 +37,7 @@ DescriptorPool* GetPool() {
class Proto2ToProto3Generator final : public CodeGenerator {
public:
bool GenerateAll(const std::vector<const FileDescriptor*>& files,
const std::string& parameter,
GeneratorContext* context,
const std::string& parameter, GeneratorContext* context,
std::string* error) const {
for (int i = 0; i < files.size(); i++) {
for (auto file : files) {
@ -52,10 +51,8 @@ class Proto2ToProto3Generator final : public CodeGenerator {
return true;
}
bool Generate(const FileDescriptor* file,
const std::string& parameter,
GeneratorContext* context,
std::string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const {
FileDescriptorProto new_file;
file->CopyTo(&new_file);
new_file.set_name(ImportScrubber::ScrubFilename(file->name()));
@ -82,9 +79,11 @@ class Proto2ToProto3Generator final : public CodeGenerator {
return true;
}
private:
bool CanGenerate(const FileDescriptor* file) const {
if (GetPool()->FindFileByName(ImportScrubber::ScrubFilename(file->name())) != nullptr) {
if (GetPool()->FindFileByName(
ImportScrubber::ScrubFilename(file->name())) != nullptr) {
return false;
}
for (int j = 0; j < file->dependency_count(); j++) {

@ -1,12 +1,14 @@
"""Parses benchmark results into a standardized json output."""
import argparse
import json
import re
import os.path
from benchmarks import benchmarks_pb2
# BEGIN OPENSOURCE
import sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
# END OPENSOURCE
from benchmarks import benchmarks_pb2
__file_size_map = {}

@ -9,9 +9,7 @@ def _arch_test_impl(
bazel_binaries = [],
system_binaries = [],
**kwargs):
"""
Bazel rule to verify that a Bazel or system binary is built for the
aarch64 architecture.
"""Bazel rule to verify that a Bazel or system binary is built for the aarch64 architecture.
Args:
name: the name of the test.
@ -19,7 +17,7 @@ def _arch_test_impl(
file_platform: the expected output of `file`.
bazel_binaries: a set of binary targets to inspect.
system_binaries: a set of paths to system executables to inspect.
**kargs: other keyword arguments that are passed to the test.
**kwargs: other keyword arguments that are passed to the test.
"""
inline_sh_test(
@ -30,27 +28,29 @@ def _arch_test_impl(
(file -L $$binary | grep -q "%s") \
|| (echo "Test binary is not an %s binary: "; file -L $$binary; exit 1)
done
""" % (" ".join(bazel_binaries),
""" % (
" ".join(bazel_binaries),
" ".join(system_binaries),
file_platform,
platform),
platform,
),
target_compatible_with = select({
"//build_defs:" + platform: [],
"//conditions:default": ["@platforms//:incompatible"],
}),
**kwargs
)
def aarch64_test(**kwargs):
_arch_test_impl(
platform = "aarch64",
file_platform = "ELF 64-bit LSB executable, ARM aarch64",
**kwargs,
**kwargs
)
def x86_64_test(**kwargs):
_arch_test_impl(
platform = "x86_64",
file_platform = "ELF 64-bit LSB executable, ARM x86_64",
**kwargs,
**kwargs
)

@ -1,3 +1,8 @@
"""
Internal tools to migrate shell commands to Bazel as an intermediate step
to wider Bazelification.
"""
def inline_sh_binary(
name,
srcs = [],
@ -6,9 +11,11 @@ def inline_sh_binary(
cmd = "",
testonly = None,
**kwargs):
"""Bazel rule to wrap up an inline bash script in a binary. This is most
useful as a stop-gap solution for migrating off Autotools. These binaries
are likely to be non-hermetic, with implicit system dependencies.
"""Bazel rule to wrap up an inline bash script in a binary.
This is most useful as a stop-gap solution for migrating off Autotools.
These binaries are likely to be non-hermetic, with implicit system
dependencies.
NOTE: the rule is only an internal workaround. The interface may change and
the rule may be removed when everything is properly "Bazelified".
@ -19,12 +26,12 @@ def inline_sh_binary(
tools: the executable tools used directly by the script. Any target used
with rootpath/execpath/location must be declared here or in `srcs`.
deps: a list of dependency labels that are required to run this binary.
**kargs: other keyword arguments that are passed to sh_binary.
cmd: the inline sh command to run.
**kwargs: other keyword arguments that are passed to sh_binary.
testonly: common rule attribute (see:
https://bazel.build/reference/be/common-definitions#common-attributes)
"""
native.genrule(
name = name + "_genrule",
srcs = srcs,
@ -50,9 +57,10 @@ def inline_sh_test(
deps = [],
cmd = "",
**kwargs):
"""Bazel rule to wrap up an inline bash script in a test. This is most
useful as a stop-gap solution for migrating off Autotools. These tests
are likely to be non-hermetic, with implicit system dependencies.
"""Bazel rule to wrap up an inline bash script in a test.
This is most useful as a stop-gap solution for migrating off Autotools.
These tests are likely to be non-hermetic, with implicit system dependencies.
NOTE: the rule is only an internal workaround. The interface may change and
the rule may be removed when everything is properly "Bazelified".
@ -63,11 +71,11 @@ def inline_sh_test(
tools: the executable tools used directly by the script. Any target used
with rootpath/execpath/location must be declared here or in `srcs`.
deps: a list of dependency labels that are required to run this binary.
**kargs: other keyword arguments that are passed to sh_binary.
cmd: the inline sh command to run.
**kwargs: other keyword arguments that are passed to sh_binary.
https://bazel.build/reference/be/common-definitions#common-attributes)
"""
native.genrule(
name = name + "_genrule",
srcs = srcs,

@ -1,8 +1,7 @@
# Conformance testing for Protobuf.
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library", "objc_library")
load("@rules_python//python:defs.bzl", "py_library")
load("//:protobuf.bzl", "internal_py_proto_library", "internal_php_proto_library", "internal_csharp_proto_library", "internal_ruby_proto_library", "internal_objc_proto_library")
load("//:protobuf.bzl", "internal_csharp_proto_library", "internal_objc_proto_library", "internal_php_proto_library", "internal_py_proto_library", "internal_ruby_proto_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load(
"@rules_pkg//:mappings.bzl",
@ -94,10 +93,10 @@ internal_objc_proto_library(
internal_py_proto_library(
name = "conformance_py_proto",
srcs = ["conformance.proto"],
srcs_version = "PY2AND3",
visibility = [
"//python:__subpackages__",
],
srcs_version = "PY2AND3",
)
internal_php_proto_library(
@ -183,21 +182,25 @@ cc_binary(
cc_binary(
name = "conformance_cpp",
testonly = 1,
srcs = ["conformance_cpp.cc"],
visibility = ["//src:__subpackages__"],
deps = [
":conformance_cc_proto",
"//:protobuf",
"//:test_messages_proto2_cc_proto",
"//:test_messages_proto3_cc_proto",
],
testonly = 1,
visibility = ["//src:__subpackages__"],
)
java_binary(
name = "conformance_java",
testonly = 1,
srcs = ["ConformanceJava.java"],
main_class = "ConformanceJava",
visibility = [
"//java:__subpackages__",
],
deps = [
":conformance_java_proto",
"//:protobuf_java",
@ -205,14 +208,12 @@ java_binary(
"//:test_messages_proto2_java_proto",
"//:test_messages_proto3_java_proto",
],
testonly = 1,
visibility = [
"//java:__subpackages__",
],
)
java_binary(
name = "conformance_java_lite",
testonly = 1,
srcs = ["ConformanceJavaLite.java"],
main_class = "ConformanceJavaLite",
visibility = [
"//java:__subpackages__",
@ -224,110 +225,111 @@ java_binary(
"//:test_messages_proto2_java_proto_lite",
"//:test_messages_proto3_java_proto_lite",
],
testonly = 1,
srcs = ["ConformanceJavaLite.java"],
)
py_binary(
name = "conformance_python",
testonly = 1,
srcs = ["conformance_python.py"],
imports = [
"..",
"../python",
],
srcs_version = "PY2AND3",
visibility = ["//python:__subpackages__"],
deps = [
":conformance_py_proto",
"//:protobuf_python",
"//python:test_messages_proto2_py_proto",
"//python:test_messages_proto3_py_proto",
],
imports = [".", "../python"],
srcs_version = "PY2AND3",
testonly = 1,
visibility = ["//python:__subpackages__"],
)
inline_sh_binary(
name = "conformance_php",
testonly = 1,
srcs = [
"conformance_php.php",
"autoload.php",
],
deps = [
":conformance_php_proto",
"//php:source_files",
"//:test_messages_proto3_php_proto",
"conformance_php.php",
],
cmd = """
php -d include_path=conformance:src/google/protobuf \\
-d auto_prepend_file=$(rootpath autoload.php) \\
$(rootpath conformance_php.php)
""",
testonly = 1,
visibility = ["//php:__subpackages__"],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
"//php:source_files",
],
)
inline_sh_binary(
name = "conformance_php_c",
testonly = 1,
srcs = [
"conformance_php.php",
"//php:extension",
],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
],
cmd = """
php -dextension=$(rootpath //php:extension) \\
-d include_path=conformance:src/google/protobuf \\
$(rootpath conformance_php.php)
""",
testonly = 1,
visibility = ["//php:__subpackages__"],
deps = [
":conformance_php_proto",
"//:test_messages_proto3_php_proto",
],
)
inline_sh_binary(
name = "conformance_csharp",
testonly = 1,
srcs = ["//csharp/src/Google.Protobuf.Conformance:conformance_dll"],
cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/src/Google.Protobuf.Conformance:conformance_runfiles",
],
cmd = "dotnet $(rootpath //csharp/src/Google.Protobuf.Conformance:conformance_dll)",
testonly = 1,
visibility = ["//csharp:__subpackages__"],
)
objc_library(
name = "conformance_objc_lib",
testonly = 1,
non_arc_srcs = ["conformance_objc.m"],
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
deps = [
":conformance_objc_proto",
"//:test_messages_proto2_objc_proto",
"//:test_messages_proto3_objc_proto",
],
testonly = 1,
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
)
cc_binary(
name = "conformance_objc",
deps = [":conformance_objc_lib"],
testonly = 1,
# See https://github.com/bazelbuild/bazel/issues/12897.
tags = ["manual"],
visibility = ["//objectivec:__subpackages__"],
deps = [":conformance_objc_lib"],
)
inline_sh_binary(
name = "conformance_ruby",
testonly = 1,
srcs = ["conformance_ruby.rb"],
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
visibility = ["//ruby:__subpackages__"],
deps = [
":conformance_ruby_proto",
"//:well_known_ruby_protos",
"//:test_messages_proto2_ruby_proto",
"//:test_messages_proto3_ruby_proto",
"//:well_known_ruby_protos",
"//ruby:protobuf",
],
cmd = "RUBYLIB=ruby/lib:conformance:src $(rootpath conformance_ruby.rb)",
testonly = 1,
visibility = ["//ruby:__subpackages__"],
)
################################################################################

@ -45,6 +45,7 @@
#include <google/protobuf/stubs/status.h>
#include <google/protobuf/stubs/statusor.h>
#include "conformance/conformance.pb.h"
#include "conformance/conformance.pb.h"
#include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/test_messages_proto3.pb.h>

@ -42,7 +42,7 @@ from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2
from conformance import conformance_pb2
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)

@ -42,7 +42,7 @@
#include <google/protobuf/util/field_comparator.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/message_differencer.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
using conformance::ConformanceRequest;
using conformance::ConformanceResponse;

@ -45,7 +45,7 @@
#include <google/protobuf/descriptor.h>
#include <google/protobuf/wire_format_lite.h>
#include <google/protobuf/util/type_resolver.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
namespace conformance {
class ConformanceRequest;

@ -63,7 +63,7 @@
#include <vector>
#include <google/protobuf/stubs/stringprintf.h>
#include "conformance.pb.h"
#include "conformance/conformance.pb.h"
#include "conformance_test.h"
using conformance::ConformanceResponse;

@ -39,7 +39,7 @@ def conformance_test(
"@bazel_tools//tools/bash/runfiles",
],
tags = ["conformance"],
**kwargs,
**kwargs
)
def _strip_bazel(testee):

@ -62,7 +62,7 @@ do
PROTOC=$BOOTSTRAP_PROTOC
BOOTSTRAP_PROTOC=""
else
bazel build -j$(nproc) $@ //:protoc
bazel build $@ //:protoc
if test $? -ne 0; then
echo "Failed to build protoc."
exit 1

@ -1,7 +1,7 @@
package(default_visibility = ["//java:__subpackages__"])
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
package(default_visibility = ["//java:__subpackages__"])
pkg_files(
name = "dist_files",
srcs = [
@ -15,8 +15,8 @@ pkg_files(
java_test(
name = "java_version",
test_class = "JavaVersionTest",
srcs = ["JavaVersionTest.java"],
test_class = "JavaVersionTest",
deps = [
"@maven//:com_google_truth_truth",
"@maven//:junit_junit",

@ -25,6 +25,7 @@ kt_jvm_library(
deps = [
":only_for_use_in_proto_generated_code_its_generator_and_tests",
"//java/lite",
"@maven//:com_google_errorprone_error_prone_annotations",
],
)

@ -34,6 +34,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>

@ -1,10 +1,10 @@
{
"dependency_tree": {
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 579287445,
"__INPUT_ARTIFACTS_HASH": -1875290602,
"__RESOLVED_ARTIFACTS_HASH": -1248440885,
"conflict_resolution": {
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.11.0"
"com.google.errorprone:error_prone_annotations:2.5.1": "com.google.errorprone:error_prone_annotations:2.11.0"
},
"dependencies": [
{

@ -381,9 +381,9 @@ cc_dist_library(
"//src/google/protobuf/util:differencer",
"//src/google/protobuf/util:field_mask_util",
"//src/google/protobuf/util:json_util",
"//src/google/protobuf/util:zero_copy_sink",
"//src/google/protobuf/util:time_util",
"//src/google/protobuf/util:type_resolver_util",
"//src/google/protobuf/util:zero_copy_sink",
"//src/google/protobuf/util/internal:datapiece",
"//src/google/protobuf/util/internal:default_value",
"//src/google/protobuf/util/internal:field_mask_utility",
@ -427,23 +427,23 @@ cc_dist_library(
cc_dist_library(
name = "compiler_annotation_test_util",
deps = ["//src/google/protobuf/compiler:annotation_test_util"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/compiler:annotation_test_util"],
)
cc_dist_library(
name = "compiler_mock_code_generator",
deps = ["//src/google/protobuf/compiler:mock_code_generator"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/compiler:mock_code_generator"],
)
cc_dist_library(
name = "testinglib",
deps = ["//src/google/protobuf/testing"],
testonly = 1,
tags = ["manual"],
deps = ["//src/google/protobuf/testing"],
)
################################################################################

@ -6,7 +6,7 @@ PROTOBUF_MAVEN_ARTIFACTS = [
"com.google.caliper:caliper:1.0-beta-3",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.8.9",
"com.google.errorprone:error_prone_annotations:2.3.2",
"com.google.errorprone:error_prone_annotations:2.5.1",
"com.google.j2objc:j2objc-annotations:1.3",
"com.google.guava:guava:31.1-jre",
"com.google.guava:guava-testlib:31.1-jre",

@ -7,7 +7,6 @@
# //:well_known_types_py_pb2
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("//:protobuf.bzl", "internal_py_proto_library")
load("//build_defs:cpp_opts.bzl", "COPTS")
@ -53,8 +52,8 @@ internal_py_proto_library(
internal_copy_files(
name = "copied_wkt_proto_files",
srcs = [
"//src/google/protobuf:descriptor_proto_srcs",
"//:well_known_type_protos",
"//src/google/protobuf:descriptor_proto_srcs",
],
strip_prefix = "src",
)
@ -216,28 +215,28 @@ internal_py_proto_library(
internal_py_proto_library(
name = "test_messages_proto2_py_proto",
testonly = 1,
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
srcs = [":copied_test_messages_proto2_files"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
)
internal_py_proto_library(
name = "test_messages_proto3_py_proto",
testonly = 1,
srcs = [":copied_test_messages_proto3_files"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
visibility = [
"//conformance:__pkg__",
"//python:__subpackages__",
],
srcs = [":copied_test_messages_proto3_files"],
deps = [":well_known_types_py_pb2"],
include = ".",
default_runtime = "//:protobuf_python",
protoc = "//:protoc",
)
py_library(
@ -400,27 +399,27 @@ py_test(
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_python.txt",
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python.txt",
env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "python"},
failure_list = "//conformance:failure_list_python.txt",
target_compatible_with = select({
":use_fast_cpp_protos": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python.txt",
)
# Note: this requires --define=use_fast_cpp_protos=true
conformance_test(
name = "conformance_test_cpp",
failure_list = "//conformance:failure_list_python.txt",
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt",
env = {"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": "cpp"},
failure_list = "//conformance:failure_list_python.txt",
target_compatible_with = select({
":use_fast_cpp_protos": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
testee = "//conformance:conformance_python",
text_format_failure_list = "//conformance:text_format_failure_list_python_cpp.txt",
)
################################################################################

@ -27,12 +27,12 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Test that Kokoro is using the expected version of python."""
import os
import unittest
import sys
import unittest
class PythonVersionTest(unittest.TestCase):
@ -40,11 +40,12 @@ class PythonVersionTest(unittest.TestCase):
"""Test that we can import nested import public messages."""
exp = os.getenv('KOKORO_PYTHON_VERSION', '')
if exp == '':
print("No kokoro python version found, skipping check", file=sys.stderr)
if not exp:
print('No kokoro python version found, skipping check', file=sys.stderr)
return
self.assertTrue(sys.version.startswith(exp),
"Expected Python %s but found Python %s" % (exp, sys.version))
self.assertTrue(
sys.version.startswith(exp),
'Expected Python %s but found Python %s' % (exp, sys.version))
if __name__ == '__main__':

@ -306,7 +306,8 @@ if __name__ == '__main__':
else:
library_dirs = ['..']
TestConformanceCmd.target = '//python:conformance_test_cpp --define=use_fast_cpp_protos=true'
TestConformanceCmd.target = ('//python:conformance_test_cpp '
'--define=use_fast_cpp_protos=true')
extra_compile_args = []

@ -216,8 +216,8 @@ cc_library(
"field_mask.pb.cc",
"generated_message_bases.cc",
"generated_message_reflection.cc",
"generated_message_tctable_gen.cc",
"generated_message_tctable_full.cc",
"generated_message_tctable_gen.cc",
"map_field.cc",
"message.cc",
"reflection_ops.cc",
@ -458,13 +458,16 @@ proto_library(
],
)
exports_files([
exports_files(
[
"test_messages_proto2.proto",
"test_messages_proto3.proto",
], visibility = [
],
visibility = [
"//:__pkg__",
"//python:__pkg__",
])
],
)
proto_library(
name = "test_messages_proto2_proto",
@ -480,6 +483,10 @@ proto_library(
name = "test_messages_proto3_proto",
srcs = ["test_messages_proto3.proto"],
strip_import_prefix = "/src",
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
],
deps = [
":any_proto",
":duration_proto",
@ -488,10 +495,6 @@ proto_library(
":timestamp_proto",
":wrappers_proto",
],
visibility = [
"//:__pkg__",
"//conformance:__pkg__",
],
)
cc_proto_library(

@ -6,7 +6,6 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
"pkg_filegroup",
"pkg_files",
"strip_prefix",
)
@ -116,7 +115,6 @@ alias(
visibility = ["//visibility:public"],
)
# Test that the protoc binary is built for the correct architecture.
aarch64_test(
name = "protoc_aarch64_test",

@ -359,7 +359,8 @@ void CommandLineInterfaceTest::RunWithArgs(std::vector<std::string> args) {
if (plugin_path.empty() || !FileExists(plugin_path)) {
GOOGLE_LOG(ERROR)
<< "Plugin tests are likely to fail. Plugin executable not found at: " << plugin_path;
<< "Plugin executable not found. Plugin tests are likely to fail."
<< plugin_path;
} else {
args.push_back("--plugin=prefix-gen-plug=" + plugin_path);
}

@ -43,7 +43,7 @@ namespace compiler {
namespace java {
Context::Context(const FileDescriptor* file, const Options& options)
: name_resolver_(new ClassNameResolver), options_(options) {
: name_resolver_(new ClassNameResolver(options)), options_(options) {
InitializeFieldGeneratorInfo(file);
}

@ -96,6 +96,7 @@ void WriteMethodDocComment(io::Printer* printer,
const MethodDescriptor* method);
// Exposed for testing only.
// Also called by proto1-Java code generator.
PROTOC_EXPORT std::string EscapeJavadoc(const std::string& input);
} // namespace java

@ -80,6 +80,10 @@ EnumGenerator::~EnumGenerator() {}
void EnumGenerator::Generate(io::Printer* printer) {
WriteEnumDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_, immutable_api_);
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"$deprecation$public enum $classname$\n"
" implements com.google.protobuf.ProtocolMessageEnum {\n",
@ -181,7 +185,9 @@ void EnumGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
"\n"
"\n");
if (context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
@ -192,12 +198,19 @@ void EnumGenerator::Generate(io::Printer* printer) {
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n",
"classname", descriptor_->name());
}
printer->Print(
"/**\n"
" * @param value The numeric wire value of the corresponding enum "
"entry.\n"
" * @return The enum associated with the given numeric wire value.\n"
" */\n"
" */\n");
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
}
printer->Print(
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n",
"classname", descriptor_->name());

@ -60,7 +60,8 @@ namespace {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -68,7 +69,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
@ -142,7 +144,7 @@ ImmutableEnumFieldGenerator::ImmutableEnumFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
ImmutableEnumFieldGenerator::~ImmutableEnumFieldGenerator() {}
@ -636,7 +638,7 @@ RepeatedImmutableEnumFieldGenerator::RepeatedImmutableEnumFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
RepeatedImmutableEnumFieldGenerator::~RepeatedImmutableEnumFieldGenerator() {}

@ -68,7 +68,8 @@ bool EnableExperimentalRuntimeForLite() {
void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -76,7 +77,8 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["kt_type"] = EscapeKotlinKeywords((*variables)["type"]);
(*variables)["mutable_type"] =
name_resolver->GetMutableClassName(descriptor->enum_type());
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_number"] =
StrCat(descriptor->default_value_enum()->number());
(*variables)["tag"] = StrCat(
@ -95,6 +97,12 @@ void SetEnumVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (HasHasbit(descriptor)) {
if (!context->options().opensource_runtime) {
(*variables)["bit_field_id"] = StrCat(messageBitIndex / 32);
(*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
(*variables)["bit_field_mask"] =
StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
@ -142,7 +150,7 @@ ImmutableEnumFieldLiteGenerator::ImmutableEnumFieldLiteGenerator(
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
ImmutableEnumFieldLiteGenerator::~ImmutableEnumFieldLiteGenerator() {}
@ -169,6 +177,20 @@ void ImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
void ImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
" isRequired=$required$)\n");
if (HasHazzer(descriptor_)) {
printer->Print(variables_,
"@com.google.protobuf.ProtoPresenceCheckedField(\n"
" presenceBitsId=$bit_field_id$,\n"
" mask=$bit_field_mask$)\n");
}
}
printer->Print(variables_, "private int $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@ -514,7 +536,7 @@ RepeatedImmutableEnumFieldLiteGenerator::
name_resolver_(context->GetNameResolver()) {
SetEnumVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor), name_resolver_,
&variables_);
&variables_, context);
}
RepeatedImmutableEnumFieldLiteGenerator::
@ -550,6 +572,13 @@ void RepeatedImmutableEnumFieldLiteGenerator::GenerateInterfaceMembers(
void RepeatedImmutableEnumFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
}
printer->Print(
variables_,
"private com.google.protobuf.Internal.IntList $name$_;\n"

@ -153,7 +153,9 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
printer->Print(
" return value;\n"
"}\n"
"\n"
"\n");
if (context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * @param value The number of the enum to look for.\n"
" * @return The enum associated with the given number.\n"
@ -163,7 +165,14 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
"public static $classname$ valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n",
"classname", descriptor_->name());
}
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoMethodMayReturnNull\n");
}
printer->Print(
"public static $classname$ forNumber(int value) {\n"
" switch (value) {\n",
"classname", descriptor_->name());
@ -212,6 +221,35 @@ void EnumLiteGenerator::Generate(io::Printer* printer) {
" };\n"
"\n",
"classname", descriptor_->name());
if (!context_->options().opensource_runtime) {
printer->Print(
"/**\n"
" * Override of toString that prints the number and name.\n"
" * This is primarily intended as a developer aid.\n"
" *\n"
" * <p>NOTE: This implementation is liable to change in the future,\n"
" * and should not be relied on in code.\n"
" */\n"
"@java.lang.Override\n"
"public java.lang.String toString() {\n"
" StringBuilder result = new StringBuilder(\"<\");\n"
" result.append(getClass().getName()).append('@')\n"
" .append(java.lang.Integer.toHexString(\n"
" java.lang.System.identityHashCode(this)));\n");
if (SupportUnknownEnumValue(descriptor_->file())) {
printer->Print(
" if (this != UNRECOGNIZED) {\n"
" result.append(\" number=\").append(getNumber());\n"
" }\n");
} else {
printer->Print(" result.append(\" number=\").append(getNumber());\n");
}
printer->Print(
" return result.append(\" name=\")\n"
" .append(name()).append('>').toString();\n"
"}\n"
"\n");
}
printer->Print(
"private final int value;\n\n"

@ -51,7 +51,9 @@ namespace java {
ImmutableExtensionGenerator::ImmutableExtensionGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@ -66,7 +68,7 @@ ImmutableExtensionGenerator::~ImmutableExtensionGenerator() {}
void ExtensionGenerator::InitTemplateVars(
const FieldDescriptor* descriptor, const std::string& scope, bool immutable,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer) {
std::map<std::string, std::string>* vars_pointer, Context* context) {
std::map<std::string, std::string>& vars = *vars_pointer;
vars["scope"] = scope;
vars["name"] = UnderscoresToCamelCaseCheckReserved(descriptor);
@ -77,7 +79,8 @@ void ExtensionGenerator::InitTemplateVars(
vars["index"] = StrCat(descriptor->index());
vars["default"] = descriptor->is_repeated()
? ""
: DefaultValue(descriptor, immutable, name_resolver);
: DefaultValue(descriptor, immutable, name_resolver,
context->options());
vars["type_constant"] = FieldTypeName(GetType(descriptor));
vars["packed"] = descriptor->is_packed() ? "true" : "false";
vars["enum_map"] = "null";
@ -116,7 +119,7 @@ void ImmutableExtensionGenerator::Generate(io::Printer* printer) {
std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
&vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);

@ -79,10 +79,11 @@ class ExtensionGenerator {
virtual int GenerateRegistrationCode(io::Printer* printer) = 0;
protected:
static void InitTemplateVars(
const FieldDescriptor* descriptor, const std::string& scope,
bool immutable, ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer);
static void InitTemplateVars(const FieldDescriptor* descriptor,
const std::string& scope, bool immutable,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* vars_pointer,
Context* context);
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionGenerator);
@ -102,6 +103,7 @@ class ImmutableExtensionGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
std::string scope_;
Context* context_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionGenerator);

@ -47,7 +47,9 @@ namespace java {
ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator(
const FieldDescriptor* descriptor, Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
if (descriptor_->extension_scope() != NULL) {
scope_ =
name_resolver_->GetImmutableClassName(descriptor_->extension_scope());
@ -62,7 +64,7 @@ void ImmutableExtensionLiteGenerator::Generate(io::Printer* printer) {
std::map<std::string, std::string> vars;
const bool kUseImmutableNames = true;
InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
&vars);
&vars, context_);
printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
WriteFieldDocComment(printer, descriptor_);

@ -63,6 +63,7 @@ class ImmutableExtensionLiteGenerator : public ExtensionGenerator {
const FieldDescriptor* descriptor_;
ClassNameResolver* name_resolver_;
std::string scope_;
Context* context_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableExtensionLiteGenerator);
};

@ -188,7 +188,7 @@ void MaybeRestartJavaMethod(io::Printer* printer, int* bytecode_estimate,
FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options,
bool immutable_api)
: file_(file),
java_package_(FileJavaPackage(file, immutable_api)),
java_package_(FileJavaPackage(file, immutable_api, options)),
message_generators_(file->message_type_count()),
extension_generators_(file->extension_count()),
context_(new Context(file, options)),
@ -271,8 +271,12 @@ void FileGenerator::Generate(io::Printer* printer) {
"package", java_package_);
}
PrintGeneratedAnnotation(
printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "");
printer, '$', options_.annotate_code ? classname_ + ".java.pb.meta" : "",
options_);
if (!options_.opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"$deprecation$public final class $classname$ {\n"
" private $ctor$() {}\n",
@ -401,11 +405,14 @@ void FileGenerator::GenerateDescriptorInitializationCodeForImmutable(
" descriptor;\n"
"static {\n",
// TODO(dweis): Mark this as final.
"final", "");
"final", options_.opensource_runtime ? "" : "final");
printer->Indent();
if (options_.opensource_runtime) {
SharedCodeGenerator shared_code_generator(file_, options_);
shared_code_generator.GenerateDescriptors(printer);
} else {
}
int bytecode_estimate = 0;
int method_num = 0;
@ -499,8 +506,8 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
printer->Print(
"descriptor = $immutable_package$.$descriptor_classname$.descriptor;\n",
"immutable_package", FileJavaPackage(file_, true), "descriptor_classname",
name_resolver_->GetDescriptorClassName(file_));
"immutable_package", FileJavaPackage(file_, true, options_),
"descriptor_classname", name_resolver_->GetDescriptorClassName(file_));
for (int i = 0; i < file_->message_type_count(); i++) {
message_generators_[i]->GenerateStaticVariableInitializers(printer);
@ -547,7 +554,7 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(
scope = name_resolver_->GetMutableClassName(field->extension_scope()) +
".getDescriptor()";
} else {
scope = FileJavaPackage(field->file(), true) + "." +
scope = FileJavaPackage(field->file(), true, options_) + "." +
name_resolver_->GetDescriptorClassName(field->file()) +
".descriptor";
}

@ -74,6 +74,8 @@ bool JavaGenerator::Generate(const FileDescriptor* file,
ParseGeneratorParameter(parameter, &options);
Options file_options;
file_options.opensource_runtime = opensource_runtime_;
for (int i = 0; i < options.size(); i++) {
if (options[i].first == "output_list_file") {
file_options.output_list_file = options[i].second;

@ -68,7 +68,7 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
}
private:
bool opensource_runtime_ = true;
bool opensource_runtime_ = PROTO2_IS_OSS;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator);
};

@ -66,8 +66,9 @@ const char kThinSeparator[] =
"// -------------------------------------------------------------------\n";
namespace {
const char* kDefaultPackage = "";
const char* DefaultPackage(Options options) {
return options.opensource_runtime ? "" : "com.google.protos";
}
// Names that should be avoided (in UpperCamelCase format).
// Using them will cause the compiler to generate accessors whose names
@ -136,7 +137,8 @@ std::string FieldName(const FieldDescriptor* field) {
} // namespace
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter,
const std::string& annotation_file) {
const std::string& annotation_file,
Options options) {
if (annotation_file.empty()) {
return;
}
@ -305,17 +307,17 @@ std::string CamelCaseFieldName(const FieldDescriptor* field) {
}
std::string FileClassName(const FileDescriptor* file, bool immutable) {
ClassNameResolver name_resolver;
return name_resolver.GetFileClassName(file, immutable);
return ClassNameResolver().GetFileClassName(file, immutable);
}
std::string FileJavaPackage(const FileDescriptor* file, bool immutable) {
std::string FileJavaPackage(const FileDescriptor* file, bool immutable,
Options options) {
std::string result;
if (file->options().has_java_package()) {
result = file->options().java_package();
} else {
result = kDefaultPackage;
result = DefaultPackage(options);
if (!file->package().empty()) {
if (!result.empty()) result += '.';
result += file->package();
@ -325,8 +327,8 @@ std::string FileJavaPackage(const FileDescriptor* file, bool immutable) {
return result;
}
std::string FileJavaPackage(const FileDescriptor* file) {
return FileJavaPackage(file, true /* immutable */);
std::string FileJavaPackage(const FileDescriptor* file, Options options) {
return FileJavaPackage(file, true /* immutable */, options);
}
std::string JavaPackageToDir(std::string package_name) {
@ -532,7 +534,7 @@ std::string GetOneofStoredType(const FieldDescriptor* field) {
case JAVATYPE_ENUM:
return "java.lang.Integer";
case JAVATYPE_MESSAGE:
return ClassName(field->message_type());
return ClassNameResolver().GetClassName(field->message_type(), true);
default:
return BoxedPrimitiveTypeName(javaType);
}
@ -595,7 +597,7 @@ bool AllAscii(const std::string& text) {
}
std::string DefaultValue(const FieldDescriptor* field, bool immutable,
ClassNameResolver* name_resolver) {
ClassNameResolver* name_resolver, Options options) {
// Switch on CppType since we need to know which default_value_* method
// of FieldDescriptor to call.
switch (field->cpp_type()) {
@ -819,7 +821,8 @@ bool IsReferenceType(JavaType type) {
return false;
}
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable) {
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable,
Options options) {
switch (GetType(field)) {
case FieldDescriptor::TYPE_INT32:
return "Int32";

@ -41,8 +41,12 @@
#include <google/protobuf/io/printer.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/compiler/java/context.h>
#include <google/protobuf/compiler/java/options.h>
#include <google/protobuf/descriptor.pb.h>
// Must be last.
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace compiler {
@ -64,7 +68,8 @@ bool IsForbiddenKotlin(const std::string& field_name);
// annotation_file should be generated from the filename of the source file
// being annotated (which in turn must be a Java identifier plus ".java").
void PrintGeneratedAnnotation(io::Printer* printer, char delimiter = '$',
const std::string& annotation_file = "");
const std::string& annotation_file = "",
Options options = {});
// If a GeneratedMessageLite contains non-lite enums, then its verifier
// must be instantiated inline, rather than retrieved from the enum class.
@ -113,7 +118,8 @@ std::string UniqueFileScopeIdentifier(const Descriptor* descriptor);
std::string FileClassName(const FileDescriptor* file, bool immutable = true);
// Returns the file's Java package name.
std::string FileJavaPackage(const FileDescriptor* file, bool immutable);
std::string FileJavaPackage(const FileDescriptor* file, bool immutable,
Options options = {});
// Returns output directory for the given package name.
std::string JavaPackageToDir(std::string package_name);
@ -209,7 +215,8 @@ void MaybePrintGeneratedAnnotation(Context* context, io::Printer* printer,
PrintGeneratedAnnotation(printer, '$',
context->options().annotate_code
? AnnotationFileName(descriptor, suffix)
: "");
: "",
context->options());
}
}
@ -254,10 +261,12 @@ const char* FieldTypeName(const FieldDescriptor::Type field_type);
class ClassNameResolver;
std::string DefaultValue(const FieldDescriptor* field, bool immutable,
ClassNameResolver* name_resolver);
ClassNameResolver* name_resolver,
Options options = {});
inline std::string ImmutableDefaultValue(const FieldDescriptor* field,
ClassNameResolver* name_resolver) {
return DefaultValue(field, true, name_resolver);
ClassNameResolver* name_resolver,
Options options = {}) {
return DefaultValue(field, true, name_resolver, options);
}
bool IsDefaultValueJavaDefault(const FieldDescriptor* field);
bool IsByteStringWithCustomDefaultValue(const FieldDescriptor* field);
@ -336,7 +345,8 @@ bool IsReferenceType(JavaType type);
// Returns the capitalized name for calling relative functions in
// CodedInputStream
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable);
const char* GetCapitalizedType(const FieldDescriptor* field, bool immutable,
Options options);
// For encodings with fixed sizes, returns that size in bytes. Otherwise
// returns -1.
@ -474,4 +484,5 @@ std::pair<int, int> GetTableDrivenNumberOfEntriesAndLookUpStartFieldNumber(
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_HELPERS_H__

@ -102,7 +102,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
std::string pass_through_nullness = "/* nullable */\n";
// The code that generates the open-source version appears not to understand
// #else, so we have an #ifndef instead.
std::string pass_through_nullness =
context->options().opensource_runtime
? "/* nullable */\n"
: "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
std::string boxed_key_type = TypeName(key, name_resolver, true);
@ -113,7 +118,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["short_key_type"] =
boxed_key_type.substr(boxed_key_type.rfind('.') + 1);
(*variables)["key_wire_type"] = WireType(key);
(*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
(*variables)["key_default_value"] =
DefaultValue(key, true, name_resolver, context->options());
(*variables)["key_null_check"] =
IsReferenceType(keyJavaType)
? "if (key == null) { throw new NullPointerException(\"map key\"); }"
@ -132,7 +138,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver) + ".getNumber()";
DefaultValue(value, true, name_resolver, context->options()) +
".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
@ -146,7 +153,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
@ -158,7 +165,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
(*variables)["type_parameters"] =
(*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
@ -194,7 +201,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMapFieldGenerator::ImmutableMapFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor), context,
&variables_);
@ -218,6 +227,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -226,6 +236,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -277,6 +288,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -285,6 +297,7 @@ void ImmutableMapFieldGenerator::GenerateInterfaceMembers(
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@ -401,6 +414,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
@ -413,6 +427,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" internalGetMutable$capitalized_name$().getMutableMap());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$public Builder ${$put$capitalized_name$$}$(\n"
@ -437,6 +452,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (SupportUnknownEnumValue(descriptor_->file())) {
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
@ -448,6 +464,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -473,6 +490,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
@ -484,6 +502,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" return internalGetMutable$capitalized_name$().getMutableMap();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$"
@ -530,7 +549,9 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
@ -541,6 +562,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -640,6 +662,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -651,6 +674,7 @@ void ImmutableMapFieldGenerator::GenerateMapGetters(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"

@ -71,6 +71,7 @@ class ImmutableMapFieldGenerator : public ImmutableFieldGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
void GenerateMapGetters(io::Printer* printer) const;
};

@ -104,14 +104,18 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
const JavaType keyJavaType = GetJavaType(key);
const JavaType valueJavaType = GetJavaType(value);
std::string pass_through_nullness = "/* nullable */\n";
std::string pass_through_nullness =
context->options().opensource_runtime
? "/* nullable */\n"
: "@com.google.protobuf.Internal.ProtoPassThroughNullness ";
(*variables)["key_type"] = TypeName(key, name_resolver, false);
(*variables)["boxed_key_type"] = TypeName(key, name_resolver, true);
(*variables)["kt_key_type"] = KotlinTypeName(key, name_resolver);
(*variables)["kt_value_type"] = KotlinTypeName(value, name_resolver);
(*variables)["key_wire_type"] = WireType(key);
(*variables)["key_default_value"] = DefaultValue(key, true, name_resolver);
(*variables)["key_default_value"] =
DefaultValue(key, true, name_resolver, context->options());
// We use `x.getClass()` as a null check because it generates less bytecode
// than an `if (x == null) { throw ... }` statement.
(*variables)["key_null_check"] =
@ -131,7 +135,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = "java.lang.Integer";
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver) + ".getNumber()";
DefaultValue(value, true, name_resolver, context->options()) +
".getNumber()";
(*variables)["value_enum_type"] = TypeName(value, name_resolver, false);
@ -145,7 +150,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
} else {
// Map unknown values to the default value if we don't have UNRECOGNIZED.
(*variables)["unrecognized_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
} else {
(*variables)["value_type"] = TypeName(value, name_resolver, false);
@ -157,7 +162,7 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["boxed_value_type"] = TypeName(value, name_resolver, true);
(*variables)["value_wire_type"] = WireType(value);
(*variables)["value_default_value"] =
DefaultValue(value, true, name_resolver);
DefaultValue(value, true, name_resolver, context->options());
}
(*variables)["type_parameters"] =
(*variables)["boxed_key_type"] + ", " + (*variables)["boxed_value_type"];
@ -203,6 +208,7 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
" $key_type$ key);\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -211,6 +217,7 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
"java.util.Map<$boxed_key_type$, $value_enum_type$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -262,6 +269,7 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -270,6 +278,7 @@ void ImmutableMapFieldLiteGenerator::GenerateInterfaceMembers(
"java.util.Map<$type_parameters$>\n"
"${$get$capitalized_name$$}$();\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"$deprecation$java.util.Map<$type_parameters$>\n"
@ -306,6 +315,12 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" $value_wire_type$,\n"
" $value_default_value$);\n"
"}\n");
if (!context_->options().opensource_runtime) {
printer->Print(variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.MAP)\n");
}
printer->Print(variables_,
"private com.google.protobuf.MapFieldLite<\n"
" $type_parameters$> $name$_ =\n"
@ -347,7 +362,9 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" com.google.protobuf.Internal.MapAdapter.newEnumConverter(\n"
" $value_enum_type$.internalGetValueMap(),\n"
" $unrecognized_value$);\n");
printer->Print(variables_,
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
@ -357,6 +374,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
@ -461,6 +479,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -472,6 +491,7 @@ void ImmutableMapFieldLiteGenerator::GenerateMembers(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -602,7 +622,9 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) {
printer->Print(variables_,
if (context_->options().opensource_runtime) {
printer->Print(
variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
" */\n"
@ -612,6 +634,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"
@ -757,6 +780,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
} else {
if (context_->options().opensource_runtime) {
printer->Print(variables_,
"/**\n"
" * Use {@link #get$capitalized_name$Map()} instead.\n"
@ -768,6 +792,7 @@ void ImmutableMapFieldLiteGenerator::GenerateBuilderMembers(
" return get$capitalized_name$Map();\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
}
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
"@java.lang.Override\n"

@ -261,6 +261,9 @@ int ImmutableMessageGenerator::GenerateFieldAccessorTableInitializer(
void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder");
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n"
@ -320,6 +323,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
WriteMessageDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
// The builder_type stores the super type name of the nested Builder class.
std::string builder_type;
if (descriptor_->extension_range_count() > 0) {
@ -458,6 +465,7 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"private $oneof_capitalized_name$Case(int value) {\n"
" this.value = value;\n"
"}\n");
if (context_->options().opensource_runtime) {
printer->Print(
vars,
"/**\n"
@ -469,7 +477,10 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) {
"public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n");
}
printer->Print(
vars,
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
for (int j = 0; j < (oneof)->field_count(); j++) {
@ -982,6 +993,10 @@ void ImmutableMessageGenerator::GenerateEqualsAndHashCode(
printer->Print(
"@java.lang.Override\n"
"public boolean equals(");
if (!context_->options().opensource_runtime) {
printer->Print(
"@com.google.protobuf.Internal.ProtoMethodAcceptsNullParameter\n");
}
printer->Print("final java.lang.Object obj) {\n");
printer->Indent();
printer->Print(
@ -1440,8 +1455,15 @@ void ImmutableMessageGenerator::GenerateKotlinDsl(io::Printer* printer) const {
void ImmutableMessageGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n",
"camelcase_name",
name_resolver_->GetKotlinFactoryName(descriptor_));
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
"inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): "
"$message$ "
@ -1470,8 +1492,13 @@ void ImmutableMessageGenerator::GenerateKotlinMembers(
void ImmutableMessageGenerator::GenerateTopLevelKotlinMembers(
io::Printer* printer) const {
printer->Print("@kotlin.jvm.JvmSynthetic\n");
if (context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"@kotlin.jvm.JvmSynthetic\n"
"inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create(this.toBuilder()).apply { block() "
@ -1716,7 +1743,8 @@ void ImmutableMessageGenerator::GenerateAnyMethods(io::Printer* printer) {
"@java.lang.SuppressWarnings(\"unchecked\")\n"
"public <T extends com.google.protobuf.Message> T unpack(\n"
" java.lang.Class<T> clazz)\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n"
" throws com.google.protobuf.InvalidProtocolBufferException {\n");
printer->Print(
" boolean invalidClazz = false;\n"
" if (cachedUnpackValue != null) {\n"
" if (cachedUnpackValue.getClass() == clazz) {\n"

@ -168,6 +168,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
.GenerateBuilderMembers(printer);
}
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
@ -186,6 +187,7 @@ void MessageBuilderGenerator::Generate(io::Printer* printer) {
" return super.mergeUnknownFields(unknownFields);\n"
"}\n"
"\n");
}
printer->Print(
"\n"
@ -443,6 +445,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
"\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
if (context_->options().opensource_runtime) {
// Override methods declared in GeneratedMessage to return the concrete
// generated type so callsites won't depend on GeneratedMessage. This
// is needed to keep binary compatibility when we change generated code
@ -513,6 +516,7 @@ void MessageBuilderGenerator::GenerateCommonBuilderMethods(
"}\n",
"classname", name_resolver_->GetImmutableClassName(descriptor_));
}
}
// -----------------------------------------------------------------

@ -59,7 +59,8 @@ namespace {
void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -82,7 +83,9 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
(*variables)["on_changed"] = "onChanged();";
(*variables)["ver"] = GeneratedCodeVersionSuffix();
(*variables)["get_parser"] =
ExposePublicParser(descriptor->message_type()->file()) ? "PARSER"
ExposePublicParser(descriptor->message_type()->file()) &&
context->options().opensource_runtime
? "PARSER"
: "parser()";
if (HasHasbit(descriptor)) {
@ -133,10 +136,12 @@ void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
ImmutableMessageFieldGenerator::ImmutableMessageFieldGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableMessageFieldGenerator::~ImmutableMessageFieldGenerator() {}
@ -861,7 +866,7 @@ RepeatedImmutableMessageFieldGenerator::RepeatedImmutableMessageFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetMessageVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableMessageFieldGenerator::

@ -91,6 +91,7 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
void PrintNestedBuilderCondition(io::Printer* printer,
const char* regular_case,

@ -59,7 +59,8 @@ namespace {
void SetMessageVariables(const FieldDescriptor* descriptor, int messageBitIndex,
int builderBitIndex, const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["type"] =
@ -118,10 +119,11 @@ ImmutableMessageFieldLiteGenerator::ImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
name_resolver_(context->GetNameResolver()) {
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableMessageFieldLiteGenerator::~ImmutableMessageFieldLiteGenerator() {}
@ -496,10 +498,12 @@ RepeatedImmutableMessageFieldLiteGenerator::
RepeatedImmutableMessageFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetMessageVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableMessageFieldLiteGenerator::
@ -529,6 +533,13 @@ void RepeatedImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers(
void RepeatedImmutableMessageFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$)\n");
}
printer->Print(
variables_,
"private com.google.protobuf.Internal.ProtobufList<$type$> $name$_;\n");

@ -82,6 +82,7 @@ class ImmutableMessageFieldLiteGenerator : public ImmutableFieldLiteGenerator {
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
ClassNameResolver* name_resolver_;
Context* context_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableMessageFieldLiteGenerator);
@ -128,6 +129,7 @@ class RepeatedImmutableMessageFieldLiteGenerator
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableMessageFieldLiteGenerator);

@ -114,6 +114,10 @@ int ImmutableMessageLiteGenerator::GenerateStaticVariableInitializers(
void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) {
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true, "OrBuilder");
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
if (descriptor_->extension_range_count() > 0) {
printer->Print(
"$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n"
@ -236,10 +240,12 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
vars["oneof_capitalized_name"] =
context_->GetOneofGeneratorInfo(oneof)->capitalized_name;
vars["oneof_index"] = StrCat((oneof)->index());
if (context_->options().opensource_runtime) {
// oneofCase_ and oneof_
printer->Print(vars,
"private int $oneof_name$Case_ = 0;\n"
"private java.lang.Object $oneof_name$_;\n");
}
// OneofCase enum
printer->Print(vars, "public enum $oneof_capitalized_name$Case {\n");
printer->Indent();
@ -256,6 +262,7 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"private $oneof_capitalized_name$Case(int value) {\n"
" this.value = value;\n"
"}\n");
if (context_->options().opensource_runtime) {
printer->Print(
vars,
"/**\n"
@ -265,7 +272,10 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) {
"public static $oneof_capitalized_name$Case valueOf(int value) {\n"
" return forNumber(value);\n"
"}\n"
"\n"
"\n");
}
printer->Print(
vars,
"public static $oneof_capitalized_name$Case forNumber(int value) {\n"
" switch (value) {\n");
for (int j = 0; j < (oneof)->field_count(); j++) {
@ -782,8 +792,14 @@ void ImmutableMessageLiteGenerator::GenerateKotlinDsl(
void ImmutableMessageLiteGenerator::GenerateKotlinMembers(
io::Printer* printer) const {
printer->Print("@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n",
"camelcase_name",
name_resolver_->GetKotlinFactoryName(descriptor_));
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"@kotlin.jvm.JvmName(\"-initialize$camelcase_name$\")\n"
"inline fun $camelcase_name$(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): $message$ =\n"
" $message_kt$.Dsl._create($message$.newBuilder()).apply { block() "
@ -810,6 +826,9 @@ void ImmutableMessageLiteGenerator::GenerateKotlinMembers(
void ImmutableMessageLiteGenerator::GenerateTopLevelKotlinMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.errorprone.annotations.CheckReturnValue\n");
}
printer->Print(
"inline fun $message$.copy(block: $message_kt$.Dsl.() -> "
"kotlin.Unit): $message$ =\n"

@ -141,10 +141,6 @@ bool MessageHasConflictingClassName(const Descriptor* message,
} // namespace
ClassNameResolver::ClassNameResolver() {}
ClassNameResolver::~ClassNameResolver() {}
std::string ClassNameResolver::GetFileDefaultImmutableClassName(
const FileDescriptor* file) {
std::string basename;
@ -217,8 +213,12 @@ bool ClassNameResolver::HasConflictingClassName(const FileDescriptor* file,
}
std::string ClassNameResolver::GetDescriptorClassName(
const FileDescriptor* descriptor) {
return GetFileImmutableClassName(descriptor);
const FileDescriptor* file) {
if (options_.opensource_runtime) {
return GetFileImmutableClassName(file);
} else {
return GetFileImmutableClassName(file) + "InternalDescriptors";
}
}
std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor,
@ -228,7 +228,7 @@ std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor,
std::string ClassNameResolver::GetClassName(const FileDescriptor* descriptor,
bool immutable, bool kotlin) {
std::string result = FileJavaPackage(descriptor, immutable);
std::string result = FileJavaPackage(descriptor, immutable, options_);
if (!result.empty()) result += '.';
result += GetFileClassName(descriptor, immutable, kotlin);
return result;
@ -248,7 +248,7 @@ std::string ClassNameResolver::GetClassFullName(
bool immutable, bool is_own_file, bool kotlin) {
std::string result;
if (is_own_file) {
result = FileJavaPackage(file, immutable);
result = FileJavaPackage(file, immutable, options_);
} else {
result = GetClassName(file, immutable, kotlin);
}
@ -308,7 +308,7 @@ std::string ClassNameResolver::GetJavaClassFullName(
bool immutable, bool kotlin) {
std::string result;
if (MultipleJavaFiles(file, immutable)) {
result = FileJavaPackage(file, immutable);
result = FileJavaPackage(file, immutable, options_);
if (!result.empty()) result += '.';
} else {
result = GetClassName(file, immutable, kotlin);
@ -372,7 +372,7 @@ std::string ClassNameResolver::GetDowngradedFileClassName(
std::string ClassNameResolver::GetDowngradedClassName(
const Descriptor* descriptor) {
return FileJavaPackage(descriptor->file()) + "." +
return FileJavaPackage(descriptor->file(), true, options_) + "." +
GetDowngradedFileClassName(descriptor->file()) + "." +
ClassNameWithoutPackage(descriptor, false);
}

@ -34,7 +34,9 @@
#include <map>
#include <string>
#include <google/protobuf/stubs/logging.h>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/compiler/java/options.h>
// Must be last.
#include <google/protobuf/port_def.inc>
@ -58,8 +60,11 @@ enum NameEquality { NO_MATCH, EXACT_EQUAL, EQUAL_IGNORE_CASE };
// Thread-safety note: This class is *not* thread-safe.
class ClassNameResolver {
public:
ClassNameResolver();
~ClassNameResolver();
explicit ClassNameResolver(const Options& options = {}) : options_(options) {}
~ClassNameResolver() = default;
ClassNameResolver(const ClassNameResolver&) = delete;
ClassNameResolver& operator=(const ClassNameResolver&) = delete;
// Gets the unqualified outer class name for the file.
std::string GetFileClassName(const FileDescriptor* file, bool immutable);
@ -135,6 +140,8 @@ class ClassNameResolver {
const FileDescriptor* file, bool immutable,
bool is_own_file, bool kotlin);
Options options_;
private:
// Get the Java Class style full name of a message.
std::string GetJavaClassFullName(const std::string& name_without_package,
@ -145,8 +152,6 @@ class ClassNameResolver {
// Caches the result to provide better performance.
std::map<const FileDescriptor*, std::string>
file_immutable_outer_class_names_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ClassNameResolver);
};
} // namespace java

@ -40,6 +40,8 @@
#include <string>
#include <google/protobuf/compiler/java/options.h>
namespace google {
namespace protobuf {
@ -85,7 +87,8 @@ std::string ClassName(const ServiceDescriptor* descriptor);
//
// Returns:
// Java package name.
std::string FileJavaPackage(const FileDescriptor* descriptor);
std::string FileJavaPackage(const FileDescriptor* descriptor,
Options options = {});
// Requires:
// descriptor != NULL

@ -33,6 +33,8 @@
#include <string>
#include <google/protobuf/port_def.inc>
namespace google {
namespace protobuf {
namespace compiler {
@ -54,6 +56,7 @@ struct Options {
// When set, the protoc will generate the current files and all the transitive
// dependencies as lite runtime.
bool enforce_lite;
bool opensource_runtime = PROTO2_IS_OSS;
// If true, we should build .meta files and emit @Generated annotations into
// generated code.
bool annotate_code;
@ -70,4 +73,5 @@ struct Options {
} // namespace protobuf
} // namespace google
#include <google/protobuf/port_undef.inc>
#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_OPTIONS_H__

@ -61,7 +61,8 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor);
@ -106,13 +107,15 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
(*variables)["repeated_set"] = (*variables)["name"] + "_.set";
}
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_init"] =
IsDefaultValueJavaDefault(descriptor)
? ""
: ("= " + ImmutableDefaultValue(descriptor, name_resolver));
(*variables)["capitalized_type"] =
GetCapitalizedType(descriptor, /* immutable = */ true);
: ("= " + ImmutableDefaultValue(descriptor, name_resolver,
context->options()));
(*variables)["capitalized_type"] = GetCapitalizedType(
descriptor, /* immutable = */ true, context->options());
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
@ -209,7 +212,7 @@ ImmutablePrimitiveFieldGenerator::ImmutablePrimitiveFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutablePrimitiveFieldGenerator::~ImmutablePrimitiveFieldGenerator() {}
@ -681,7 +684,7 @@ RepeatedImmutablePrimitiveFieldGenerator::
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutablePrimitiveFieldGenerator::

@ -69,16 +69,18 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
JavaType javaType = GetJavaType(descriptor);
(*variables)["type"] = PrimitiveTypeName(javaType);
(*variables)["boxed_type"] = BoxedPrimitiveTypeName(javaType);
(*variables)["kt_type"] = KotlinTypeName(javaType);
(*variables)["field_type"] = (*variables)["type"];
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["capitalized_type"] =
GetCapitalizedType(descriptor, /* immutable = */ true);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = GetCapitalizedType(
descriptor, /* immutable = */ true, context->options());
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
(*variables)["tag_size"] = StrCat(
@ -199,10 +201,11 @@ ImmutablePrimitiveFieldLiteGenerator::ImmutablePrimitiveFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
context_(context),
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutablePrimitiveFieldLiteGenerator::~ImmutablePrimitiveFieldLiteGenerator() {}
@ -231,6 +234,20 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
variables_,
"private static final $field_type$ $bytes_default$ = $default$;\n");
}
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
" isRequired=$required$)\n");
if (HasHazzer(descriptor_)) {
printer->Print(variables_,
"@com.google.protobuf.ProtoPresenceCheckedField(\n"
" presenceBitsId=$bit_field_id$,\n"
" mask=$bit_field_mask$)\n");
}
}
printer->Print(variables_, "private $field_type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (HasHazzer(descriptor_)) {
@ -493,7 +510,7 @@ RepeatedImmutablePrimitiveFieldLiteGenerator::
name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutablePrimitiveFieldLiteGenerator::

@ -81,6 +81,7 @@ class ImmutablePrimitiveFieldLiteGenerator
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
Context* context_;
ClassNameResolver* name_resolver_;
private:

@ -68,6 +68,10 @@ void ImmutableServiceGenerator::Generate(io::Printer* printer) {
WriteServiceDocComment(printer, descriptor_);
MaybePrintGeneratedAnnotation(context_, printer, descriptor_,
/* immutable = */ true);
if (!context_->options().opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"public $static$ abstract class $classname$\n"
" implements com.google.protobuf.Service {\n",

@ -51,14 +51,16 @@ namespace java {
SharedCodeGenerator::SharedCodeGenerator(const FileDescriptor* file,
const Options& options)
: name_resolver_(new ClassNameResolver), file_(file), options_(options) {}
: name_resolver_(new ClassNameResolver(options)),
file_(file),
options_(options) {}
SharedCodeGenerator::~SharedCodeGenerator() {}
void SharedCodeGenerator::Generate(
GeneratorContext* context, std::vector<std::string>* file_list,
std::vector<std::string>* annotation_file_list) {
std::string java_package = FileJavaPackage(file_);
std::string java_package = FileJavaPackage(file_, true, options_);
std::string package_dir = JavaPackageToDir(java_package);
if (HasDescriptorMethods(file_, options_.enforce_lite)) {
@ -87,7 +89,12 @@ void SharedCodeGenerator::Generate(
"package", java_package);
}
PrintGeneratedAnnotation(printer.get(), '$',
options_.annotate_code ? info_relative_path : "");
options_.annotate_code ? info_relative_path : "",
options_);
if (!options_.opensource_runtime) {
printer->Print("@com.google.protobuf.Internal.ProtoNonnullApi\n");
}
printer->Print(
"public final class $classname$ {\n"
" public static com.google.protobuf.Descriptors.FileDescriptor\n"
@ -163,7 +170,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
std::vector<std::pair<std::string, std::string> > dependencies;
for (int i = 0; i < file_->dependency_count(); i++) {
std::string filename = file_->dependency(i)->name();
std::string package = FileJavaPackage(file_->dependency(i));
std::string package = FileJavaPackage(file_->dependency(i), true, options_);
std::string classname =
name_resolver_->GetDescriptorClassName(file_->dependency(i));
std::string full_name;
@ -180,6 +187,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
printer->Print(
"descriptor = com.google.protobuf.Descriptors.FileDescriptor\n"
" .internalBuildGeneratedFileFrom(descriptorData,\n");
if (options_.opensource_runtime) {
printer->Print(
" new com.google.protobuf.Descriptors.FileDescriptor[] {\n");
@ -188,6 +196,7 @@ void SharedCodeGenerator::GenerateDescriptors(io::Printer* printer) {
printer->Print(" $dependency$.getDescriptor(),\n", "dependency",
dependency);
}
}
printer->Print(" });\n");
}

@ -63,14 +63,17 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] = "com.google.protobuf.LazyStringArrayList.EMPTY";
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_init"] =
"= " + ImmutableDefaultValue(descriptor, name_resolver);
"= " +
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = "String";
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
@ -151,7 +154,7 @@ ImmutableStringFieldGenerator::ImmutableStringFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableStringFieldGenerator::~ImmutableStringFieldGenerator() {}
@ -753,7 +756,7 @@ RepeatedImmutableStringFieldGenerator::RepeatedImmutableStringFieldGenerator(
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
SetPrimitiveVariables(descriptor, messageBitIndex, builderBitIndex,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableStringFieldGenerator::

@ -63,15 +63,18 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
int messageBitIndex, int builderBitIndex,
const FieldGeneratorInfo* info,
ClassNameResolver* name_resolver,
std::map<std::string, std::string>* variables) {
std::map<std::string, std::string>* variables,
Context* context) {
SetCommonFieldVariables(descriptor, info, variables);
(*variables)["empty_list"] =
"com.google.protobuf.GeneratedMessageLite.emptyProtobufList()";
(*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver);
(*variables)["default"] =
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["default_init"] =
"= " + ImmutableDefaultValue(descriptor, name_resolver);
"= " +
ImmutableDefaultValue(descriptor, name_resolver, context->options());
(*variables)["capitalized_type"] = "java.lang.String";
(*variables)["tag"] =
StrCat(static_cast<int32_t>(WireFormat::MakeTag(descriptor)));
@ -92,8 +95,17 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor,
" is deprecated\") "
: "";
(*variables)["required"] = descriptor->is_required() ? "true" : "false";
if (!context->options().opensource_runtime) {
(*variables)["enforce_utf8"] = CheckUtf8(descriptor) ? "true" : "false";
}
if (HasHasbit(descriptor)) {
if (!context->options().opensource_runtime) {
(*variables)["bit_field_id"] = StrCat(messageBitIndex / 32);
(*variables)["bit_field_name"] = GetBitFieldNameForBit(messageBitIndex);
(*variables)["bit_field_mask"] =
StrCat(1 << (messageBitIndex % 32));
}
// For singular messages and builders, one bit is used for the hasField bit.
(*variables)["get_has_field_bit_message"] = GenerateGetBit(messageBitIndex);
@ -126,10 +138,11 @@ ImmutableStringFieldLiteGenerator::ImmutableStringFieldLiteGenerator(
const FieldDescriptor* descriptor, int messageBitIndex, Context* context)
: descriptor_(descriptor),
messageBitIndex_(messageBitIndex),
name_resolver_(context->GetNameResolver()) {
name_resolver_(context->GetNameResolver()),
context_(context) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
ImmutableStringFieldLiteGenerator::~ImmutableStringFieldLiteGenerator() {}
@ -181,6 +194,21 @@ void ImmutableStringFieldLiteGenerator::GenerateInterfaceMembers(
void ImmutableStringFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
" isRequired=$required$,\n"
" isEnforceUtf8=$enforce_utf8$)\n");
if (HasHazzer(descriptor_)) {
printer->Print(variables_,
"@com.google.protobuf.ProtoPresenceCheckedField(\n"
" presenceBitsId=$bit_field_id$,\n"
" mask=$bit_field_mask$)\n");
}
}
printer->Print(variables_, "private java.lang.String $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
@ -520,10 +548,12 @@ RepeatedImmutableStringFieldLiteGenerator::
RepeatedImmutableStringFieldLiteGenerator(const FieldDescriptor* descriptor,
int messageBitIndex,
Context* context)
: descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
: descriptor_(descriptor),
name_resolver_(context->GetNameResolver()),
context_(context) {
SetPrimitiveVariables(descriptor, messageBitIndex, 0,
context->GetFieldGeneratorInfo(descriptor),
name_resolver_, &variables_);
name_resolver_, &variables_, context);
}
RepeatedImmutableStringFieldLiteGenerator::
@ -554,6 +584,14 @@ void RepeatedImmutableStringFieldLiteGenerator::GenerateInterfaceMembers(
void RepeatedImmutableStringFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
if (!context_->options().opensource_runtime) {
printer->Print(
variables_,
"@com.google.protobuf.ProtoField(\n"
" fieldNumber=$number$,\n"
" type=com.google.protobuf.FieldType.$annotation_field_type$,\n"
" isEnforceUtf8=$enforce_utf8$)\n");
}
printer->Print(
variables_,
"private com.google.protobuf.Internal.ProtobufList<java.lang.String> "

@ -83,6 +83,7 @@ class ImmutableStringFieldLiteGenerator : public ImmutableFieldLiteGenerator {
std::map<std::string, std::string> variables_;
const int messageBitIndex_;
ClassNameResolver* name_resolver_;
Context* context_;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableStringFieldLiteGenerator);
@ -127,6 +128,7 @@ class RepeatedImmutableStringFieldLiteGenerator
const FieldDescriptor* descriptor_;
std::map<std::string, std::string> variables_;
ClassNameResolver* name_resolver_;
Context* context_;
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedImmutableStringFieldLiteGenerator);
};

@ -993,6 +993,8 @@
#define PROTOBUF_DLOG(x) \
for (bool b = PROTOBUF_DEBUG; b; b = false) GOOGLE_LOG(x)
#define PROTO2_IS_OSS true
// We don't want code outside port_def doing complex testing, so
// remove our portable condition test macros to nudge folks away from
// using it themselves.

@ -111,6 +111,7 @@
#undef PROTOBUF_GUARDED_BY
#undef PROTOBUF_DEBUG
#undef PROTOBUF_DLOG
#undef PROTO2_IS_OSS
#ifdef PROTOBUF_FUTURE_BREAKING_CHANGES
#undef PROTOBUF_FUTURE_BREAKING_CHANGES

@ -121,7 +121,6 @@ std::string ProtocVersionString(int version) {
buffer[sizeof(buffer) - 1] = '\0';
return buffer;
}
} // namespace internal

@ -106,10 +106,12 @@ void PROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
const char* filename);
// Converts a numeric version number to a string.
std::string PROTOBUF_EXPORT VersionString(int version);
std::string PROTOBUF_EXPORT
VersionString(int version); // NOLINT(runtime/string)
// Prints the protoc compiler version (no major version)
std::string PROTOBUF_EXPORT ProtocVersionString(int version);
std::string PROTOBUF_EXPORT
ProtocVersionString(int version); // NOLINT(runtime/string)
} // namespace internal

@ -101,7 +101,11 @@ class PROTOBUF_EXPORT WireFormatLite {
// identifies the encoding of this data, it is possible to skip
// unrecognized fields for forwards compatibility.
enum WireType {
enum WireType
#ifndef SWIG
: int
#endif // !SWIG
{
WIRETYPE_VARINT = 0,
WIRETYPE_FIXED64 = 1,
WIRETYPE_LENGTH_DELIMITED = 2,

Loading…
Cancel
Save