aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2010-09-03 16:36:50 -0500
committercsharptest <roger@csharptest.net>2010-09-03 16:36:50 -0500
commite8e1dab03f8cdd473a3504c4efbe6920eb2c2612 (patch)
tree7c03f66af7cb01ed678a82f2832cf90c00a34eca /src/ProtocolBuffers/Descriptors/FileDescriptor.cs
parent5c69749b0b4b4aaa808c208d33b9192e4328e7b4 (diff)
downloadprotobuf-e8e1dab03f8cdd473a3504c4efbe6920eb2c2612.tar.gz
protobuf-e8e1dab03f8cdd473a3504c4efbe6920eb2c2612.tar.bz2
protobuf-e8e1dab03f8cdd473a3504c4efbe6920eb2c2612.zip
Completed the following changes & testing, see todo.txt for more information
1 - Add a way to specify the output directory 2 - Added an option "file_extension" to control the suffix for cs files generated, defaults to ".cs" 3 - Added the option for "umbrella_namespace" used when nest_classes=false and having name conflicts 4 - Optionally remove dependencies to csharp options 5 - Investigate command line parsing library 6 - Investigate calling protoc directly 7 - Unable to resolve dependencies correctly 8 - Added several (20) nunits to automate the command-line invocation of each option
Diffstat (limited to 'src/ProtocolBuffers/Descriptors/FileDescriptor.cs')
-rw-r--r--src/ProtocolBuffers/Descriptors/FileDescriptor.cs62
1 files changed, 46 insertions, 16 deletions
diff --git a/src/ProtocolBuffers/Descriptors/FileDescriptor.cs b/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
index 4d7b54e0..be4a054f 100644
--- a/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
+++ b/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
@@ -73,21 +73,36 @@ namespace Google.ProtocolBuffers.Descriptors {
(field, index) => new FieldDescriptor(field, this, null, index, true));
}
- private CSharpFileOptions BuildOrFakeCSharpOptions() {
- // TODO(jonskeet): Check if we could use FileDescriptorProto.Descriptor.Name - interesting bootstrap issues
- if (proto.Name == "google/protobuf/descriptor.proto") {
- return new CSharpFileOptions.Builder {
- Namespace = "Google.ProtocolBuffers.DescriptorProtos",
- UmbrellaClassname = "DescriptorProtoFile", NestClasses = false, MultipleFiles = false, PublicClasses = true
- }.Build();
- }
- if (proto.Name == "google/protobuf/csharp_options.proto") {
- return new CSharpFileOptions.Builder {
- Namespace = "Google.ProtocolBuffers.DescriptorProtos",
- UmbrellaClassname = "CSharpOptions", NestClasses = false, MultipleFiles = false, PublicClasses = true
- }.Build();
- }
- CSharpFileOptions.Builder builder = CSharpFileOptions.CreateBuilder();
+
+ /// <summary>
+ /// ROK - Added to allow the GeneratorOptions to sepcify the default for any or all of these values
+ /// </summary>
+ internal void ConfigureWithDefaultOptions(CSharpFileOptions options)
+ {
+ csharpFileOptions = BuildOrFakeWithDefaultOptions(options);
+ }
+ private CSharpFileOptions BuildOrFakeWithDefaultOptions(CSharpFileOptions defaultOptions)
+ {
+ // ROK 2010-09-03 - fix for being able to relocate these files to any directory structure
+ if(proto.Package == "google.protobuf") {
+ string filename = System.IO.Path.GetFileName(proto.Name);
+ // TODO(jonskeet): Check if we could use FileDescriptorProto.Descriptor.Name - interesting bootstrap issues)
+ if (filename == "descriptor.proto") {
+ return new CSharpFileOptions.Builder {
+ Namespace = "Google.ProtocolBuffers.DescriptorProtos",
+ UmbrellaClassname = "DescriptorProtoFile", NestClasses = false, MultipleFiles = false, PublicClasses = true,
+ OutputDirectory = defaultOptions.OutputDirectory, IgnoreGoogleProtobuf = defaultOptions.IgnoreGoogleProtobuf
+ }.Build();
+ }
+ if (filename == "csharp_options.proto") {
+ return new CSharpFileOptions.Builder {
+ Namespace = "Google.ProtocolBuffers.DescriptorProtos",
+ UmbrellaClassname = "CSharpOptions", NestClasses = false, MultipleFiles = false, PublicClasses = true,
+ OutputDirectory = defaultOptions.OutputDirectory, IgnoreGoogleProtobuf = defaultOptions.IgnoreGoogleProtobuf
+ }.Build();
+ }
+ }
+ CSharpFileOptions.Builder builder = defaultOptions.ToBuilder();
if (proto.Options.HasExtension(DescriptorProtos.CSharpOptions.CSharpFileOptions)) {
builder.MergeFrom(proto.Options.GetExtension(DescriptorProtos.CSharpOptions.CSharpFileOptions));
}
@@ -99,6 +114,21 @@ namespace Google.ProtocolBuffers.Descriptors {
string baseName = Name.Substring(lastSlash + 1);
builder.UmbrellaClassname = NameHelpers.UnderscoresToPascalCase(NameHelpers.StripProto(baseName));
}
+
+ // ROK 2010-09-03 - auto fix for name collision by placing umbrella class into a new namespace. This
+ // still won't fix the collisions with nesting enabled; however, you have to turn that on so whatever.
+ if(!builder.NestClasses && !builder.HasUmbrellaNamespace) {
+ bool collision = false;
+ 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)
+ builder.UmbrellaNamespace = "Proto";
+ }
+
return builder.Build();
}
@@ -124,7 +154,7 @@ namespace Google.ProtocolBuffers.Descriptors {
get {
lock (optionsLock) {
if (csharpFileOptions == null) {
- csharpFileOptions = BuildOrFakeCSharpOptions();
+ csharpFileOptions = BuildOrFakeWithDefaultOptions(CSharpFileOptions.DefaultInstance);
}
}
return csharpFileOptions;