aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/csharp/csharp_helpers.cc
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2015-04-13 16:32:54 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2015-04-13 16:32:54 -0700
commit7cc05ecb3a6fecf97604ab89803e7cbb34838268 (patch)
treeb9405fbc4362b509184e34af65689c5bd50ecc02 /src/google/protobuf/compiler/csharp/csharp_helpers.cc
parent5ac8de5b46a7b2adb81f957dfb78c612137d9ffb (diff)
fixing implementation of GetFileUmbrellaNamespace
Diffstat (limited to 'src/google/protobuf/compiler/csharp/csharp_helpers.cc')
-rw-r--r--src/google/protobuf/compiler/csharp/csharp_helpers.cc40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/google/protobuf/compiler/csharp/csharp_helpers.cc b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
index fd6e3722..c7e9e4cc 100644
--- a/src/google/protobuf/compiler/csharp/csharp_helpers.cc
+++ b/src/google/protobuf/compiler/csharp/csharp_helpers.cc
@@ -127,26 +127,30 @@ std::string GetFileUmbrellaClassname(const FileDescriptor* descriptor) {
}
std::string GetFileUmbrellaNamespace(const FileDescriptor* descriptor) {
- if (!descriptor->options().has_csharp_umbrella_namespace()) {
- bool collision = false;
- // TODO(jtattermusch): detect collisions!
-// foreach (IDescriptor d in MessageTypes)
-// {
-// collision |= d.Name == builder.UmbrellaClassname;
-// }
-// foreach (IDescriptor d in Services)
-// {
-// collision |= d.Name == builder.UmbrellaClassname;
-// }
-// foreach (IDescriptor d in EnumTypes)
-// {
-// collision |= d.Name == builder.UmbrellaClassname;
-// }
- if (collision) {
- return "Proto";
+ if (descriptor->options().has_csharp_umbrella_namespace()) {
+ return descriptor->options().csharp_umbrella_namespace();
+ }
+ bool collision = false;
+ std::string umbrella_classname = GetFileUmbrellaClassname(descriptor);
+ for(int i = 0; i < descriptor->message_type_count(); i++) {
+ if (descriptor->message_type(i)->name() == umbrella_classname) {
+ collision = true;
+ break;
+ }
+ }
+ for (int i = 0; i < descriptor->service_count(); i++) {
+ if (descriptor->service(i)->name() == umbrella_classname) {
+ collision = true;
+ break;
+ }
+ }
+ for (int i = 0; i < descriptor->enum_type_count(); i++) {
+ if (descriptor->enum_type(i)->name() == umbrella_classname) {
+ collision = true;
+ break;
}
}
- return "";
+ return collision ? "Proto" : "";
}
// TODO(jtattermusch): can we reuse a utility function?