Add semantic annotations for proto field accessors in java

PiperOrigin-RevId: 532148589
pull/12800/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent 9dd2e26dbb
commit 191f4be064
  1. 25
      src/google/protobuf/compiler/java/enum_field.cc
  2. 17
      src/google/protobuf/compiler/java/map_field.cc
  3. 56
      src/google/protobuf/compiler/java/message_field.cc
  4. 23
      src/google/protobuf/compiler/java/message_field.h
  5. 17
      src/google/protobuf/compiler/java/primitive_field.cc
  6. 23
      src/google/protobuf/compiler/java/string_field.cc
  7. 14
      src/google/protobuf/io/printer.h

@ -57,6 +57,7 @@ namespace compiler {
namespace java {
namespace {
using Semantic = ::google::protobuf::io::AnnotationCollector::Semantic;
void SetEnumVariables(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
@ -237,7 +238,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
@ -260,7 +261,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
@ -271,7 +272,7 @@ void ImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
void ImmutableEnumFieldGenerator::GenerateKotlinDslMembers(
@ -495,7 +496,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
@ -523,7 +524,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
@ -537,7 +538,7 @@ void ImmutableEnumOneofFieldGenerator::GenerateBuilderMembers(
" }\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
void ImmutableEnumOneofFieldGenerator::GenerateBuilderClearCode(
@ -804,7 +805,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ true);
printer->Print(variables_,
@ -818,7 +819,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ true);
printer->Print(variables_,
@ -831,7 +832,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
@ -842,7 +843,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (SupportUnknownEnumValue(descriptor_)) {
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_GETTER);
@ -872,7 +873,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldEnumValueAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ true);
printer->Print(variables_,
@ -883,7 +884,7 @@ void RepeatedImmutableEnumFieldGenerator::GenerateBuilderMembers(
" onChanged();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldEnumValueAccessorDocComment(printer, descriptor_,
LIST_MULTI_ADDER, /* builder */ true);
printer->Print(

@ -46,6 +46,7 @@ namespace compiler {
namespace java {
namespace {
using Semantic = ::google::protobuf::io::AnnotationCollector::Semantic;
std::string TypeName(const FieldDescriptor* field,
ClassNameResolver* name_resolver, bool boxed) {
@ -409,7 +410,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" .clear();\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@ -420,7 +421,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" .remove(key);\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
const FieldDescriptor* value = MapValueField(descriptor_);
if (GetJavaType(value) == JAVATYPE_ENUM) {
@ -452,7 +453,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
@ -465,7 +466,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (SupportUnknownEnumValue(value)) {
if (context_->options().opensource_runtime) {
@ -496,7 +497,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
@ -508,7 +509,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
} else {
if (context_->options().opensource_runtime) {
@ -538,7 +539,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
@ -550,7 +551,7 @@ void ImmutableMapFieldGenerator::GenerateBuilderMembers(
" $set_has_field_bit_builder$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
}

@ -56,6 +56,7 @@ namespace java {
namespace {
using Semantic = ::google::protobuf::io::AnnotationCollector::Semantic;
void SetMessageVariables(
const FieldDescriptor* descriptor, int messageBitIndex, int builderBitIndex,
@ -230,9 +231,10 @@ void ImmutableMessageFieldGenerator::PrintNestedBuilderCondition(
void ImmutableMessageFieldGenerator::PrintNestedBuilderFunction(
io::Printer* printer, const char* method_prototype,
const char* regular_case, const char* nested_builder_case,
const char* trailing_code) const {
const char* trailing_code,
absl::optional<io::AnnotationCollector::Semantic> semantic) const {
printer->Print(variables_, method_prototype);
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, semantic);
printer->Print(" {\n");
printer->Indent();
PrintNestedBuilderCondition(printer, regular_case, nested_builder_case);
@ -290,7 +292,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$set_has_field_bit_builder$\n"
"$on_changed$\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
@ -305,7 +308,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$set_has_field_bit_builder$\n"
"$on_changed$\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Message.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
@ -324,7 +328,8 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$set_has_field_bit_builder$\n"
"$on_changed$\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Message.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
@ -340,7 +345,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
// Field.Builder getFieldBuilder()
WriteFieldDocComment(printer, descriptor_);
@ -625,7 +630,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.setMessage(value);\n",
"$set_oneof_case_message$;\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
@ -640,7 +646,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.setMessage(builderForValue.build());\n",
"$set_oneof_case_message$;\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Field.Builder mergeField(Field value)
WriteFieldDocComment(printer, descriptor_);
@ -664,7 +671,8 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
"}\n",
"$set_oneof_case_message$;\n"
"return this;\n");
"return this;\n",
Semantic::kSet);
// Field.Builder clearField()
WriteFieldDocComment(printer, descriptor_);
@ -683,7 +691,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
"}\n"
"$name$Builder_.clear();\n",
"return this;\n");
"return this;\n", Semantic::kSet);
WriteFieldDocComment(printer, descriptor_);
printer->Print(variables_,
@ -913,9 +921,10 @@ void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderCondition(
void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderFunction(
io::Printer* printer, const char* method_prototype,
const char* regular_case, const char* nested_builder_case,
const char* trailing_code) const {
const char* trailing_code,
absl::optional<io::AnnotationCollector::Semantic> semantic) const {
printer->Print(variables_, method_prototype);
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, semantic);
printer->Print(" {\n");
printer->Indent();
PrintNestedBuilderCondition(printer, regular_case, nested_builder_case);
@ -1011,7 +1020,8 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"ensure$capitalized_name$IsMutable();\n"
"$name$_.set(index, value);\n"
"$on_changed$\n",
"$name$Builder_.setMessage(index, value);\n", "return this;\n");
"$name$Builder_.setMessage(index, value);\n", "return this;\n",
Semantic::kSet);
// Builder setRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
@ -1026,7 +1036,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.setMessage(index, builderForValue.build());\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder addRepeatedField(Field value)
WriteFieldDocComment(printer, descriptor_);
@ -1044,7 +1054,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.addMessage(value);\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder addRepeatedField(int index, Field value)
WriteFieldDocComment(printer, descriptor_);
@ -1062,7 +1072,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.addMessage(index, value);\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder addRepeatedField(Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
@ -1077,7 +1087,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.addMessage(builderForValue.build());\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder addRepeatedField(int index, Field.Builder builderForValue)
WriteFieldDocComment(printer, descriptor_);
@ -1092,7 +1102,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.addMessage(index, builderForValue.build());\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder addAllRepeatedField(Iterable<Field> values)
WriteFieldDocComment(printer, descriptor_);
@ -1108,7 +1118,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.addAllMessages(values);\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder clearRepeatedField()
WriteFieldDocComment(printer, descriptor_);
@ -1121,7 +1131,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.clear();\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Builder removeRepeatedField(int index)
WriteFieldDocComment(printer, descriptor_);
@ -1135,7 +1145,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
"$name$Builder_.remove(index);\n",
"return this;\n");
"return this;\n", Semantic::kSet);
// Field.Builder getRepeatedFieldBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
@ -1183,7 +1193,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
" return get$capitalized_name$FieldBuilder().addBuilder(\n"
" $type$.getDefaultInstance());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
// Field.Builder addRepeatedFieldBuilder(int index)
WriteFieldDocComment(printer, descriptor_);
@ -1194,7 +1204,7 @@ void RepeatedImmutableMessageFieldGenerator::GenerateBuilderMembers(
" return get$capitalized_name$FieldBuilder().addBuilder(\n"
" index, $type$.getDefaultInstance());\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
// List<Field.Builder> getRepeatedFieldBuilderList()
WriteFieldDocComment(printer, descriptor_);

@ -38,6 +38,7 @@
#include <string>
#include "google/protobuf/compiler/java/field.h"
#include "google/protobuf/io/printer.h"
namespace google {
namespace protobuf {
@ -102,11 +103,12 @@ class ImmutableMessageFieldGenerator : public ImmutableFieldGenerator {
virtual void PrintNestedBuilderCondition(
io::Printer* printer, const char* regular_case,
const char* nested_builder_case) const;
virtual void PrintNestedBuilderFunction(io::Printer* printer,
const char* method_prototype,
const char* regular_case,
const char* nested_builder_case,
const char* trailing_code) const;
virtual void PrintNestedBuilderFunction(
io::Printer* printer, const char* method_prototype,
const char* regular_case, const char* nested_builder_case,
const char* trailing_code,
absl::optional<io::AnnotationCollector::Semantic> semantic =
absl::nullopt) const;
private:
void GenerateKotlinOrNull(io::Printer* printer) const;
@ -171,11 +173,12 @@ class RepeatedImmutableMessageFieldGenerator
void PrintNestedBuilderCondition(
io::Printer* printer, const char* regular_case,
const char* nested_builder_case) const override;
void PrintNestedBuilderFunction(io::Printer* printer,
const char* method_prototype,
const char* regular_case,
const char* nested_builder_case,
const char* trailing_code) const override;
void PrintNestedBuilderFunction(
io::Printer* printer, const char* method_prototype,
const char* regular_case, const char* nested_builder_case,
const char* trailing_code,
absl::optional<io::AnnotationCollector::Semantic> semantic =
absl::nullopt) const override;
};
} // namespace java

@ -53,6 +53,7 @@ namespace compiler {
namespace java {
using internal::WireFormat;
using Semantic = ::google::protobuf::io::AnnotationCollector::Semantic;
namespace {
@ -290,7 +291,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
@ -298,7 +299,7 @@ void ImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
variables_,
"$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n"
" $clear_has_field_bit_builder$\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
JavaType type = GetJavaType(descriptor_);
if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) {
// The default value is not a simple literal so we want to avoid executing
@ -581,7 +582,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
@ -595,7 +596,7 @@ void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderMembers(
" }\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
void ImmutablePrimitiveOneofFieldGenerator::GenerateBuilderClearCode(
@ -804,7 +805,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $repeated_set$(index, value);\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (descriptor_->type() != FieldDescriptor::TYPE_BYTES) {
printer->Print(variables_, " $set_has_field_bit_builder$\n");
}
@ -820,7 +821,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" $null_check$\n"
" ensure$capitalized_name$IsMutable();\n"
" $repeated_add$(value);\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (descriptor_->type() != FieldDescriptor::TYPE_BYTES) {
printer->Print(variables_, " $set_has_field_bit_builder$\n");
}
@ -836,7 +837,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" ensure$capitalized_name$IsMutable();\n"
" com.google.protobuf.AbstractMessageLite.Builder.addAll(\n"
" values, $name$_);\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (descriptor_->type() != FieldDescriptor::TYPE_BYTES) {
printer->Print(variables_, " $set_has_field_bit_builder$\n");
}
@ -854,7 +855,7 @@ void RepeatedImmutablePrimitiveFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
}
void RepeatedImmutablePrimitiveFieldGenerator::GenerateKotlinDslMembers(

@ -55,6 +55,7 @@ namespace java {
using internal::WireFormat;
using internal::WireFormatLite;
using Semantic = ::google::protobuf::io::AnnotationCollector::Semantic;
namespace {
@ -340,13 +341,13 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
variables_,
"$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
// The default value is not a simple literal so we want to avoid executing
// it multiple times. Instead, get the default out of the default instance.
printer->Print(variables_,
@ -364,7 +365,7 @@ void ImmutableStringFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" $null_check$\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
}
@ -655,7 +656,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
@ -668,7 +669,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
" }\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldStringBytesAccessorDocComment(printer, descriptor_, SETTER,
/* builder */ true);
@ -677,7 +678,7 @@ void ImmutableStringOneofFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" $null_check$\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
}
@ -894,7 +895,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ true);
printer->Print(variables_,
@ -907,7 +908,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, LIST_MULTI_ADDER,
/* builder */ true);
printer->Print(variables_,
@ -920,7 +921,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER,
/* builder */ true);
printer->Print(
@ -932,7 +933,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
" $on_changed$\n"
" return this;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
WriteFieldStringBytesAccessorDocComment(printer, descriptor_, LIST_ADDER,
/* builder */ true);
@ -941,7 +942,7 @@ void RepeatedImmutableStringFieldGenerator::GenerateBuilderMembers(
"$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n"
" com.google.protobuf.ByteString value) {\n"
" $null_check$\n");
printer->Annotate("{", "}", descriptor_);
printer->Annotate("{", "}", descriptor_, Semantic::kSet);
if (CheckUtf8(descriptor_)) {
printer->Print(variables_, " checkByteStringIsUtf8(value);\n");
}

@ -646,21 +646,25 @@ class PROTOBUF_EXPORT Printer {
// Link a substitution variable emitted by the last call to Print to the file
// with path file_name.
void Annotate(absl::string_view varname, absl::string_view file_name) {
Annotate(varname, varname, file_name);
void Annotate(
absl::string_view varname, absl::string_view file_name,
absl::optional<AnnotationCollector::Semantic> semantic = absl::nullopt) {
Annotate(varname, varname, file_name, semantic);
}
// Link the output range defined by the substitution variables as emitted by
// the last call to Print to the file with path file_name. The range begins
// at begin_varname's value and ends after the last character of the value
// substituted for end_varname.
void Annotate(absl::string_view begin_varname, absl::string_view end_varname,
absl::string_view file_name) {
void Annotate(
absl::string_view begin_varname, absl::string_view end_varname,
absl::string_view file_name,
absl::optional<AnnotationCollector::Semantic> semantic = absl::nullopt) {
if (options_.annotation_collector == nullptr) {
return;
}
Annotate(begin_varname, end_varname, file_name, {}, absl::nullopt);
Annotate(begin_varname, end_varname, file_name, {}, semantic);
}
// Indent text by `options.spaces_per_indent`; undone by Outdent().

Loading…
Cancel
Save