Commit ca4cbda9 authored by Jon Skeet's avatar Jon Skeet

Extensions don't need to go under a separate type.

parent d6c94957
......@@ -114,7 +114,7 @@ namespace Google.ProtocolBuffers {
FieldDescriptor messageField = messageType.FindDescriptor<FieldDescriptor>("optional_foreign_message");
FieldDescriptor cordField = messageType.FindDescriptor<FieldDescriptor>("optional_cord");
FieldDescriptor extension = UnitTestProtoFile.OptionalInt32Extension.Descriptor;
FieldDescriptor nestedExtension = TestRequired.Types.Single.Descriptor;
FieldDescriptor nestedExtension = TestRequired.Single.Descriptor;
Assert.AreEqual("optional_int32", primitiveField.Name);
Assert.AreEqual("protobuf_unittest.TestAllTypes.optional_int32",
......
......@@ -116,16 +116,16 @@ namespace Google.ProtocolBuffers {
Assert.IsTrue(builder.IsInitialized);
builder.SetExtension(TestRequired.Types.Single, TestRequiredUninitialized);
builder.SetExtension(TestRequired.Single, TestRequiredUninitialized);
Assert.IsFalse(builder.IsInitialized);
builder.SetExtension(TestRequired.Types.Single, TestRequiredInitialized);
builder.SetExtension(TestRequired.Single, TestRequiredInitialized);
Assert.IsTrue(builder.IsInitialized);
builder.AddExtension(TestRequired.Types.Multi, TestRequiredUninitialized);
builder.AddExtension(TestRequired.Multi, TestRequiredUninitialized);
Assert.IsFalse(builder.IsInitialized);
builder.SetExtension(TestRequired.Types.Multi, 0, TestRequiredInitialized);
builder.SetExtension(TestRequired.Multi, 0, TestRequiredInitialized);
Assert.IsTrue(builder.IsInitialized);
}
......
......@@ -518,10 +518,10 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return self::UnitTestMessageSetProtoFile.internal__static_protobuf_unittest_TestMessageSetExtension1__FieldAccessorTable; }
}
public static readonly pb::GeneratedExtensionBase<self::TestMessageSetExtension1> MessageSetExtension =
pb::GeneratedSingleExtension<self::TestMessageSetExtension1>.CreateInstance(Descriptor.Extensions[0]);
#region Nested types
public static class Types {
public static readonly pb::GeneratedExtensionBase<self::TestMessageSetExtension1> MessageSetExtension =
pb::GeneratedSingleExtension<self::TestMessageSetExtension1>.CreateInstance(Descriptor.Extensions[0]);
}
#endregion
......@@ -728,10 +728,10 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return self::UnitTestMessageSetProtoFile.internal__static_protobuf_unittest_TestMessageSetExtension2__FieldAccessorTable; }
}
public static readonly pb::GeneratedExtensionBase<self::TestMessageSetExtension2> MessageSetExtension =
pb::GeneratedSingleExtension<self::TestMessageSetExtension2>.CreateInstance(Descriptor.Extensions[0]);
#region Nested types
public static class Types {
public static readonly pb::GeneratedExtensionBase<self::TestMessageSetExtension2> MessageSetExtension =
pb::GeneratedSingleExtension<self::TestMessageSetExtension2>.CreateInstance(Descriptor.Extensions[0]);
}
#endregion
......
......@@ -75,10 +75,10 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return self::UnitTestOptimizeForProtoFile.internal__static_protobuf_unittest_TestOptimizedForSize__FieldAccessorTable; }
}
public static readonly pb::GeneratedExtensionBase<int> TestExtension =
pb::GeneratedSingleExtension<int>.CreateInstance(Descriptor.Extensions[0]);
#region Nested types
public static class Types {
public static readonly pb::GeneratedExtensionBase<int> TestExtension =
pb::GeneratedSingleExtension<int>.CreateInstance(Descriptor.Extensions[0]);
}
#endregion
......
......@@ -6147,13 +6147,13 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return self::UnitTestProtoFile.internal__static_protobuf_unittest_TestRequired__FieldAccessorTable; }
}
public static readonly pb::GeneratedExtensionBase<self::TestRequired> Single =
pb::GeneratedSingleExtension<self::TestRequired>.CreateInstance(Descriptor.Extensions[0]);
public static readonly
pb::GeneratedExtensionBase<scg::IList<self::TestRequired>> Multi =
pb::GeneratedRepeatExtension<self::TestRequired>.CreateInstance(Descriptor.Extensions[1]);
#region Nested types
public static class Types {
public static readonly pb::GeneratedExtensionBase<self::TestRequired> Single =
pb::GeneratedSingleExtension<self::TestRequired>.CreateInstance(Descriptor.Extensions[0]);
public static readonly
pb::GeneratedExtensionBase<scg::IList<self::TestRequired>> Multi =
pb::GeneratedRepeatExtension<self::TestRequired>.CreateInstance(Descriptor.Extensions[1]);
}
#endregion
......
......@@ -121,10 +121,10 @@ namespace Google.ProtocolBuffers {
TestMessageSet messageSet =
TestMessageSet.CreateBuilder()
.SetExtension(
TestMessageSetExtension1.Types.MessageSetExtension,
TestMessageSetExtension1.MessageSetExtension,
TestMessageSetExtension1.CreateBuilder().SetI(123).Build())
.SetExtension(
TestMessageSetExtension2.Types.MessageSetExtension,
TestMessageSetExtension2.MessageSetExtension,
TestMessageSetExtension2.CreateBuilder().SetStr("foo").Build())
.SetUnknownFields(
UnknownFieldSet.CreateBuilder()
......@@ -159,8 +159,8 @@ namespace Google.ProtocolBuffers {
[Test]
public void ParseMessageSet() {
ExtensionRegistry extensionRegistry = ExtensionRegistry.CreateInstance();
extensionRegistry.Add(TestMessageSetExtension1.Types.MessageSetExtension);
extensionRegistry.Add(TestMessageSetExtension2.Types.MessageSetExtension);
extensionRegistry.Add(TestMessageSetExtension1.MessageSetExtension);
extensionRegistry.Add(TestMessageSetExtension2.MessageSetExtension);
// Set up a RawMessageSet with two known messages and an unknown one.
RawMessageSet raw =
......@@ -194,8 +194,8 @@ namespace Google.ProtocolBuffers {
TestMessageSet messageSet =
TestMessageSet.ParseFrom(data, extensionRegistry);
Assert.AreEqual(123, messageSet.GetExtension(TestMessageSetExtension1.Types.MessageSetExtension).I);
Assert.AreEqual("foo", messageSet.GetExtension(TestMessageSetExtension2.Types.MessageSetExtension).Str);
Assert.AreEqual(123, messageSet.GetExtension(TestMessageSetExtension1.MessageSetExtension).I);
Assert.AreEqual("foo", messageSet.GetExtension(TestMessageSetExtension2.MessageSetExtension).Str);
// Check for unknown field with type LENGTH_DELIMITED,
// number UNKNOWN_TYPE_ID, and contents "bar".
......
......@@ -237,9 +237,14 @@ void MessageGenerator::Generate(io::Printer* printer) {
"fileclass", ClassName(descriptor_->file()),
"identifier", UniqueFileScopeIdentifier(descriptor_));
// Extensions don't need to go in an extra nested type
for (int i = 0; i < descriptor_->extension_count(); i++) {
ExtensionGenerator(descriptor_->extension(i)).Generate(printer);
}
if (descriptor_->enum_type_count()
+ descriptor_->nested_type_count()
+ descriptor_->extension_count() > 0) {
+ descriptor_->nested_type_count()
+ descriptor_->extension_count() > 0) {
printer->Print("#region Nested types\r\n");
printer->Print("public static class Types {\r\n");
printer->Indent();
......@@ -252,9 +257,6 @@ void MessageGenerator::Generate(io::Printer* printer) {
MessageGenerator(descriptor_->nested_type(i)).Generate(printer);
}
for (int i = 0; i < descriptor_->extension_count(); i++) {
ExtensionGenerator(descriptor_->extension(i)).Generate(printer);
}
printer->Outdent();
printer->Print("}\r\n");
printer->Print("#endregion\r\n\r\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment