@@ -1885,6 +1885,7 @@ type oneofSubField struct {
1885
1885
fieldNumber int // Actual field number, as defined in proto, e.g. 12
1886
1886
getterDef string // Default for getters, e.g. "nil", `""` or "Default_MessageType_FieldName"
1887
1887
protoDef string // Default value as defined in the proto file, e.g "yoshi" or "5"
1888
+ deprecated string // Deprecation comment, if any.
1888
1889
}
1889
1890
1890
1891
// wireTypeName returns a textual wire type, needed for oneof sub fields in generated code.
@@ -2154,6 +2155,9 @@ func (f *oneofField) getter(g *Generator, mc *msgCtx) {
2154
2155
g .P ()
2155
2156
// Getters for each oneof
2156
2157
for _ , sf := range f .subFields {
2158
+ if sf .deprecated != "" {
2159
+ g .P (sf .deprecated )
2160
+ }
2157
2161
g .P ("func (m *" , mc .goName , ") " , Annotate (mc .message .file , sf .fullPath , sf .getterName ), "() " + sf .goType + " {" )
2158
2162
g .P ("if x, ok := m." , f .getterName , "().(*" , sf .oneofTypeName , "); ok {" )
2159
2163
g .P ("return x." , sf .goName )
@@ -2583,6 +2587,11 @@ func (g *Generator) generateMessage(message *Descriptor) {
2583
2587
}
2584
2588
}
2585
2589
2590
+ fieldDeprecated := ""
2591
+ if field .GetOptions ().GetDeprecated () {
2592
+ fieldDeprecated = deprecationComment
2593
+ }
2594
+
2586
2595
dvalue := g .getterDefault (field , goTypeName )
2587
2596
if oneof {
2588
2597
tname := goTypeName + "_" + fieldName
@@ -2626,17 +2635,13 @@ func (g *Generator) generateMessage(message *Descriptor) {
2626
2635
getterDef : dvalue ,
2627
2636
protoDef : field .GetDefaultValue (),
2628
2637
oneofTypeName : tname ,
2638
+ deprecated : fieldDeprecated ,
2629
2639
}
2630
2640
oneofField .subFields = append (oneofField .subFields , & sf )
2631
2641
g .RecordTypeUse (field .GetTypeName ())
2632
2642
continue
2633
2643
}
2634
2644
2635
- fieldDeprecated := ""
2636
- if field .GetOptions ().GetDeprecated () {
2637
- fieldDeprecated = deprecationComment
2638
- }
2639
-
2640
2645
fieldFullPath := fmt .Sprintf ("%s,%d,%d" , message .path , messageFieldPath , i )
2641
2646
c , ok := g .makeComments (fieldFullPath )
2642
2647
if ok {
0 commit comments