aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2010-11-03 10:05:24 +0000
committerJon Skeet <skeet@pobox.com>2010-11-03 10:05:24 +0000
commitc58ce5dc0c6dbe792ad53c63926bb3e8facef47b (patch)
treea6c9b361377f3bf5c1cb21838ec74e03c3d04167 /src/ProtocolBuffers
parentf18a5b09ac622c50e1406860b5f1dffe8d762778 (diff)
parente8e1dab03f8cdd473a3504c4efbe6920eb2c2612 (diff)
downloadprotobuf-c58ce5dc0c6dbe792ad53c63926bb3e8facef47b.tar.gz
protobuf-c58ce5dc0c6dbe792ad53c63926bb3e8facef47b.tar.bz2
protobuf-c58ce5dc0c6dbe792ad53c63926bb3e8facef47b.zip
Merge remote branch 'csharptest/master'
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r--src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs186
-rw-r--r--src/ProtocolBuffers/Descriptors/FileDescriptor.cs62
2 files changed, 224 insertions, 24 deletions
diff --git a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
index 313c855e..ae13b5ac 100644
--- a/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
+++ b/src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
@@ -37,23 +37,26 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
byte[] descriptorData = global::System.Convert.FromBase64String(
"CiRnb29nbGUvcHJvdG9idWYvY3NoYXJwX29wdGlvbnMucHJvdG8SD2dvb2ds" +
"ZS5wcm90b2J1ZhogZ29vZ2xlL3Byb3RvYnVmL2Rlc2NyaXB0b3IucHJvdG8i" +
- "6gEKEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1" +
+ "6wIKEUNTaGFycEZpbGVPcHRpb25zEhEKCW5hbWVzcGFjZRgBIAEoCRIaChJ1" +
"bWJyZ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29nbGUu" +
+ "cHJvdG9idWYuRmllbGRPcHRpb25zGOgHIAEoCzIjLmdvb2dsZS5wcm90b2J1" +
+ "Zi5DU2hhcnBGaWVsZE9wdGlvbnM=");
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root;
internal__static_google_protobuf_CSharpFileOptions__Descriptor = Descriptor.MessageTypes[0];
internal__static_google_protobuf_CSharpFileOptions__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFileOptions.Builder>(internal__static_google_protobuf_CSharpFileOptions__Descriptor,
- new string[] { "Namespace", "UmbrellaClassname", "PublicClasses", "MultipleFiles", "NestClasses", "CodeContracts", "ExpandNamespaceDirectories", "ClsCompliance", });
+ new string[] { "Namespace", "UmbrellaClassname", "PublicClasses", "MultipleFiles", "NestClasses", "CodeContracts", "ExpandNamespaceDirectories", "ClsCompliance", "FileExtension", "UmbrellaNamespace", "OutputDirectory", "IgnoreGoogleProtobuf", });
internal__static_google_protobuf_CSharpFieldOptions__Descriptor = Descriptor.MessageTypes[1];
internal__static_google_protobuf_CSharpFieldOptions__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions, global::Google.ProtocolBuffers.DescriptorProtos.CSharpFieldOptions.Builder>(internal__static_google_protobuf_CSharpFieldOptions__Descriptor,
@@ -173,6 +176,46 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
get { return clsCompliance_; }
}
+ public const int FileExtensionFieldNumber = 221;
+ private bool hasFileExtension;
+ private string fileExtension_ = ".cs";
+ public bool HasFileExtension {
+ get { return hasFileExtension; }
+ }
+ public string FileExtension {
+ get { return fileExtension_; }
+ }
+
+ public const int UmbrellaNamespaceFieldNumber = 222;
+ private bool hasUmbrellaNamespace;
+ private string umbrellaNamespace_ = "";
+ public bool HasUmbrellaNamespace {
+ get { return hasUmbrellaNamespace; }
+ }
+ public string UmbrellaNamespace {
+ get { return umbrellaNamespace_; }
+ }
+
+ public const int OutputDirectoryFieldNumber = 223;
+ private bool hasOutputDirectory;
+ private string outputDirectory_ = ".";
+ public bool HasOutputDirectory {
+ get { return hasOutputDirectory; }
+ }
+ public string OutputDirectory {
+ get { return outputDirectory_; }
+ }
+
+ public const int IgnoreGoogleProtobufFieldNumber = 224;
+ private bool hasIgnoreGoogleProtobuf;
+ private bool ignoreGoogleProtobuf_ = false;
+ public bool HasIgnoreGoogleProtobuf {
+ get { return hasIgnoreGoogleProtobuf; }
+ }
+ public bool IgnoreGoogleProtobuf {
+ get { return ignoreGoogleProtobuf_; }
+ }
+
public override bool IsInitialized {
get {
return true;
@@ -205,6 +248,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (HasClsCompliance) {
output.WriteBool(8, ClsCompliance);
}
+ if (HasFileExtension) {
+ output.WriteString(221, FileExtension);
+ }
+ if (HasUmbrellaNamespace) {
+ output.WriteString(222, UmbrellaNamespace);
+ }
+ if (HasOutputDirectory) {
+ output.WriteString(223, OutputDirectory);
+ }
+ if (HasIgnoreGoogleProtobuf) {
+ output.WriteBool(224, IgnoreGoogleProtobuf);
+ }
UnknownFields.WriteTo(output);
}
@@ -239,6 +294,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (HasClsCompliance) {
size += pb::CodedOutputStream.ComputeBoolSize(8, ClsCompliance);
}
+ if (HasFileExtension) {
+ size += pb::CodedOutputStream.ComputeStringSize(221, FileExtension);
+ }
+ if (HasUmbrellaNamespace) {
+ size += pb::CodedOutputStream.ComputeStringSize(222, UmbrellaNamespace);
+ }
+ if (HasOutputDirectory) {
+ size += pb::CodedOutputStream.ComputeStringSize(223, OutputDirectory);
+ }
+ if (HasIgnoreGoogleProtobuf) {
+ size += pb::CodedOutputStream.ComputeBoolSize(224, IgnoreGoogleProtobuf);
+ }
size += UnknownFields.SerializedSize;
memoizedSerializedSize = size;
return size;
@@ -355,6 +422,18 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
if (other.HasClsCompliance) {
ClsCompliance = other.ClsCompliance;
}
+ if (other.HasFileExtension) {
+ FileExtension = other.FileExtension;
+ }
+ if (other.HasUmbrellaNamespace) {
+ UmbrellaNamespace = other.UmbrellaNamespace;
+ }
+ if (other.HasOutputDirectory) {
+ OutputDirectory = other.OutputDirectory;
+ }
+ if (other.HasIgnoreGoogleProtobuf) {
+ IgnoreGoogleProtobuf = other.IgnoreGoogleProtobuf;
+ }
this.MergeUnknownFields(other.UnknownFields);
return this;
}
@@ -419,6 +498,22 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
ClsCompliance = input.ReadBool();
break;
}
+ case 1770: {
+ FileExtension = input.ReadString();
+ break;
+ }
+ case 1778: {
+ UmbrellaNamespace = input.ReadString();
+ break;
+ }
+ case 1786: {
+ OutputDirectory = input.ReadString();
+ break;
+ }
+ case 1792: {
+ IgnoreGoogleProtobuf = input.ReadBool();
+ break;
+ }
}
}
}
@@ -569,6 +664,81 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
result.clsCompliance_ = true;
return this;
}
+
+ public bool HasFileExtension {
+ get { return result.HasFileExtension; }
+ }
+ public string FileExtension {
+ get { return result.FileExtension; }
+ set { SetFileExtension(value); }
+ }
+ public Builder SetFileExtension(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasFileExtension = true;
+ result.fileExtension_ = value;
+ return this;
+ }
+ public Builder ClearFileExtension() {
+ result.hasFileExtension = false;
+ result.fileExtension_ = ".cs";
+ return this;
+ }
+
+ public bool HasUmbrellaNamespace {
+ get { return result.HasUmbrellaNamespace; }
+ }
+ public string UmbrellaNamespace {
+ get { return result.UmbrellaNamespace; }
+ set { SetUmbrellaNamespace(value); }
+ }
+ public Builder SetUmbrellaNamespace(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasUmbrellaNamespace = true;
+ result.umbrellaNamespace_ = value;
+ return this;
+ }
+ public Builder ClearUmbrellaNamespace() {
+ result.hasUmbrellaNamespace = false;
+ result.umbrellaNamespace_ = "";
+ return this;
+ }
+
+ public bool HasOutputDirectory {
+ get { return result.HasOutputDirectory; }
+ }
+ public string OutputDirectory {
+ get { return result.OutputDirectory; }
+ set { SetOutputDirectory(value); }
+ }
+ public Builder SetOutputDirectory(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasOutputDirectory = true;
+ result.outputDirectory_ = value;
+ return this;
+ }
+ public Builder ClearOutputDirectory() {
+ result.hasOutputDirectory = false;
+ result.outputDirectory_ = ".";
+ return this;
+ }
+
+ public bool HasIgnoreGoogleProtobuf {
+ get { return result.HasIgnoreGoogleProtobuf; }
+ }
+ public bool IgnoreGoogleProtobuf {
+ get { return result.IgnoreGoogleProtobuf; }
+ set { SetIgnoreGoogleProtobuf(value); }
+ }
+ public Builder SetIgnoreGoogleProtobuf(bool value) {
+ result.hasIgnoreGoogleProtobuf = true;
+ result.ignoreGoogleProtobuf_ = value;
+ return this;
+ }
+ public Builder ClearIgnoreGoogleProtobuf() {
+ result.hasIgnoreGoogleProtobuf = false;
+ result.ignoreGoogleProtobuf_ = false;
+ return this;
+ }
}
static CSharpFileOptions() {
object.ReferenceEquals(global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor, null);
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;