From a3ea9d120389d535164e42e45c07b539a398c6e1 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 4 Feb 2016 07:05:49 +0000 Subject: Rename GeneratedCodeInfo to GeneratedClrTypeInfo Recently, descriptor.proto gained a GeneratedCodeInfo message, which means the generated code conflicts with our type. Unfortunately this affects codegen as well, although this is a part of the public API which is very unlikely to affect hand-written code. Generated code changes in next commit. --- Makefile.am | 2 +- csharp/src/Google.Protobuf/Google.Protobuf.csproj | 2 +- .../Google.Protobuf/Reflection/FileDescriptor.cs | 6 +- .../Reflection/GeneratedClrTypeInfo.cs | 103 +++++++++++++++++++++ .../Reflection/GeneratedCodeInfo.cs | 103 --------------------- .../Reflection/MessageDescriptor.cs | 2 +- .../compiler/csharp/csharp_reflection_class.cc | 8 +- 7 files changed, 113 insertions(+), 113 deletions(-) create mode 100644 csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs delete mode 100644 csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs diff --git a/Makefile.am b/Makefile.am index 188346fe..c7267e02 100644 --- a/Makefile.am +++ b/Makefile.am @@ -146,7 +146,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs \ csharp/src/Google.Protobuf/Reflection/FieldType.cs \ csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs \ - csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs \ + csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs \ csharp/src/Google.Protobuf/Reflection/IDescriptor.cs \ csharp/src/Google.Protobuf/Reflection/IFieldAccessor.cs \ csharp/src/Google.Protobuf/Reflection/MapFieldAccessor.cs \ diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index f95bae07..326b6d31 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -109,7 +109,7 @@ - + diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 48ee5596..ab7cd922 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -43,7 +43,7 @@ namespace Google.Protobuf.Reflection /// public sealed class FileDescriptor : IDescriptor { - private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) + private FileDescriptor(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, DescriptorPool pool, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) { SerializedData = descriptorData; DescriptorPool = pool; @@ -223,7 +223,7 @@ namespace Google.Protobuf.Reflection /// If is not /// a valid descriptor. This can occur for a number of reasons, such as a field /// having an undefined type or because two messages were defined with the same name. - private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedCodeInfo generatedCodeInfo) + private static FileDescriptor BuildFrom(ByteString descriptorData, FileDescriptorProto proto, FileDescriptor[] dependencies, bool allowUnknownDependencies, GeneratedClrTypeInfo generatedCodeInfo) { // Building descriptors involves two steps: translating and linking. // In the translation step (implemented by FileDescriptor's @@ -291,7 +291,7 @@ namespace Google.Protobuf.Reflection public static FileDescriptor FromGeneratedCode( byte[] descriptorData, FileDescriptor[] dependencies, - GeneratedCodeInfo generatedCodeInfo) + GeneratedClrTypeInfo generatedCodeInfo) { FileDescriptorProto proto; try diff --git a/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs b/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs new file mode 100644 index 00000000..fe5db656 --- /dev/null +++ b/csharp/src/Google.Protobuf/Reflection/GeneratedClrTypeInfo.cs @@ -0,0 +1,103 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion +using System; + +namespace Google.Protobuf.Reflection +{ + /// + /// Extra information provided by generated code when initializing a message or file descriptor. + /// These are constructed as required, and are not long-lived. Hand-written code should + /// never need to use this type. + /// + public sealed class GeneratedClrTypeInfo + { + private static readonly string[] EmptyNames = new string[0]; + private static readonly GeneratedClrTypeInfo[] EmptyCodeInfo = new GeneratedClrTypeInfo[0]; + + /// + /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. + /// + public Type ClrType { get; private set; } + + /// + /// Irrelevant for file descriptors; the parser for message descriptors. + /// + public MessageParser Parser { get; } + + /// + /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order) + /// for fields in the message for message descriptors. + /// + public string[] PropertyNames { get; } + + /// + /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order) + /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo", + /// there will be a "FooCase" property and a "ClearFoo" method. + /// + public string[] OneofNames { get; } + + /// + /// The reflection information for types within this file/message descriptor. Elements may be null + /// if there is no corresponding generated type, e.g. for map entry types. + /// + public GeneratedClrTypeInfo[] NestedTypes { get; } + + /// + /// The CLR types for enums within this file/message descriptor. + /// + public Type[] NestedEnums { get; } + + /// + /// Creates a GeneratedClrTypeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names. + /// Each array parameter may be null, to indicate a lack of values. + /// The parameter order is designed to make it feasible to format the generated code readably. + /// + public GeneratedClrTypeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) + { + NestedTypes = nestedTypes ?? EmptyCodeInfo; + NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; + ClrType = clrType; + Parser = parser; + PropertyNames = propertyNames ?? EmptyNames; + OneofNames = oneofNames ?? EmptyNames; + } + + /// + /// Creates a GeneratedClrTypeInfo for a file descriptor, with only types and enums. + /// + public GeneratedClrTypeInfo(Type[] nestedEnums, GeneratedClrTypeInfo[] nestedTypes) + : this(null, null, null, null, nestedEnums, nestedTypes) + { + } + } +} \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs b/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs deleted file mode 100644 index e5fe9fb7..00000000 --- a/csharp/src/Google.Protobuf/Reflection/GeneratedCodeInfo.cs +++ /dev/null @@ -1,103 +0,0 @@ -#region Copyright notice and license -// Protocol Buffers - Google's data interchange format -// Copyright 2015 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#endregion -using System; - -namespace Google.Protobuf.Reflection -{ - /// - /// Extra information provided by generated code when initializing a message or file descriptor. - /// These are constructed as required, and are not long-lived. Hand-written code should - /// never need to use this type. - /// - public sealed class GeneratedCodeInfo - { - private static readonly string[] EmptyNames = new string[0]; - private static readonly GeneratedCodeInfo[] EmptyCodeInfo = new GeneratedCodeInfo[0]; - - /// - /// Irrelevant for file descriptors; the CLR type for the message for message descriptors. - /// - public Type ClrType { get; private set; } - - /// - /// Irrelevant for file descriptors; the parser for message descriptors. - /// - public MessageParser Parser { get; } - - /// - /// Irrelevant for file descriptors; the CLR property names (in message descriptor field order) - /// for fields in the message for message descriptors. - /// - public string[] PropertyNames { get; } - - /// - /// Irrelevant for file descriptors; the CLR property "base" names (in message descriptor oneof order) - /// for oneofs in the message for message descriptors. It is expected that for a oneof name of "Foo", - /// there will be a "FooCase" property and a "ClearFoo" method. - /// - public string[] OneofNames { get; } - - /// - /// The reflection information for types within this file/message descriptor. Elements may be null - /// if there is no corresponding generated type, e.g. for map entry types. - /// - public GeneratedCodeInfo[] NestedTypes { get; } - - /// - /// The CLR types for enums within this file/message descriptor. - /// - public Type[] NestedEnums { get; } - - /// - /// Creates a GeneratedCodeInfo for a message descriptor, with nested types, nested enums, the CLR type, property names and oneof names. - /// Each array parameter may be null, to indicate a lack of values. - /// The parameter order is designed to make it feasible to format the generated code readably. - /// - public GeneratedCodeInfo(Type clrType, MessageParser parser, string[] propertyNames, string[] oneofNames, Type[] nestedEnums, GeneratedCodeInfo[] nestedTypes) - { - NestedTypes = nestedTypes ?? EmptyCodeInfo; - NestedEnums = nestedEnums ?? ReflectionUtil.EmptyTypes; - ClrType = clrType; - Parser = parser; - PropertyNames = propertyNames ?? EmptyNames; - OneofNames = oneofNames ?? EmptyNames; - } - - /// - /// Creates a GeneratedCodeInfo for a file descriptor, with only types and enums. - /// - public GeneratedCodeInfo(Type[] nestedEnums, GeneratedCodeInfo[] nestedTypes) - : this(null, null, null, null, nestedEnums, nestedTypes) - { - } - } -} \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index f43803a6..f5798d1e 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -60,7 +60,7 @@ namespace Google.Protobuf.Reflection private readonly IList fieldsInNumberOrder; private readonly IDictionary jsonFieldMap; - internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedCodeInfo generatedCodeInfo) + internal MessageDescriptor(DescriptorProto proto, FileDescriptor file, MessageDescriptor parent, int typeIndex, GeneratedClrTypeInfo generatedCodeInfo) : base(file, file.ComputeFullName(parent, proto.Name), typeIndex) { Proto = proto; diff --git a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc index 3862f001..22dae43b 100644 --- a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc +++ b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc @@ -182,7 +182,7 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) { } } printer->Print("},\n" - " new pbr::GeneratedCodeInfo("); + " new pbr::GeneratedClrTypeInfo("); // Specify all the generated code information, recursively. if (file_->enum_type_count() > 0) { printer->Print("new[] {"); @@ -195,7 +195,7 @@ void ReflectionClassGenerator::WriteDescriptor(io::Printer* printer) { printer->Print("null, "); } if (file_->message_type_count() > 0) { - printer->Print("new pbr::GeneratedCodeInfo[] {\n"); + printer->Print("new pbr::GeneratedClrTypeInfo[] {\n"); printer->Indent(); printer->Indent(); printer->Indent(); @@ -232,7 +232,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript return; } // Generated message type - printer->Print("new pbr::GeneratedCodeInfo(typeof($type_name$), $type_name$.Parser, ", "type_name", GetClassName(descriptor)); + printer->Print("new pbr::GeneratedClrTypeInfo(typeof($type_name$), $type_name$.Parser, ", "type_name", GetClassName(descriptor)); // Fields if (descriptor->field_count() > 0) { @@ -273,7 +273,7 @@ void ReflectionClassGenerator::WriteGeneratedCodeInfo(const Descriptor* descript // Nested types if (descriptor->nested_type_count() > 0) { // Need to specify array type explicitly here, as all elements may be null. - printer->Print("new pbr::GeneratedCodeInfo[] { "); + printer->Print("new pbr::GeneratedClrTypeInfo[] { "); for (int i = 0; i < descriptor->nested_type_count(); i++) { WriteGeneratedCodeInfo(descriptor->nested_type(i), printer, i == descriptor->nested_type_count() - 1); } -- cgit v1.2.3