cmd/protoc-gen-go: generate oneof types seperately

Seperate out the generation of the oneof wrapper types from the
code block that is about getter methods.

Change-Id: Ief44ef953d0b5ad8c998a8542c830ca70468a3bf
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/171029
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 1b05a43..1b8b332 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -476,10 +476,8 @@
 
 	// Getter methods.
 	for _, field := range message.Fields {
-		if field.OneofType != nil {
-			if field == field.OneofType.Fields[0] {
-				genOneofTypes(gen, g, f, message, field.OneofType)
-			}
+		if isFirstOneofField(field) {
+			genOneofGetter(gen, g, f, message, field.OneofType)
 		}
 		goType, pointer := fieldGoType(g, field)
 		defaultValue := fieldDefaultValue(g, message, field)
@@ -510,9 +508,15 @@
 		g.P()
 	}
 
+	// XXX_OneofWrappers method.
 	if len(message.Oneofs) > 0 {
 		genOneofWrappers(gen, g, f, message)
 	}
+
+	// Oneof wrapper types.
+	for _, oneof := range message.Oneofs {
+		genOneofTypes(gen, g, f, message, oneof)
+	}
 }
 
 // fieldGoType returns the Go type used for a field.
@@ -739,11 +743,35 @@
 	g.P(oneofFieldName(oneof), " ", oneofInterfaceName(oneof), " `protobuf_oneof:\"", oneof.Desc.Name(), "\"`")
 }
 
+// genOneofGetter generate a Get method for a oneof.
+func genOneofGetter(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message, oneof *protogen.Oneof) {
+	g.Annotate(message.GoIdent.GoName+".Get"+oneof.GoName, oneof.Location)
+	g.P("func (m *", message.GoIdent.GoName, ") Get", oneof.GoName, "() ", oneofInterfaceName(oneof), " {")
+	g.P("if m != nil {")
+	g.P("return m.", oneofFieldName(oneof))
+	g.P("}")
+	g.P("return nil")
+	g.P("}")
+	g.P()
+}
+
+// genOneofWrappers generates the XXX_OneofWrappers method for a message.
+func genOneofWrappers(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message) {
+	g.P("// XXX_OneofWrappers is for the internal use of the proto package.")
+	g.P("func (*", message.GoIdent.GoName, ") XXX_OneofWrappers() []interface{} {")
+	g.P("return []interface{}{")
+	for _, oneof := range message.Oneofs {
+		for _, field := range oneof.Fields {
+			g.P("(*", fieldOneofType(field), ")(nil),")
+		}
+	}
+	g.P("}")
+	g.P("}")
+	g.P()
+}
+
 // genOneofTypes generates the interface type used for a oneof field,
 // and the wrapper types that satisfy that interface.
-//
-// It also generates the getter method for the parent oneof field
-// (but not the member fields).
 func genOneofTypes(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message, oneof *protogen.Oneof) {
 	ifName := oneofInterfaceName(oneof)
 	g.P("type ", ifName, " interface {")
@@ -767,14 +795,11 @@
 		g.P("func (*", fieldOneofType(field), ") ", ifName, "() {}")
 		g.P()
 	}
-	g.Annotate(message.GoIdent.GoName+".Get"+oneof.GoName, oneof.Location)
-	g.P("func (m *", message.GoIdent.GoName, ") Get", oneof.GoName, "() ", ifName, " {")
-	g.P("if m != nil {")
-	g.P("return m.", oneofFieldName(oneof))
-	g.P("}")
-	g.P("return nil")
-	g.P("}")
-	g.P()
+}
+
+// isFirstOneofField reports whether this is the first field in a oneof.
+func isFirstOneofField(field *protogen.Field) bool {
+	return field.OneofType != nil && field.OneofType.Fields[0] == field
 }
 
 // oneofFieldName returns the name of the struct field holding the oneof value.
@@ -791,21 +816,6 @@
 	return fmt.Sprintf("is%s_%s", oneof.ParentMessage.GoIdent.GoName, oneof.GoName)
 }
 
-// genOneofWrappers generates the XXX_OneofWrappers method for a message.
-func genOneofWrappers(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message) {
-	g.P("// XXX_OneofWrappers is for the internal use of the proto package.")
-	g.P("func (*", message.GoIdent.GoName, ") XXX_OneofWrappers() []interface{} {")
-	g.P("return []interface{}{")
-	for _, oneof := range message.Oneofs {
-		for _, field := range oneof.Fields {
-			g.P("(*", fieldOneofType(field), ")(nil),")
-		}
-	}
-	g.P("}")
-	g.P("}")
-	g.P()
-}
-
 // fieldOneofType returns the wrapper type used to represent a field in a oneof.
 func fieldOneofType(field *protogen.Field) protogen.GoIdent {
 	ident := protogen.GoIdent{
diff --git a/cmd/protoc-gen-go/testdata/comments/comments.pb.go b/cmd/protoc-gen-go/testdata/comments/comments.pb.go
index 4f973b2..af8e8c5 100644
--- a/cmd/protoc-gen-go/testdata/comments/comments.pb.go
+++ b/cmd/protoc-gen-go/testdata/comments/comments.pb.go
@@ -60,16 +60,6 @@
 	return ""
 }
 
-type isMessage1_Oneof1A interface {
-	isMessage1_Oneof1A()
-}
-
-type Message1_Oneof1AField1 struct {
-	Oneof1AField1 string `protobuf:"bytes,2,opt,name=Oneof1AField1,oneof"`
-}
-
-func (*Message1_Oneof1AField1) isMessage1_Oneof1A() {}
-
 func (m *Message1) GetOneof1A() isMessage1_Oneof1A {
 	if m != nil {
 		return m.Oneof1A
@@ -91,6 +81,16 @@
 	}
 }
 
+type isMessage1_Oneof1A interface {
+	isMessage1_Oneof1A()
+}
+
+type Message1_Oneof1AField1 struct {
+	Oneof1AField1 string `protobuf:"bytes,2,opt,name=Oneof1AField1,oneof"`
+}
+
+func (*Message1_Oneof1AField1) isMessage1_Oneof1A() {}
+
 // COMMENT: Message2
 type Message2 struct {
 	XXX_NoUnkeyedLiteral struct{} `json:"-"`
diff --git a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
index b8832bd..88e0b7d 100644
--- a/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
+++ b/cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go
@@ -179,16 +179,6 @@
 	return ""
 }
 
-type isMessage_OneofConflictA_ interface {
-	isMessage_OneofConflictA_()
-}
-
-type Message_OneofConflictA struct {
-	OneofConflictA string `protobuf:"bytes,40,opt,name=OneofConflictA,oneof"`
-}
-
-func (*Message_OneofConflictA) isMessage_OneofConflictA_() {}
-
 func (m *Message) GetOneofConflictA_() isMessage_OneofConflictA_ {
 	if m != nil {
 		return m.OneofConflictA_
@@ -203,22 +193,6 @@
 	return ""
 }
 
-type isMessage_OneofConflictB interface {
-	isMessage_OneofConflictB()
-}
-
-type Message_OneofNoConflict struct {
-	OneofNoConflict string `protobuf:"bytes,50,opt,name=oneof_no_conflict,json=oneofNoConflict,oneof"`
-}
-
-type Message_OneofConflictB_ struct {
-	OneofConflictB_ string `protobuf:"bytes,51,opt,name=OneofConflictB,oneof"`
-}
-
-func (*Message_OneofNoConflict) isMessage_OneofConflictB() {}
-
-func (*Message_OneofConflictB_) isMessage_OneofConflictB() {}
-
 func (m *Message) GetOneofConflictB() isMessage_OneofConflictB {
 	if m != nil {
 		return m.OneofConflictB
@@ -240,16 +214,6 @@
 	return ""
 }
 
-type isMessage_OneofConflictC interface {
-	isMessage_OneofConflictC()
-}
-
-type Message_OneofMessageConflict_ struct {
-	OneofMessageConflict string `protobuf:"bytes,60,opt,name=oneof_message_conflict,json=oneofMessageConflict,oneof"`
-}
-
-func (*Message_OneofMessageConflict_) isMessage_OneofConflictC() {}
-
 func (m *Message) GetOneofConflictC() isMessage_OneofConflictC {
 	if m != nil {
 		return m.OneofConflictC
@@ -274,6 +238,42 @@
 	}
 }
 
+type isMessage_OneofConflictA_ interface {
+	isMessage_OneofConflictA_()
+}
+
+type Message_OneofConflictA struct {
+	OneofConflictA string `protobuf:"bytes,40,opt,name=OneofConflictA,oneof"`
+}
+
+func (*Message_OneofConflictA) isMessage_OneofConflictA_() {}
+
+type isMessage_OneofConflictB interface {
+	isMessage_OneofConflictB()
+}
+
+type Message_OneofNoConflict struct {
+	OneofNoConflict string `protobuf:"bytes,50,opt,name=oneof_no_conflict,json=oneofNoConflict,oneof"`
+}
+
+type Message_OneofConflictB_ struct {
+	OneofConflictB_ string `protobuf:"bytes,51,opt,name=OneofConflictB,oneof"`
+}
+
+func (*Message_OneofNoConflict) isMessage_OneofConflictB() {}
+
+func (*Message_OneofConflictB_) isMessage_OneofConflictB() {}
+
+type isMessage_OneofConflictC interface {
+	isMessage_OneofConflictC()
+}
+
+type Message_OneofMessageConflict_ struct {
+	OneofMessageConflict string `protobuf:"bytes,60,opt,name=oneof_message_conflict,json=oneofMessageConflict,oneof"`
+}
+
+func (*Message_OneofMessageConflict_) isMessage_OneofConflictC() {}
+
 type Message_OneofMessageConflict struct {
 	XXX_NoUnkeyedLiteral struct{} `json:"-"`
 	XXX_unrecognized     []byte   `json:"-"`
diff --git a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
index 053bfb0..cf4e72c 100644
--- a/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
+++ b/cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go
@@ -241,22 +241,6 @@
 	return Default_M_F
 }
 
-type isM_OneofField interface {
-	isM_OneofField()
-}
-
-type M_OneofInt32 struct {
-	OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof"`
-}
-
-type M_OneofInt64 struct {
-	OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof"`
-}
-
-func (*M_OneofInt32) isM_OneofField() {}
-
-func (*M_OneofInt64) isM_OneofField() {}
-
 func (m *M) GetOneofField() isM_OneofField {
 	if m != nil {
 		return m.OneofField
@@ -286,6 +270,22 @@
 	}
 }
 
+type isM_OneofField interface {
+	isM_OneofField()
+}
+
+type M_OneofInt32 struct {
+	OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof"`
+}
+
+type M_OneofInt64 struct {
+	OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof"`
+}
+
+func (*M_OneofInt32) isM_OneofField() {}
+
+func (*M_OneofInt64) isM_OneofField() {}
+
 type M_Submessage struct {
 	// Types that are valid to be assigned to SubmessageOneofField:
 	//	*M_Submessage_SubmessageOneofInt32
@@ -319,22 +319,6 @@
 	return xxx_File_import_public_sub_a_proto_rawDescGZIP(), []int{0, 0}
 }
 
-type isM_Submessage_SubmessageOneofField interface {
-	isM_Submessage_SubmessageOneofField()
-}
-
-type M_Submessage_SubmessageOneofInt32 struct {
-	SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof"`
-}
-
-type M_Submessage_SubmessageOneofInt64 struct {
-	SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof"`
-}
-
-func (*M_Submessage_SubmessageOneofInt32) isM_Submessage_SubmessageOneofField() {}
-
-func (*M_Submessage_SubmessageOneofInt64) isM_Submessage_SubmessageOneofField() {}
-
 func (m *M_Submessage) GetSubmessageOneofField() isM_Submessage_SubmessageOneofField {
 	if m != nil {
 		return m.SubmessageOneofField
@@ -364,6 +348,22 @@
 	}
 }
 
+type isM_Submessage_SubmessageOneofField interface {
+	isM_Submessage_SubmessageOneofField()
+}
+
+type M_Submessage_SubmessageOneofInt32 struct {
+	SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof"`
+}
+
+type M_Submessage_SubmessageOneofInt64 struct {
+	SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof"`
+}
+
+func (*M_Submessage_SubmessageOneofInt32) isM_Submessage_SubmessageOneofField() {}
+
+func (*M_Submessage_SubmessageOneofInt64) isM_Submessage_SubmessageOneofField() {}
+
 var xxx_File_import_public_sub_a_proto_extDescs = []protoiface.ExtensionDescV1{
 	{
 		ExtendedType:  (*M)(nil),
diff --git a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
index 36cc583..a484165 100644
--- a/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
+++ b/cmd/protoc-gen-go/testdata/issue780_oneof_conflict/test.pb.go
@@ -45,16 +45,6 @@
 	return xxx_File_issue780_oneof_conflict_test_proto_rawDescGZIP(), []int{0}
 }
 
-type isFoo_Bar interface {
-	isFoo_Bar()
-}
-
-type Foo_GetBar struct {
-	GetBar string `protobuf:"bytes,1,opt,name=get_bar,json=getBar,oneof"`
-}
-
-func (*Foo_GetBar) isFoo_Bar() {}
-
 func (m *Foo) GetBar() isFoo_Bar {
 	if m != nil {
 		return m.Bar
@@ -76,6 +66,16 @@
 	}
 }
 
+type isFoo_Bar interface {
+	isFoo_Bar()
+}
+
+type Foo_GetBar struct {
+	GetBar string `protobuf:"bytes,1,opt,name=get_bar,json=getBar,oneof"`
+}
+
+func (*Foo_GetBar) isFoo_Bar() {}
+
 var File_issue780_oneof_conflict_test_proto protoreflect.FileDescriptor
 
 var xxx_File_issue780_oneof_conflict_test_proto_rawDesc = []byte{
diff --git a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
index 6906ece..2134518 100644
--- a/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
+++ b/cmd/protoc-gen-go/testdata/proto2/fields.pb.go
@@ -794,124 +794,6 @@
 	return nil
 }
 
-type isFieldTestMessage_OneofField interface {
-	isFieldTestMessage_OneofField()
-}
-
-type FieldTestMessage_OneofBool struct {
-	OneofBool bool `protobuf:"varint,601,opt,name=oneof_bool,json=oneofBool,oneof"`
-}
-
-type FieldTestMessage_OneofEnum struct {
-	OneofEnum FieldTestMessage_Enum `protobuf:"varint,602,opt,name=oneof_enum,json=oneofEnum,enum=goproto.protoc.proto2.FieldTestMessage_Enum,oneof"`
-}
-
-type FieldTestMessage_OneofInt32 struct {
-	OneofInt32 int32 `protobuf:"varint,603,opt,name=oneof_int32,json=oneofInt32,oneof"`
-}
-
-type FieldTestMessage_OneofSint32 struct {
-	OneofSint32 int32 `protobuf:"zigzag32,604,opt,name=oneof_sint32,json=oneofSint32,oneof"`
-}
-
-type FieldTestMessage_OneofUint32 struct {
-	OneofUint32 uint32 `protobuf:"varint,605,opt,name=oneof_uint32,json=oneofUint32,oneof"`
-}
-
-type FieldTestMessage_OneofInt64 struct {
-	OneofInt64 int64 `protobuf:"varint,606,opt,name=oneof_int64,json=oneofInt64,oneof"`
-}
-
-type FieldTestMessage_OneofSint64 struct {
-	OneofSint64 int64 `protobuf:"zigzag64,607,opt,name=oneof_sint64,json=oneofSint64,oneof"`
-}
-
-type FieldTestMessage_OneofUint64 struct {
-	OneofUint64 uint64 `protobuf:"varint,608,opt,name=oneof_uint64,json=oneofUint64,oneof"`
-}
-
-type FieldTestMessage_OneofSfixed32 struct {
-	OneofSfixed32 int32 `protobuf:"fixed32,609,opt,name=oneof_sfixed32,json=oneofSfixed32,oneof"`
-}
-
-type FieldTestMessage_OneofFixed32 struct {
-	OneofFixed32 uint32 `protobuf:"fixed32,610,opt,name=oneof_fixed32,json=oneofFixed32,oneof"`
-}
-
-type FieldTestMessage_OneofFloat struct {
-	OneofFloat float32 `protobuf:"fixed32,611,opt,name=oneof_float,json=oneofFloat,oneof"`
-}
-
-type FieldTestMessage_OneofSfixed64 struct {
-	OneofSfixed64 int64 `protobuf:"fixed64,612,opt,name=oneof_sfixed64,json=oneofSfixed64,oneof"`
-}
-
-type FieldTestMessage_OneofFixed64 struct {
-	OneofFixed64 uint64 `protobuf:"fixed64,613,opt,name=oneof_fixed64,json=oneofFixed64,oneof"`
-}
-
-type FieldTestMessage_OneofDouble struct {
-	OneofDouble float64 `protobuf:"fixed64,614,opt,name=oneof_double,json=oneofDouble,oneof"`
-}
-
-type FieldTestMessage_OneofString struct {
-	OneofString string `protobuf:"bytes,615,opt,name=oneof_string,json=oneofString,oneof"`
-}
-
-type FieldTestMessage_OneofBytes struct {
-	OneofBytes []byte `protobuf:"bytes,616,opt,name=oneof_bytes,json=oneofBytes,oneof"`
-}
-
-type FieldTestMessage_Oneof_Message struct {
-	Oneof_Message *FieldTestMessage_Message `protobuf:"bytes,617,opt,name=oneof_Message,json=oneofMessage,oneof"`
-}
-
-type FieldTestMessage_Oneofgroup struct {
-	Oneofgroup *FieldTestMessage_OneofGroup `protobuf:"group,618,opt,name=OneofGroup,json=oneofgroup,oneof"`
-}
-
-type FieldTestMessage_OneofLargestTag struct {
-	OneofLargestTag int32 `protobuf:"varint,536870911,opt,name=oneof_largest_tag,json=oneofLargestTag,oneof"`
-}
-
-func (*FieldTestMessage_OneofBool) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofEnum) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofInt32) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofSint32) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofUint32) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofInt64) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofSint64) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofUint64) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofSfixed32) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofFixed32) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofFloat) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofSfixed64) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofFixed64) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofDouble) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofString) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofBytes) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_Oneof_Message) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_Oneofgroup) isFieldTestMessage_OneofField() {}
-
-func (*FieldTestMessage_OneofLargestTag) isFieldTestMessage_OneofField() {}
-
 func (m *FieldTestMessage) GetOneofField() isFieldTestMessage_OneofField {
 	if m != nil {
 		return m.OneofField
@@ -1052,22 +934,6 @@
 	return 0
 }
 
-type isFieldTestMessage_OneofTwo interface {
-	isFieldTestMessage_OneofTwo()
-}
-
-type FieldTestMessage_OneofTwo_1 struct {
-	OneofTwo_1 int32 `protobuf:"varint,700,opt,name=oneof_two_1,json=oneofTwo1,oneof"`
-}
-
-type FieldTestMessage_OneofTwo_2 struct {
-	OneofTwo_2 int64 `protobuf:"varint,701,opt,name=oneof_two_2,json=oneofTwo2,oneof"`
-}
-
-func (*FieldTestMessage_OneofTwo_1) isFieldTestMessage_OneofTwo() {}
-
-func (*FieldTestMessage_OneofTwo_2) isFieldTestMessage_OneofTwo() {}
-
 func (m *FieldTestMessage) GetOneofTwo() isFieldTestMessage_OneofTwo {
 	if m != nil {
 		return m.OneofTwo
@@ -1116,6 +982,140 @@
 	}
 }
 
+type isFieldTestMessage_OneofField interface {
+	isFieldTestMessage_OneofField()
+}
+
+type FieldTestMessage_OneofBool struct {
+	OneofBool bool `protobuf:"varint,601,opt,name=oneof_bool,json=oneofBool,oneof"`
+}
+
+type FieldTestMessage_OneofEnum struct {
+	OneofEnum FieldTestMessage_Enum `protobuf:"varint,602,opt,name=oneof_enum,json=oneofEnum,enum=goproto.protoc.proto2.FieldTestMessage_Enum,oneof"`
+}
+
+type FieldTestMessage_OneofInt32 struct {
+	OneofInt32 int32 `protobuf:"varint,603,opt,name=oneof_int32,json=oneofInt32,oneof"`
+}
+
+type FieldTestMessage_OneofSint32 struct {
+	OneofSint32 int32 `protobuf:"zigzag32,604,opt,name=oneof_sint32,json=oneofSint32,oneof"`
+}
+
+type FieldTestMessage_OneofUint32 struct {
+	OneofUint32 uint32 `protobuf:"varint,605,opt,name=oneof_uint32,json=oneofUint32,oneof"`
+}
+
+type FieldTestMessage_OneofInt64 struct {
+	OneofInt64 int64 `protobuf:"varint,606,opt,name=oneof_int64,json=oneofInt64,oneof"`
+}
+
+type FieldTestMessage_OneofSint64 struct {
+	OneofSint64 int64 `protobuf:"zigzag64,607,opt,name=oneof_sint64,json=oneofSint64,oneof"`
+}
+
+type FieldTestMessage_OneofUint64 struct {
+	OneofUint64 uint64 `protobuf:"varint,608,opt,name=oneof_uint64,json=oneofUint64,oneof"`
+}
+
+type FieldTestMessage_OneofSfixed32 struct {
+	OneofSfixed32 int32 `protobuf:"fixed32,609,opt,name=oneof_sfixed32,json=oneofSfixed32,oneof"`
+}
+
+type FieldTestMessage_OneofFixed32 struct {
+	OneofFixed32 uint32 `protobuf:"fixed32,610,opt,name=oneof_fixed32,json=oneofFixed32,oneof"`
+}
+
+type FieldTestMessage_OneofFloat struct {
+	OneofFloat float32 `protobuf:"fixed32,611,opt,name=oneof_float,json=oneofFloat,oneof"`
+}
+
+type FieldTestMessage_OneofSfixed64 struct {
+	OneofSfixed64 int64 `protobuf:"fixed64,612,opt,name=oneof_sfixed64,json=oneofSfixed64,oneof"`
+}
+
+type FieldTestMessage_OneofFixed64 struct {
+	OneofFixed64 uint64 `protobuf:"fixed64,613,opt,name=oneof_fixed64,json=oneofFixed64,oneof"`
+}
+
+type FieldTestMessage_OneofDouble struct {
+	OneofDouble float64 `protobuf:"fixed64,614,opt,name=oneof_double,json=oneofDouble,oneof"`
+}
+
+type FieldTestMessage_OneofString struct {
+	OneofString string `protobuf:"bytes,615,opt,name=oneof_string,json=oneofString,oneof"`
+}
+
+type FieldTestMessage_OneofBytes struct {
+	OneofBytes []byte `protobuf:"bytes,616,opt,name=oneof_bytes,json=oneofBytes,oneof"`
+}
+
+type FieldTestMessage_Oneof_Message struct {
+	Oneof_Message *FieldTestMessage_Message `protobuf:"bytes,617,opt,name=oneof_Message,json=oneofMessage,oneof"`
+}
+
+type FieldTestMessage_Oneofgroup struct {
+	Oneofgroup *FieldTestMessage_OneofGroup `protobuf:"group,618,opt,name=OneofGroup,json=oneofgroup,oneof"`
+}
+
+type FieldTestMessage_OneofLargestTag struct {
+	OneofLargestTag int32 `protobuf:"varint,536870911,opt,name=oneof_largest_tag,json=oneofLargestTag,oneof"`
+}
+
+func (*FieldTestMessage_OneofBool) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofEnum) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofInt32) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofSint32) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofUint32) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofInt64) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofSint64) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofUint64) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofSfixed32) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofFixed32) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofFloat) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofSfixed64) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofFixed64) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofDouble) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofString) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofBytes) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_Oneof_Message) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_Oneofgroup) isFieldTestMessage_OneofField() {}
+
+func (*FieldTestMessage_OneofLargestTag) isFieldTestMessage_OneofField() {}
+
+type isFieldTestMessage_OneofTwo interface {
+	isFieldTestMessage_OneofTwo()
+}
+
+type FieldTestMessage_OneofTwo_1 struct {
+	OneofTwo_1 int32 `protobuf:"varint,700,opt,name=oneof_two_1,json=oneofTwo1,oneof"`
+}
+
+type FieldTestMessage_OneofTwo_2 struct {
+	OneofTwo_2 int64 `protobuf:"varint,701,opt,name=oneof_two_2,json=oneofTwo2,oneof"`
+}
+
+func (*FieldTestMessage_OneofTwo_1) isFieldTestMessage_OneofTwo() {}
+
+func (*FieldTestMessage_OneofTwo_2) isFieldTestMessage_OneofTwo() {}
+
 type FieldTestMessage_OptionalGroup struct {
 	OptionalGroup        *string  `protobuf:"bytes,19,opt,name=optional_group,json=optionalGroup" json:"optional_group,omitempty"`
 	XXX_NoUnkeyedLiteral struct{} `json:"-"`
diff --git a/encoding/testprotos/pb2/test.pb.go b/encoding/testprotos/pb2/test.pb.go
index e5bfe82..a9d1131 100644
--- a/encoding/testprotos/pb2/test.pb.go
+++ b/encoding/testprotos/pb2/test.pb.go
@@ -759,16 +759,6 @@
 	return nil
 }
 
-type isIndirectRequired_Union interface {
-	isIndirectRequired_Union()
-}
-
-type IndirectRequired_OneofNested struct {
-	OneofNested *NestedWithRequired `protobuf:"bytes,4,opt,name=oneof_nested,json=oneofNested,oneof"`
-}
-
-func (*IndirectRequired_OneofNested) isIndirectRequired_Union() {}
-
 func (m *IndirectRequired) GetUnion() isIndirectRequired_Union {
 	if m != nil {
 		return m.Union
@@ -790,6 +780,16 @@
 	}
 }
 
+type isIndirectRequired_Union interface {
+	isIndirectRequired_Union()
+}
+
+type IndirectRequired_OneofNested struct {
+	OneofNested *NestedWithRequired `protobuf:"bytes,4,opt,name=oneof_nested,json=oneofNested,oneof"`
+}
+
+func (*IndirectRequired_OneofNested) isIndirectRequired_Union() {}
+
 type Extensions struct {
 	OptString              *string                     `protobuf:"bytes,1,opt,name=opt_string,json=optString" json:"opt_string,omitempty"`
 	OptBool                *bool                       `protobuf:"varint,101,opt,name=opt_bool,json=optBool" json:"opt_bool,omitempty"`
diff --git a/encoding/testprotos/pb3/test.pb.go b/encoding/testprotos/pb3/test.pb.go
index 383db64..3091b4a 100644
--- a/encoding/testprotos/pb3/test.pb.go
+++ b/encoding/testprotos/pb3/test.pb.go
@@ -412,28 +412,6 @@
 	return xxx_File_pb3_test_proto_rawDescGZIP(), []int{4}
 }
 
-type isOneofs_Union interface {
-	isOneofs_Union()
-}
-
-type Oneofs_OneofEnum struct {
-	OneofEnum Enum `protobuf:"varint,1,opt,name=oneof_enum,json=oneofEnum,proto3,enum=pb3.Enum,oneof"`
-}
-
-type Oneofs_OneofString struct {
-	OneofString string `protobuf:"bytes,2,opt,name=oneof_string,json=oneofString,proto3,oneof"`
-}
-
-type Oneofs_OneofNested struct {
-	OneofNested *Nested `protobuf:"bytes,3,opt,name=oneof_nested,json=oneofNested,proto3,oneof"`
-}
-
-func (*Oneofs_OneofEnum) isOneofs_Union() {}
-
-func (*Oneofs_OneofString) isOneofs_Union() {}
-
-func (*Oneofs_OneofNested) isOneofs_Union() {}
-
 func (m *Oneofs) GetUnion() isOneofs_Union {
 	if m != nil {
 		return m.Union
@@ -471,6 +449,28 @@
 	}
 }
 
+type isOneofs_Union interface {
+	isOneofs_Union()
+}
+
+type Oneofs_OneofEnum struct {
+	OneofEnum Enum `protobuf:"varint,1,opt,name=oneof_enum,json=oneofEnum,proto3,enum=pb3.Enum,oneof"`
+}
+
+type Oneofs_OneofString struct {
+	OneofString string `protobuf:"bytes,2,opt,name=oneof_string,json=oneofString,proto3,oneof"`
+}
+
+type Oneofs_OneofNested struct {
+	OneofNested *Nested `protobuf:"bytes,3,opt,name=oneof_nested,json=oneofNested,proto3,oneof"`
+}
+
+func (*Oneofs_OneofEnum) isOneofs_Union() {}
+
+func (*Oneofs_OneofString) isOneofs_Union() {}
+
+func (*Oneofs_OneofNested) isOneofs_Union() {}
+
 // Message contains map fields.
 type Maps struct {
 	Int32ToStr           map[int32]string   `protobuf:"bytes,1,rep,name=int32_to_str,json=int32ToStr,proto3" json:"int32_to_str,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
diff --git a/internal/testprotos/conformance/conformance.pb.go b/internal/testprotos/conformance/conformance.pb.go
index 8c94d06..ee3004d 100644
--- a/internal/testprotos/conformance/conformance.pb.go
+++ b/internal/testprotos/conformance/conformance.pb.go
@@ -215,34 +215,6 @@
 	return xxx_File_conformance_conformance_proto_rawDescGZIP(), []int{1}
 }
 
-type isConformanceRequest_Payload interface {
-	isConformanceRequest_Payload()
-}
-
-type ConformanceRequest_ProtobufPayload struct {
-	ProtobufPayload []byte `protobuf:"bytes,1,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"`
-}
-
-type ConformanceRequest_JsonPayload struct {
-	JsonPayload string `protobuf:"bytes,2,opt,name=json_payload,json=jsonPayload,proto3,oneof"`
-}
-
-type ConformanceRequest_JspbPayload struct {
-	JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"`
-}
-
-type ConformanceRequest_TextPayload struct {
-	TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"`
-}
-
-func (*ConformanceRequest_ProtobufPayload) isConformanceRequest_Payload() {}
-
-func (*ConformanceRequest_JsonPayload) isConformanceRequest_Payload() {}
-
-func (*ConformanceRequest_JspbPayload) isConformanceRequest_Payload() {}
-
-func (*ConformanceRequest_TextPayload) isConformanceRequest_Payload() {}
-
 func (m *ConformanceRequest) GetPayload() isConformanceRequest_Payload {
 	if m != nil {
 		return m.Payload
@@ -316,6 +288,34 @@
 	}
 }
 
