|
18 | 18 | #include "google/protobuf/compiler/csharp/csharp_doc_comment.h" |
19 | 19 | #include "google/protobuf/compiler/csharp/csharp_enum.h" |
20 | 20 | #include "google/protobuf/compiler/csharp/csharp_field_base.h" |
| 21 | +#include "google/protobuf/compiler/csharp/csharp_generator.h" |
21 | 22 | #include "google/protobuf/compiler/csharp/csharp_helpers.h" |
22 | 23 | #include "google/protobuf/compiler/csharp/csharp_options.h" |
23 | 24 | #include "google/protobuf/compiler/csharp/names.h" |
@@ -60,6 +61,9 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, |
60 | 61 | } |
61 | 62 | } |
62 | 63 | has_bit_field_count_ = (presence_bit_count + 31) / 32; |
| 64 | + nrt_enabled_ = Generator::GetResolvedSourceFeatures(*descriptor->file()) |
| 65 | + .GetExtension(pb::csharp) |
| 66 | + .nullable_reference_types(); |
63 | 67 | } |
64 | 68 |
|
65 | 69 | MessageGenerator::~MessageGenerator() = default; |
@@ -93,6 +97,7 @@ void MessageGenerator::Generate(io::Printer* printer) { |
93 | 97 | absl::flat_hash_map<absl::string_view, std::string> vars; |
94 | 98 | vars["class_name"] = class_name(); |
95 | 99 | vars["access_level"] = class_access_level(); |
| 100 | + vars["nrt_annotation"] = nrt_enabled_ ? "?" : ""; |
96 | 101 |
|
97 | 102 | WriteMessageDocComment(printer, options(), descriptor_); |
98 | 103 | AddDeprecatedFlag(printer); |
@@ -120,7 +125,8 @@ void MessageGenerator::Generate(io::Printer* printer) { |
120 | 125 | "private static readonly pb::MessageParser<$class_name$> _parser = new " |
121 | 126 | "pb::MessageParser<$class_name$>(() => new $class_name$());\n"); |
122 | 127 |
|
123 | | - printer->Print("private pb::UnknownFieldSet _unknownFields;\n"); |
| 128 | + printer->Print( |
| 129 | + vars, "private pb::UnknownFieldSet$nrt_annotation$ _unknownFields;\n"); |
124 | 130 |
|
125 | 131 | if (has_extension_ranges_) { |
126 | 132 | if (IsDescriptorProto(descriptor_->file())) { |
@@ -256,7 +262,7 @@ void MessageGenerator::Generate(io::Printer* printer) { |
256 | 262 | "TValue> extension) {\n" |
257 | 263 | " return pb::ExtensionSet.Get(ref _extensions, extension);\n" |
258 | 264 | "}\n" |
259 | | - "public pbc::RepeatedField<TValue> " |
| 265 | + "public pbc::RepeatedField<TValue>$nrt_annotation$ " |
260 | 266 | "GetExtension<TValue>(pb::RepeatedExtension<$class_name$, TValue> " |
261 | 267 | "extension) {\n" |
262 | 268 | " return pb::ExtensionSet.Get(ref _extensions, extension);\n" |
@@ -314,6 +320,7 @@ void MessageGenerator::Generate(io::Printer* printer) { |
314 | 320 | "\n"); |
315 | 321 | } |
316 | 322 |
|
| 323 | + // FIXME |
317 | 324 | if (descriptor_->extension_count() > 0) { |
318 | 325 | printer->Print(vars, |
319 | 326 | "#region Extensions\n" |
@@ -417,16 +424,17 @@ void MessageGenerator::GenerateFreezingCode(io::Printer* printer) {} |
417 | 424 | void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { |
418 | 425 | absl::flat_hash_map<absl::string_view, std::string> vars; |
419 | 426 | vars["class_name"] = class_name(); |
| 427 | + vars["nrt_annotation"] = nrt_enabled_ ? "?" : ""; |
420 | 428 |
|
421 | 429 | // Equality |
422 | 430 | WriteGeneratedCodeAttributes(printer); |
423 | 431 | printer->Print(vars, |
424 | | - "public override bool Equals(object other) {\n" |
| 432 | + "public override bool Equals(object$nrt_annotation$ other) {\n" |
425 | 433 | " return Equals(other as $class_name$);\n" |
426 | 434 | "}\n\n"); |
427 | 435 | WriteGeneratedCodeAttributes(printer); |
428 | 436 | printer->Print(vars, |
429 | | - "public bool Equals($class_name$ other) {\n" |
| 437 | + "public bool Equals($class_name$$nrt_annotation$ other) {\n" |
430 | 438 | " if (ReferenceEquals(other, null)) {\n" |
431 | 439 | " return false;\n" |
432 | 440 | " }\n" |
|
0 commit comments