aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Tattermusch <jtattermusch@google.com>2015-07-29 20:15:03 -0700
committerJan Tattermusch <jtattermusch@google.com>2015-07-30 14:54:09 -0700
commit43a2dee7085f91d7a7a55f21f0d6c474b7a83c7c (patch)
tree7be44c737bf985b2c9f2a56acb48a1a8069d16e4
parent12febd0a7611858eb026fab7eaf8a4d14c4eba80 (diff)
downloadprotobuf-43a2dee7085f91d7a7a55f21f0d6c474b7a83c7c.tar.gz
protobuf-43a2dee7085f91d7a7a55f21f0d6c474b7a83c7c.tar.bz2
protobuf-43a2dee7085f91d7a7a55f21f0d6c474b7a83c7c.zip
refactor umbrella class helpers
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_generator.cc2
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc32
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.h11
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_message.cc3
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_names.h8
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_umbrella_class.cc6
6 files changed, 28 insertions, 34 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc
index f06d79d8..e0a6c83a 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 1c7a24a9..07305a93 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 7737ffe2..1d17af61 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 54e7d92d..6ea568ca 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<string, string> 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 74466cd3..ccd2e720 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 6eb1547e..0ffae3d4 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(");