mirror of
https://github.com/protocolbuffers/protobuf
synced 2026-08-26 02:23:14 -04:00
Annotate extension names in hpb generator for Kythe metadata.
PiperOrigin-RevId: 957381097
This commit is contained in:
parent
c5cbcf787f
commit
a5412936c7
2 changed files with 33 additions and 1 deletions
|
|
@ -22,6 +22,8 @@ namespace google {
|
|||
namespace protobuf {
|
||||
namespace hpb_generator {
|
||||
|
||||
using Sub = google::protobuf::io::Printer::Sub;
|
||||
|
||||
std::string ExtensionIdentifierBase(const google::protobuf::FieldDescriptor* ext) {
|
||||
assert(ext->is_extension());
|
||||
std::string ext_scope;
|
||||
|
|
@ -55,7 +57,8 @@ void WriteExtensionIdentifierHeader(const google::protobuf::FieldDescriptor* ext
|
|||
{"linkage", linkage},
|
||||
{"mini_table_name",
|
||||
absl::StrCat(ExtensionIdentifierBase(ext), "_", ext->name(), "_ext")},
|
||||
{"extension_name", ResolveKeywordConflict(ext->name())},
|
||||
Sub("extension_name", ResolveKeywordConflict(ext->name()))
|
||||
.AnnotatedAs(ext),
|
||||
{"extension_number", ext->number()}},
|
||||
R"cc(
|
||||
inline $linkage$ constexpr ::hpb::internal::ExtensionIdentifier<
|
||||
|
|
|
|||
|
|
@ -166,6 +166,35 @@ TEST_F(HpbMetadataTest, AnnotatesStringSemantics) {
|
|||
});
|
||||
}
|
||||
|
||||
constexpr absl::string_view kExtensionTestFile = R"schema(
|
||||
syntax = "proto2";
|
||||
package foo;
|
||||
message Message {
|
||||
extensions 100 to 199;
|
||||
}
|
||||
extend Message {
|
||||
optional string ext_field = 101;
|
||||
}
|
||||
)schema";
|
||||
|
||||
TEST_F(HpbMetadataTest, AnnotatesExtensionSemantics) {
|
||||
FileDescriptorProto file;
|
||||
GeneratedCodeInfo info;
|
||||
std::string hpb_h;
|
||||
atu::AddFile("test.proto", kExtensionTestFile);
|
||||
EXPECT_TRUE(CaptureMetadata("test.proto", file, hpb_h, info));
|
||||
|
||||
// Check annotations for `ext_field`.
|
||||
std::vector<int> field_path{
|
||||
FileDescriptorProto::kExtensionFieldNumber,
|
||||
0,
|
||||
};
|
||||
ExpectAnnotationsForPathContain(info, "test.proto", hpb_h, field_path,
|
||||
{
|
||||
{"ext_field", Annotation::NONE},
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(HpbMetadataTest, GeneratesMetadataPragma) {
|
||||
FileDescriptorProto file;
|
||||
GeneratedCodeInfo info;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue