cmd/protoc-gen-go: improve generation of comments
The following improvements were made:
* All standalone comments above the "syntax" marker are preserved
similar to Java and some other generators.
* All standalone comments above the "package" marker are preserved
to be consistent with our former behavior.
* Leading comments are now generated for enums and extension fields.
* Single-line trailing comments are now generated for
enum values, message fields, and extension fields.
* The leading comments for each field that is part of a oneof are now
generated with the wrapper types rather than being shoved into the
comment for the oneof itself in an unreadable way.
* The deprecation marker is always generated as being above the declaration
rather than sometimes being an inlined comment.
* The deprecation marker is now properly generated for weak field setters.
Updates golang/protobuf#666
Change-Id: I7fd832dd4f86d15bfff70d7c22c6ba4934c05fcf
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189238
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/test/test.pb.go b/internal/testprotos/test/test.pb.go
index 41a649e..9f5b4cd 100644
--- a/internal/testprotos/test/test.pb.go
+++ b/internal/testprotos/test/test.pb.go
@@ -1,3 +1,7 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: test/test.proto
@@ -137,7 +141,7 @@
TestAllTypes_FOO TestAllTypes_NestedEnum = 0
TestAllTypes_BAR TestAllTypes_NestedEnum = 1
TestAllTypes_BAZ TestAllTypes_NestedEnum = 2
- TestAllTypes_NEG TestAllTypes_NestedEnum = -1
+ TestAllTypes_NEG TestAllTypes_NestedEnum = -1 // Intentionally negative.
)
// Enum value maps for TestAllTypes_NestedEnum.
@@ -193,9 +197,12 @@
return file_test_test_proto_rawDescGZIP(), []int{0, 0}
}
-type TestDeprecatedMessage_DeprecatedEnum int32 // Deprecated: Do not use.
+// Deprecated: Do not use.
+type TestDeprecatedMessage_DeprecatedEnum int32
+
const (
- TestDeprecatedMessage_DEPRECATED TestDeprecatedMessage_DeprecatedEnum = 0 // Deprecated: Do not use.
+ // Deprecated: Do not use.
+ TestDeprecatedMessage_DEPRECATED TestDeprecatedMessage_DeprecatedEnum = 0
)
// Enum value maps for TestDeprecatedMessage_DeprecatedEnum.
@@ -246,9 +253,10 @@
}
type TestAllTypes struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
OptionalInt32 *int32 `protobuf:"varint,1,opt,name=optional_int32,json=optionalInt32" json:"optional_int32,omitempty"`
OptionalInt64 *int64 `protobuf:"varint,2,opt,name=optional_int64,json=optionalInt64" json:"optional_int64,omitempty"`
OptionalUint32 *uint32 `protobuf:"varint,3,opt,name=optional_uint32,json=optionalUint32" json:"optional_uint32,omitempty"`
@@ -328,7 +336,7 @@
DefaultBytes []byte `protobuf:"bytes,95,opt,name=default_bytes,json=defaultBytes,def=world" json:"default_bytes,omitempty"`
DefaultNestedEnum *TestAllTypes_NestedEnum `protobuf:"varint,96,opt,name=default_nested_enum,json=defaultNestedEnum,enum=goproto.proto.test.TestAllTypes_NestedEnum,def=1" json:"default_nested_enum,omitempty"`
DefaultForeignEnum *ForeignEnum `protobuf:"varint,97,opt,name=default_foreign_enum,json=defaultForeignEnum,enum=goproto.proto.test.ForeignEnum,def=5" json:"default_foreign_enum,omitempty"`
- // Types that are valid to be assigned to OneofField:
+ // Types that are assignable to OneofField:
// *TestAllTypes_OneofUint32
// *TestAllTypes_OneofNestedMessage
// *TestAllTypes_OneofString
@@ -1069,11 +1077,13 @@
// Deprecated: Do not use.
type TestDeprecatedMessage struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
- DeprecatedInt32 *int32 `protobuf:"varint,1,opt,name=deprecated_int32,json=deprecatedInt32" json:"deprecated_int32,omitempty"` // Deprecated: Do not use.
- // Types that are valid to be assigned to DeprecatedOneof:
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // Deprecated: Do not use.
+ DeprecatedInt32 *int32 `protobuf:"varint,1,opt,name=deprecated_int32,json=deprecatedInt32" json:"deprecated_int32,omitempty"`
+ // Types that are assignable to DeprecatedOneof:
// *TestDeprecatedMessage_DeprecatedOneofField
DeprecatedOneof isTestDeprecatedMessage_DeprecatedOneof `protobuf_oneof:"deprecated_oneof"`
}
@@ -1133,6 +1143,7 @@
}
type TestDeprecatedMessage_DeprecatedOneofField struct {
+ // Deprecated: Do not use.
DeprecatedOneofField int32 `protobuf:"varint,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,oneof"`
}
@@ -1142,8 +1153,9 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- C *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
- D *int32 `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
+
+ C *int32 `protobuf:"varint,1,opt,name=c" json:"c,omitempty"`
+ D *int32 `protobuf:"varint,2,opt,name=d" json:"d,omitempty"`
}
func (x *ForeignMessage) Reset() {
@@ -1267,7 +1279,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
}
func (x *OptionalGroupExtension) Reset() {
@@ -1308,7 +1321,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
}
func (x *RepeatedGroupExtension) Reset() {
@@ -1382,6 +1396,7 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
+
RequiredField *int32 `protobuf:"varint,1,req,name=required_field,json=requiredField" json:"required_field,omitempty"`
}
@@ -1420,13 +1435,14 @@
}
type TestRequiredForeign struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
OptionalMessage *TestRequired `protobuf:"bytes,1,opt,name=optional_message,json=optionalMessage" json:"optional_message,omitempty"`
RepeatedMessage []*TestRequired `protobuf:"bytes,2,rep,name=repeated_message,json=repeatedMessage" json:"repeated_message,omitempty"`
MapMessage map[int32]*TestRequired `protobuf:"bytes,3,rep,name=map_message,json=mapMessage" json:"map_message,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
- // Types that are valid to be assigned to OneofField:
+ // Types that are assignable to OneofField:
// *TestRequiredForeign_OneofMessage
OneofField isTestRequiredForeign_OneofField `protobuf_oneof:"oneof_field"`
}
@@ -1507,6 +1523,7 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
+
Optionalgroup *TestRequiredGroupFields_OptionalGroup `protobuf:"group,1,opt,name=OptionalGroup,json=optionalgroup" json:"optionalgroup,omitempty"`
Repeatedgroup []*TestRequiredGroupFields_RepeatedGroup `protobuf:"group,3,rep,name=RepeatedGroup,json=repeatedgroup" json:"repeatedgroup,omitempty"`
}
@@ -1553,10 +1570,11 @@
}
type TestWeak struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- XXX_weak protoimpl.WeakFields `json:"-"`
- unknownFields protoimpl.UnknownFields
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ XXX_weak protoimpl.WeakFields `json:"-"`
+ unknownFields protoimpl.UnknownFields
+
XXX_weak_WeakMessage1 struct{} `protobuf:"bytes,1,opt,name=weak_message1,json=weakMessage1,weak=goproto.proto.test.weak.WeakImportMessage1" json:"weak_message1,omitempty"`
XXX_weak_WeakMessage2 struct{} `protobuf:"bytes,2,opt,name=weak_message2,json=weakMessage2,weak=goproto.proto.test.weak.WeakImportMessage2" json:"weak_message2,omitempty"`
}
@@ -1635,9 +1653,10 @@
}
type TestPackedTypes struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
PackedInt32 []int32 `protobuf:"varint,90,rep,packed,name=packed_int32,json=packedInt32" json:"packed_int32,omitempty"`
PackedInt64 []int64 `protobuf:"varint,91,rep,packed,name=packed_int64,json=packedInt64" json:"packed_int64,omitempty"`
PackedUint32 []uint32 `protobuf:"varint,92,rep,packed,name=packed_uint32,json=packedUint32" json:"packed_uint32,omitempty"`
@@ -1780,9 +1799,10 @@
}
type TestUnpackedTypes struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
UnpackedInt32 []int32 `protobuf:"varint,90,rep,name=unpacked_int32,json=unpackedInt32" json:"unpacked_int32,omitempty"`
UnpackedInt64 []int64 `protobuf:"varint,91,rep,name=unpacked_int64,json=unpackedInt64" json:"unpacked_int64,omitempty"`
UnpackedUint32 []uint32 `protobuf:"varint,92,rep,name=unpacked_uint32,json=unpackedUint32" json:"unpacked_uint32,omitempty"`
@@ -2081,8 +2101,9 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
- Corecursive *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
+
+ A *int32 `protobuf:"varint,1,opt,name=a" json:"a,omitempty"`
+ Corecursive *TestAllTypes `protobuf:"bytes,2,opt,name=corecursive" json:"corecursive,omitempty"`
}
func (x *TestAllTypes_NestedMessage) Reset() {
@@ -2130,7 +2151,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,17,opt,name=a" json:"a,omitempty"`
}
func (x *TestAllTypes_OptionalGroup) Reset() {
@@ -2171,7 +2193,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,47,opt,name=a" json:"a,omitempty"`
}
func (x *TestAllTypes_RepeatedGroup) Reset() {
@@ -2212,7 +2235,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,2,req,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,2,req,name=a" json:"a,omitempty"`
}
func (x *TestRequiredGroupFields_OptionalGroup) Reset() {
@@ -2253,7 +2277,8 @@
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- A *int32 `protobuf:"varint,4,req,name=a" json:"a,omitempty"`
+
+ A *int32 `protobuf:"varint,4,req,name=a" json:"a,omitempty"`
}
func (x *TestRequiredGroupFields_RepeatedGroup) Reset() {