+type isConformanceRequest_Payload interface {
+	isConformanceRequest_Payload()
+}
+
+type ConformanceRequest_ProtobufPayload struct {
+	ProtobufPayload []byte `protobuf:"bytes,1,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"`
+}
+
+type ConformanceRequest_JsonPayload struct {
+	JsonPayload string `protobuf:"bytes,2,opt,name=json_payload,json=jsonPayload,proto3,oneof"`
+}
+
+type ConformanceRequest_JspbPayload struct {
+	JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"`
+}
+
+type ConformanceRequest_TextPayload struct {
+	TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"`
+}
+
+func (*ConformanceRequest_ProtobufPayload) isConformanceRequest_Payload() {}
+
+func (*ConformanceRequest_JsonPayload) isConformanceRequest_Payload() {}
+
+func (*ConformanceRequest_JspbPayload) isConformanceRequest_Payload() {}
+
+func (*ConformanceRequest_TextPayload) isConformanceRequest_Payload() {}
+
 // Represents a single test case's output.
 type ConformanceResponse struct {
 	// Types that are valid to be assigned to Result:
@@ -378,58 +378,6 @@
 	return xxx_File_conformance_conformance_proto_rawDescGZIP(), []int{2}
 }
 
-type isConformanceResponse_Result interface {
-	isConformanceResponse_Result()
-}
-
-type ConformanceResponse_ParseError struct {
-	ParseError string `protobuf:"bytes,1,opt,name=parse_error,json=parseError,proto3,oneof"`
-}
-
-type ConformanceResponse_SerializeError struct {
-	SerializeError string `protobuf:"bytes,6,opt,name=serialize_error,json=serializeError,proto3,oneof"`
-}
-
-type ConformanceResponse_RuntimeError struct {
-	RuntimeError string `protobuf:"bytes,2,opt,name=runtime_error,json=runtimeError,proto3,oneof"`
-}
-
-type ConformanceResponse_ProtobufPayload struct {
-	ProtobufPayload []byte `protobuf:"bytes,3,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"`
-}
-
-type ConformanceResponse_JsonPayload struct {
-	JsonPayload string `protobuf:"bytes,4,opt,name=json_payload,json=jsonPayload,proto3,oneof"`
-}
-
-type ConformanceResponse_Skipped struct {
-	Skipped string `protobuf:"bytes,5,opt,name=skipped,proto3,oneof"`
-}
-
-type ConformanceResponse_JspbPayload struct {
-	JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"`
-}
-
-type ConformanceResponse_TextPayload struct {
-	TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"`
-}
-
-func (*ConformanceResponse_ParseError) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_SerializeError) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_RuntimeError) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_ProtobufPayload) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_JsonPayload) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_Skipped) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_JspbPayload) isConformanceResponse_Result() {}
-
-func (*ConformanceResponse_TextPayload) isConformanceResponse_Result() {}
-
 func (m *ConformanceResponse) GetResult() isConformanceResponse_Result {
 	if m != nil {
 		return m.Result
@@ -507,6 +455,58 @@
 	}
 }
 
+type isConformanceResponse_Result interface {
+	isConformanceResponse_Result()
+}
+
+type ConformanceResponse_ParseError struct {
+	ParseError string `protobuf:"bytes,1,opt,name=parse_error,json=parseError,proto3,oneof"`
+}
+
+type ConformanceResponse_SerializeError struct {
+	SerializeError string `protobuf:"bytes,6,opt,name=serialize_error,json=serializeError,proto3,oneof"`
+}
+
+type ConformanceResponse_RuntimeError struct {
+	RuntimeError string `protobuf:"bytes,2,opt,name=runtime_error,json=runtimeError,proto3,oneof"`
+}
+
+type ConformanceResponse_ProtobufPayload struct {
+	ProtobufPayload []byte `protobuf:"bytes,3,opt,name=protobuf_payload,json=protobufPayload,proto3,oneof"`
+}
+
+type ConformanceResponse_JsonPayload struct {
+	JsonPayload string `protobuf:"bytes,4,opt,name=json_payload,json=jsonPayload,proto3,oneof"`
+}
+
+type ConformanceResponse_Skipped struct {
+	Skipped string `protobuf:"bytes,5,opt,name=skipped,proto3,oneof"`
+}
+
+type ConformanceResponse_JspbPayload struct {
+	JspbPayload string `protobuf:"bytes,7,opt,name=jspb_payload,json=jspbPayload,proto3,oneof"`
+}
+
+type ConformanceResponse_TextPayload struct {
+	TextPayload string `protobuf:"bytes,8,opt,name=text_payload,json=textPayload,proto3,oneof"`
+}
+
+func (*ConformanceResponse_ParseError) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_SerializeError) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_RuntimeError) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_ProtobufPayload) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_JsonPayload) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_Skipped) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_JspbPayload) isConformanceResponse_Result() {}
+
+func (*ConformanceResponse_TextPayload) isConformanceResponse_Result() {}
+
 // Encoding options for jspb format.
 type JspbEncodingConfig struct {
 	// Encode the value field of Any as jspb array if ture, otherwise binary.
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index e6cd19b..0ac6b8e 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -900,64 +900,6 @@
 	return Default_TestAllTypes_DefaultForeignEnum
 }
 
-type isTestAllTypes_OneofField interface {
-	isTestAllTypes_OneofField()
-}
-
-type TestAllTypes_OneofUint32 struct {
-	OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof"`
-}
-
-type TestAllTypes_OneofNestedMessage struct {
-	OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof"`
-}
-
-type TestAllTypes_OneofString struct {
-	OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof"`
-}
-
-type TestAllTypes_OneofBytes struct {
-	OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof"`
-}
-
-type TestAllTypes_OneofBool struct {
-	OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof"`
-}
-
-type TestAllTypes_OneofUint64 struct {
-	OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof"`
-}
-
-type TestAllTypes_OneofFloat struct {
-	OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof"`
-}
-
-type TestAllTypes_OneofDouble struct {
-	OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof"`
-}
-
-type TestAllTypes_OneofEnum struct {
-	OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=goproto.proto.test.TestAllTypes_NestedEnum,oneof"`
-}
-
-func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofNestedMessage) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofString) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofBytes) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofBool) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofUint64) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofFloat) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
-
 func (m *TestAllTypes) GetOneofField() isTestAllTypes_OneofField {
 	if m != nil {
 		return m.OneofField
@@ -1043,6 +985,64 @@
 	}
 }
 
+type isTestAllTypes_OneofField interface {
+	isTestAllTypes_OneofField()
+}
+
+type TestAllTypes_OneofUint32 struct {
+	OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,oneof"`
+}
+
+type TestAllTypes_OneofNestedMessage struct {
+	OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,oneof"`
+}
+
+type TestAllTypes_OneofString struct {
+	OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,oneof"`
+}
+
+type TestAllTypes_OneofBytes struct {
+	OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,oneof"`
+}
+
+type TestAllTypes_OneofBool struct {
+	OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,oneof"`
+}
+
+type TestAllTypes_OneofUint64 struct {
+	OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,oneof"`
+}
+
+type TestAllTypes_OneofFloat struct {
+	OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,oneof"`
+}
+
+type TestAllTypes_OneofDouble struct {
+	OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,oneof"`
+}
+
+type TestAllTypes_OneofEnum struct {
+	OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,enum=goproto.proto.test.TestAllTypes_NestedEnum,oneof"`
+}
+
+func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofNestedMessage) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofString) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofBytes) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofBool) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofUint64) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofFloat) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
+
 // Deprecated: Do not use.
 type TestDeprecatedMessage struct {
 	DeprecatedInt32 *int32 `protobuf:"varint,1,opt,name=deprecated_int32,json=deprecatedInt32" json:"deprecated_int32,omitempty"` // Deprecated: Do not use.
@@ -1085,16 +1085,6 @@
 	return 0
 }
 
-type isTestDeprecatedMessage_DeprecatedOneof interface {
-	isTestDeprecatedMessage_DeprecatedOneof()
-}
-
-type TestDeprecatedMessage_DeprecatedOneofField struct {
-	DeprecatedOneofField int32 `protobuf:"varint,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,oneof"`
-}
-
-func (*TestDeprecatedMessage_DeprecatedOneofField) isTestDeprecatedMessage_DeprecatedOneof() {}
-
 func (m *TestDeprecatedMessage) GetDeprecatedOneof() isTestDeprecatedMessage_DeprecatedOneof {
 	if m != nil {
 		return m.DeprecatedOneof
@@ -1117,6 +1107,16 @@
 	}
 }
 
+type isTestDeprecatedMessage_DeprecatedOneof interface {
+	isTestDeprecatedMessage_DeprecatedOneof()
+}
+
+type TestDeprecatedMessage_DeprecatedOneofField struct {
+	DeprecatedOneofField int32 `protobuf:"varint,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,oneof"`
+}
+
+func (*TestDeprecatedMessage_DeprecatedOneofField) isTestDeprecatedMessage_DeprecatedOneof() {}
+
 type ForeignMessage struct {
 	C                    *int32   `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
 	D                    *int32   `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
diff --git a/internal/testprotos/test3/test.pb.go b/internal/testprotos/test3/test.pb.go
index ad26119..2b5379e 100644
--- a/internal/testprotos/test3/test.pb.go
+++ b/internal/testprotos/test3/test.pb.go
@@ -609,64 +609,6 @@
 	return nil
 }
 
-type isTestAllTypes_OneofField interface {
-	isTestAllTypes_OneofField()
-}
-
-type TestAllTypes_OneofUint32 struct {
-	OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof"`
-}
-
-type TestAllTypes_OneofNestedMessage struct {
-	OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof"`
-}
-
-type TestAllTypes_OneofString struct {
-	OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof"`
-}
-
-type TestAllTypes_OneofBytes struct {
-	OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof"`
-}
-
-type TestAllTypes_OneofBool struct {
-	OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof"`
-}
-
-type TestAllTypes_OneofUint64 struct {
-	OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof"`
-}
-
-type TestAllTypes_OneofFloat struct {
-	OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof"`
-}
-
-type TestAllTypes_OneofDouble struct {
-	OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof"`
-}
-
-type TestAllTypes_OneofEnum struct {
-	OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=goproto.proto.test3.TestAllTypes_NestedEnum,oneof"`
-}
-
-func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofNestedMessage) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofString) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofBytes) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofBool) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofUint64) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofFloat) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {}
-
-func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
-
 func (m *TestAllTypes) GetOneofField() isTestAllTypes_OneofField {
 	if m != nil {
 		return m.OneofField
@@ -752,6 +694,64 @@
 	}
 }
 
+type isTestAllTypes_OneofField interface {
+	isTestAllTypes_OneofField()
+}
+
+type TestAllTypes_OneofUint32 struct {
+	OneofUint32 uint32 `protobuf:"varint,111,opt,name=oneof_uint32,json=oneofUint32,proto3,oneof"`
+}
+
+type TestAllTypes_OneofNestedMessage struct {
+	OneofNestedMessage *TestAllTypes_NestedMessage `protobuf:"bytes,112,opt,name=oneof_nested_message,json=oneofNestedMessage,proto3,oneof"`
+}
+
+type TestAllTypes_OneofString struct {
+	OneofString string `protobuf:"bytes,113,opt,name=oneof_string,json=oneofString,proto3,oneof"`
+}
+
+type TestAllTypes_OneofBytes struct {
+	OneofBytes []byte `protobuf:"bytes,114,opt,name=oneof_bytes,json=oneofBytes,proto3,oneof"`
+}
+
+type TestAllTypes_OneofBool struct {
+	OneofBool bool `protobuf:"varint,115,opt,name=oneof_bool,json=oneofBool,proto3,oneof"`
+}
+
+type TestAllTypes_OneofUint64 struct {
+	OneofUint64 uint64 `protobuf:"varint,116,opt,name=oneof_uint64,json=oneofUint64,proto3,oneof"`
+}
+
+type TestAllTypes_OneofFloat struct {
+	OneofFloat float32 `protobuf:"fixed32,117,opt,name=oneof_float,json=oneofFloat,proto3,oneof"`
+}
+
+type TestAllTypes_OneofDouble struct {
+	OneofDouble float64 `protobuf:"fixed64,118,opt,name=oneof_double,json=oneofDouble,proto3,oneof"`
+}
+
+type TestAllTypes_OneofEnum struct {
+	OneofEnum TestAllTypes_NestedEnum `protobuf:"varint,119,opt,name=oneof_enum,json=oneofEnum,proto3,enum=goproto.proto.test3.TestAllTypes_NestedEnum,oneof"`
+}
+
+func (*TestAllTypes_OneofUint32) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofNestedMessage) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofString) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofBytes) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofBool) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofUint64) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofFloat) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofDouble) isTestAllTypes_OneofField() {}
+
+func (*TestAllTypes_OneofEnum) isTestAllTypes_OneofField() {}
+
 type ForeignMessage struct {
 	C                    int32    `protobuf:"varint,1,opt,name=c,proto3" json:"c,omitempty"`
 	D                    int32    `protobuf:"varint,2,opt,name=d,proto3" json:"d,omitempty"`
diff --git a/types/known/struct.pb.go b/types/known/struct.pb.go
index 8facc31..f4b3c83 100644
--- a/types/known/struct.pb.go
+++ b/types/known/struct.pb.go
@@ -154,46 +154,6 @@
 
 func (*Value) XXX_WellKnownType() string { return "Value" }
 
-type isValue_Kind interface {
-	isValue_Kind()
-}
-
-type Value_NullValue struct {
-	NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=google.protobuf.NullValue,oneof"`
-}
-
-type Value_NumberValue struct {
-	NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,proto3,oneof"`
-}
-
-type Value_StringValue struct {
-	StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof"`
-}
-
-type Value_BoolValue struct {
-	BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof"`
-}
-
-type Value_StructValue struct {
-	StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,proto3,oneof"`
-}
-
-type Value_ListValue struct {
-	ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof"`
-}
-
-func (*Value_NullValue) isValue_Kind() {}
-
-func (*Value_NumberValue) isValue_Kind() {}
-
-func (*Value_StringValue) isValue_Kind() {}
-
-func (*Value_BoolValue) isValue_Kind() {}
-
-func (*Value_StructValue) isValue_Kind() {}
-
-func (*Value_ListValue) isValue_Kind() {}
-
 func (m *Value) GetKind() isValue_Kind {
 	if m != nil {
 		return m.Kind
@@ -255,6 +215,46 @@
 	}
 }
 
+type isValue_Kind interface {
+	isValue_Kind()
+}
+
+type Value_NullValue struct {
+	NullValue NullValue `protobuf:"varint,1,opt,name=null_value,json=nullValue,proto3,enum=google.protobuf.NullValue,oneof"`
+}
+
+type Value_NumberValue struct {
+	NumberValue float64 `protobuf:"fixed64,2,opt,name=number_value,json=numberValue,proto3,oneof"`
+}
+
+type Value_StringValue struct {
+	StringValue string `protobuf:"bytes,3,opt,name=string_value,json=stringValue,proto3,oneof"`
+}
+
+type Value_BoolValue struct {
+	BoolValue bool `protobuf:"varint,4,opt,name=bool_value,json=boolValue,proto3,oneof"`
+}
+
+type Value_StructValue struct {
+	StructValue *Struct `protobuf:"bytes,5,opt,name=struct_value,json=structValue,proto3,oneof"`
+}
+
+type Value_ListValue struct {
+	ListValue *ListValue `protobuf:"bytes,6,opt,name=list_value,json=listValue,proto3,oneof"`
+}
+
+func (*Value_NullValue) isValue_Kind() {}
+
+func (*Value_NumberValue) isValue_Kind() {}
+
+func (*Value_StringValue) isValue_Kind() {}
+
+func (*Value_BoolValue) isValue_Kind() {}
+
+func (*Value_StructValue) isValue_Kind() {}
+
+func (*Value_ListValue) isValue_Kind() {}
+
 // `ListValue` is a wrapper around a repeated field of values.
 //
 // The JSON representation for `ListValue` is JSON array.