diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc index f06d79d8d5..e0a6c83a33 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -50,7 +50,7 @@ namespace csharp { std::string GetOutputFile(const google::protobuf::FileDescriptor* file, const std::string file_extension) { - return GetFileUmbrellaClassname(file) + file_extension; + return GetUmbrellaClassUnqualifiedName(file) + file_extension; } void GenerateFile(const google::protobuf::FileDescriptor* file, diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc index 1c7a24a9a9..07305a93fa 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc @@ -117,21 +117,18 @@ std::string GetFileNamespace(const FileDescriptor* descriptor) { return UnderscoresToCamelCase(descriptor->package(), true, true); } -std::string GetUmbrellaClassNameInternal(const std::string& proto_file) { +std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor) { + // umbrella_classname can no longer be set using message option. + std::string proto_file = descriptor->name(); int lastslash = proto_file.find_last_of("/"); std::string base = proto_file.substr(lastslash + 1); return UnderscoresToPascalCase(StripDotProto(base)); } -std::string GetFileUmbrellaClassname(const FileDescriptor* descriptor) { - // umbrella_classname can no longer be set using message option. - return GetUmbrellaClassNameInternal(descriptor->name()); -} - -std::string GetFileUmbrellaNamespace(const FileDescriptor* descriptor) { +std::string GetUmbrellaClassNestedNamespace(const FileDescriptor* descriptor) { // TODO(jtattermusch): reintroduce csharp_umbrella_namespace option bool collision = false; - std::string umbrella_classname = GetFileUmbrellaClassname(descriptor); + std::string umbrella_classname = GetUmbrellaClassUnqualifiedName(descriptor); for(int i = 0; i < descriptor->message_type_count(); i++) { if (descriptor->message_type(i)->name() == umbrella_classname) { collision = true; @@ -215,26 +212,17 @@ std::string ToCSharpName(const std::string& name, const FileDescriptor* file) { return "global::" + result; } - - -std::string GetFullUmbrellaClassName(const FileDescriptor* descriptor) { +std::string GetUmbrellaClassName(const FileDescriptor* descriptor) { std::string result = GetFileNamespace(descriptor); if (!result.empty()) { result += '.'; } - result += GetQualifiedUmbrellaClassName(descriptor); - return "global::" + result; -} - -std::string GetQualifiedUmbrellaClassName(const FileDescriptor* descriptor) { - std::string umbrellaNamespace = GetFileUmbrellaNamespace(descriptor); - std::string umbrellaClassname = GetFileUmbrellaClassname(descriptor); - - std::string fullName = umbrellaClassname; + std::string umbrellaNamespace = GetUmbrellaClassNestedNamespace(descriptor); if (!umbrellaNamespace.empty()) { - fullName = umbrellaNamespace + "." + umbrellaClassname; + result += umbrellaNamespace + "."; } - return fullName; + result += GetUmbrellaClassUnqualifiedName(descriptor); + return "global::" + result; } std::string GetClassName(const Descriptor* descriptor) { diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.h b/src/google/protobuf/compiler/csharp/csharp_helpers.h index 7737ffe22a..1d17af61be 100644 --- a/src/google/protobuf/compiler/csharp/csharp_helpers.h +++ b/src/google/protobuf/compiler/csharp/csharp_helpers.h @@ -69,13 +69,12 @@ CSharpType GetCSharpType(FieldDescriptor::Type type); std::string StripDotProto(const std::string& proto_file); -std::string GetFileUmbrellaClassname(const FileDescriptor* descriptor); +// Gets unqualified name of the umbrella class +std::string GetUmbrellaClassUnqualifiedName(const FileDescriptor* descriptor); -std::string GetFileUmbrellaNamespace(const FileDescriptor* descriptor); - -std::string GetFullUmbrellaClassName(const FileDescriptor* descriptor); - -std::string GetQualifiedUmbrellaClassName(const FileDescriptor* descriptor); +// Gets name of the nested for umbrella class (just the nested part, +// not including the GetFileNamespace part). +std::string GetUmbrellaClassNestedNamespace(const FileDescriptor* descriptor); std::string GetClassName(const Descriptor* descriptor); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 54e7d92db7..6ea568ca17 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -100,7 +100,6 @@ void MessageGenerator::Generate(io::Printer* printer) { map vars; vars["class_name"] = class_name(); vars["access_level"] = class_access_level(); - vars["umbrella_class_name"] = GetFullUmbrellaClassName(descriptor_->file()); printer->Print( "[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]\n"); @@ -118,7 +117,7 @@ void MessageGenerator::Generate(io::Printer* printer) { // Access the message descriptor via the relevant file descriptor or containing message descriptor. if (!descriptor_->containing_type()) { - vars["descriptor_accessor"] = GetFullUmbrellaClassName(descriptor_->file()) + vars["descriptor_accessor"] = GetUmbrellaClassName(descriptor_->file()) + ".Descriptor.MessageTypes[" + SimpleItoa(descriptor_->index()) + "]"; } else { vars["descriptor_accessor"] = GetClassName(descriptor_->containing_type()) diff --git a/src/google/protobuf/compiler/csharp/csharp_names.h b/src/google/protobuf/compiler/csharp/csharp_names.h index 74466cd374..ccd2e72089 100644 --- a/src/google/protobuf/compiler/csharp/csharp_names.h +++ b/src/google/protobuf/compiler/csharp/csharp_names.h @@ -65,6 +65,14 @@ string GetFileNamespace(const FileDescriptor* descriptor); // The fully-qualified C# class name. string GetClassName(const Descriptor* descriptor); +// Requires: +// descriptor != NULL +// +// Returns: +// The fully-qualified name of the C# class that provides +// access to the file descriptor. Proto compiler generates +// such class for each .proto file processed. +std::string GetUmbrellaClassName(const FileDescriptor* descriptor); } // namespace csharp } // namespace compiler diff --git a/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc b/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc index 6eb1547e72..0ffae3d4a9 100644 --- a/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc +++ b/src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc @@ -54,8 +54,8 @@ UmbrellaClassGenerator::UmbrellaClassGenerator(const FileDescriptor* file) : SourceGeneratorBase(file), file_(file) { namespace_ = GetFileNamespace(file); - umbrellaClassname_ = GetFileUmbrellaClassname(file); - umbrellaNamespace_ = GetFileUmbrellaNamespace(file); + umbrellaClassname_ = GetUmbrellaClassUnqualifiedName(file); + umbrellaNamespace_ = GetUmbrellaClassNestedNamespace(file); } UmbrellaClassGenerator::~UmbrellaClassGenerator() { @@ -183,7 +183,7 @@ void UmbrellaClassGenerator::WriteDescriptor(io::Printer* printer) { printer->Print( "$full_umbrella_class_name$.Descriptor, ", "full_umbrella_class_name", - GetFullUmbrellaClassName(file_->dependency(i))); + GetUmbrellaClassName(file_->dependency(i))); } printer->Print("},\n" " new pbr::GeneratedCodeInfo(");