mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-03-08 19:14:05 +00:00
reflect/protoreflect: remove bool output for Descriptor.Parent method
This is a breaking change. The equivalent replacement logic is to trivially check whether the parent descriptor is not nil. Change-Id: I5c89c1d9f29f9e6f721bbfbcf7774188d8f0086a Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/175987 Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
dddbe8b487
commit
a93fdf5404
@ -251,7 +251,7 @@ type (
|
||||
)
|
||||
|
||||
func (fd *fileDesc) ParentFile() pref.FileDescriptor { return fd }
|
||||
func (fd *fileDesc) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (fd *fileDesc) Parent() pref.Descriptor { return nil }
|
||||
func (fd *fileDesc) Index() int { return 0 }
|
||||
func (fd *fileDesc) Syntax() pref.Syntax { return fd.lazyInit().syntax }
|
||||
func (fd *fileDesc) Name() pref.Name { return fd.Package().Name() }
|
||||
@ -611,7 +611,7 @@ type baseDesc struct {
|
||||
}
|
||||
|
||||
func (d *baseDesc) ParentFile() pref.FileDescriptor { return d.parentFile }
|
||||
func (d *baseDesc) Parent() (pref.Descriptor, bool) { return d.parent, true }
|
||||
func (d *baseDesc) Parent() pref.Descriptor { return d.parent }
|
||||
func (d *baseDesc) Index() int { return d.index }
|
||||
func (d *baseDesc) Syntax() pref.Syntax { return d.parentFile.Syntax() }
|
||||
func (d *baseDesc) IsPlaceholder() bool { return false }
|
||||
|
@ -421,8 +421,8 @@ func TestDescriptor(t *testing.T) {
|
||||
name := v.Type().Method(i).Name
|
||||
if m := v.Method(i); m.Type().NumIn() == 0 && m.Type().NumOut() == 1 {
|
||||
switch name {
|
||||
case "ParentFile":
|
||||
// Ignore parent file to avoid recursive cycle.
|
||||
case "ParentFile", "Parent":
|
||||
// Ignore parents to avoid recursive cycle.
|
||||
case "Index":
|
||||
// Ignore index since legacy descriptors have no parent.
|
||||
case "Options":
|
||||
|
@ -504,6 +504,8 @@ func TestExtensionConvert(t *testing.T) {
|
||||
name := v.Type().Method(i).Name
|
||||
if m := v.Method(i); m.Type().NumIn() == 0 && m.Type().NumOut() == 1 {
|
||||
switch name {
|
||||
case "ParentFile", "Parent":
|
||||
// Ignore parents to avoid recursive cycle.
|
||||
case "New":
|
||||
// Ignore New since it a constructor.
|
||||
case "Options":
|
||||
|
@ -31,7 +31,7 @@ var (
|
||||
type placeholderName pref.FullName
|
||||
|
||||
func (t placeholderName) ParentFile() pref.FileDescriptor { return nil }
|
||||
func (t placeholderName) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (t placeholderName) Parent() pref.Descriptor { return nil }
|
||||
func (t placeholderName) Index() int { return 0 }
|
||||
func (t placeholderName) Syntax() pref.Syntax { return 0 }
|
||||
func (t placeholderName) Name() pref.Name { return pref.FullName(t).Name() }
|
||||
|
@ -111,8 +111,7 @@ type oneofFields oneofFieldsMeta
|
||||
func (p *oneofFieldsMeta) lazyInit(parent pref.Descriptor) *oneofFields {
|
||||
p.once.Do(func() {
|
||||
od := parent.(pref.OneofDescriptor)
|
||||
md, _ := parent.Parent()
|
||||
fs := md.(pref.MessageDescriptor).Fields()
|
||||
fs := parent.Parent().(pref.MessageDescriptor).Fields()
|
||||
for i := 0; i < fs.Len(); i++ {
|
||||
if f := fs.Get(i); od == f.ContainingOneof() {
|
||||
p.typs = append(p.typs, f)
|
||||
|
@ -64,7 +64,7 @@ func newFile(f *File) fileDesc {
|
||||
return fileDesc{f}
|
||||
}
|
||||
func (t fileDesc) ParentFile() pref.FileDescriptor { return t }
|
||||
func (t fileDesc) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (t fileDesc) Parent() pref.Descriptor { return nil }
|
||||
func (t fileDesc) Index() int { return 0 }
|
||||
func (t fileDesc) Syntax() pref.Syntax { return t.f.Syntax }
|
||||
func (t fileDesc) Name() pref.Name { return t.f.Package.Name() }
|
||||
@ -83,7 +83,7 @@ func (t fileDesc) ProtoType(pref.FileDescriptor) {}
|
||||
func (t fileDesc) ProtoInternal(pragma.DoNotImplement) {}
|
||||
|
||||
func parentFile(d protoreflect.Descriptor) protoreflect.FileDescriptor {
|
||||
for ; d != nil; d, _ = d.Parent() {
|
||||
for ; d != nil; d = d.Parent() {
|
||||
if fd, ok := d.(protoreflect.FileDescriptor); ok {
|
||||
return fd
|
||||
}
|
||||
@ -104,7 +104,7 @@ type messageMeta struct {
|
||||
type messageDesc struct{ m *Message }
|
||||
|
||||
func (t messageDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t messageDesc) Parent() (pref.Descriptor, bool) { return t.m.parent, true }
|
||||
func (t messageDesc) Parent() pref.Descriptor { return t.m.parent }
|
||||
func (t messageDesc) Index() int { return t.m.index }
|
||||
func (t messageDesc) Syntax() pref.Syntax { return t.m.syntax }
|
||||
func (t messageDesc) Name() pref.Name { return t.m.Name }
|
||||
@ -156,7 +156,7 @@ type fieldMeta struct {
|
||||
type fieldDesc struct{ f *Field }
|
||||
|
||||
func (t fieldDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t fieldDesc) Parent() (pref.Descriptor, bool) { return t.f.parent, true }
|
||||
func (t fieldDesc) Parent() pref.Descriptor { return t.f.parent }
|
||||
func (t fieldDesc) Index() int { return t.f.index }
|
||||
func (t fieldDesc) Syntax() pref.Syntax { return t.f.syntax }
|
||||
func (t fieldDesc) Name() pref.Name { return t.f.Name }
|
||||
@ -264,8 +264,7 @@ type oneofReference struct {
|
||||
func (p *oneofReference) lazyInit(parent pref.Descriptor, name pref.Name) pref.OneofDescriptor {
|
||||
p.once.Do(func() {
|
||||
if name != "" {
|
||||
mtyp, _ := parent.Parent()
|
||||
p.otyp = mtyp.(pref.MessageDescriptor).Oneofs().ByName(name)
|
||||
p.otyp = parent.Parent().(pref.MessageDescriptor).Oneofs().ByName(name)
|
||||
// TODO: We need validate to detect this mismatch.
|
||||
}
|
||||
})
|
||||
@ -280,7 +279,7 @@ type oneofMeta struct {
|
||||
type oneofDesc struct{ o *Oneof }
|
||||
|
||||
func (t oneofDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t oneofDesc) Parent() (pref.Descriptor, bool) { return t.o.parent, true }
|
||||
func (t oneofDesc) Parent() pref.Descriptor { return t.o.parent }
|
||||
func (t oneofDesc) Index() int { return t.o.index }
|
||||
func (t oneofDesc) Syntax() pref.Syntax { return t.o.syntax }
|
||||
func (t oneofDesc) Name() pref.Name { return t.o.Name }
|
||||
@ -303,7 +302,7 @@ type extensionMeta struct {
|
||||
type extensionDesc struct{ x *Extension }
|
||||
|
||||
func (t extensionDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t extensionDesc) Parent() (pref.Descriptor, bool) { return t.x.parent, true }
|
||||
func (t extensionDesc) Parent() pref.Descriptor { return t.x.parent }
|
||||
func (t extensionDesc) Syntax() pref.Syntax { return t.x.syntax }
|
||||
func (t extensionDesc) Index() int { return t.x.index }
|
||||
func (t extensionDesc) Name() pref.Name { return t.x.Name }
|
||||
@ -352,7 +351,7 @@ type enumMeta struct {
|
||||
type enumDesc struct{ e *Enum }
|
||||
|
||||
func (t enumDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t enumDesc) Parent() (pref.Descriptor, bool) { return t.e.parent, true }
|
||||
func (t enumDesc) Parent() pref.Descriptor { return t.e.parent }
|
||||
func (t enumDesc) Index() int { return t.e.index }
|
||||
func (t enumDesc) Syntax() pref.Syntax { return t.e.syntax }
|
||||
func (t enumDesc) Name() pref.Name { return t.e.Name }
|
||||
@ -372,7 +371,7 @@ type enumValueMeta struct {
|
||||
type enumValueDesc struct{ v *EnumValue }
|
||||
|
||||
func (t enumValueDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t enumValueDesc) Parent() (pref.Descriptor, bool) { return t.v.parent, true }
|
||||
func (t enumValueDesc) Parent() pref.Descriptor { return t.v.parent }
|
||||
func (t enumValueDesc) Index() int { return t.v.index }
|
||||
func (t enumValueDesc) Syntax() pref.Syntax { return t.v.syntax }
|
||||
func (t enumValueDesc) Name() pref.Name { return t.v.Name }
|
||||
@ -394,7 +393,7 @@ type serviceMeta struct {
|
||||
type serviceDesc struct{ s *Service }
|
||||
|
||||
func (t serviceDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t serviceDesc) Parent() (pref.Descriptor, bool) { return t.s.parent, true }
|
||||
func (t serviceDesc) Parent() pref.Descriptor { return t.s.parent }
|
||||
func (t serviceDesc) Index() int { return t.s.index }
|
||||
func (t serviceDesc) Syntax() pref.Syntax { return t.s.syntax }
|
||||
func (t serviceDesc) Name() pref.Name { return t.s.Name }
|
||||
@ -417,7 +416,7 @@ type methodMeta struct {
|
||||
type methodDesc struct{ m *Method }
|
||||
|
||||
func (t methodDesc) ParentFile() pref.FileDescriptor { return parentFile(t) }
|
||||
func (t methodDesc) Parent() (pref.Descriptor, bool) { return t.m.parent, true }
|
||||
func (t methodDesc) Parent() pref.Descriptor { return t.m.parent }
|
||||
func (t methodDesc) Index() int { return t.m.index }
|
||||
func (t methodDesc) Syntax() pref.Syntax { return t.m.syntax }
|
||||
func (t methodDesc) Name() pref.Name { return t.m.Name }
|
||||
@ -577,7 +576,7 @@ func resolveReference(parent pref.Descriptor, refName pref.FullName) pref.Descri
|
||||
}
|
||||
// No match. (e.g., refName: foo.firetruck, curName: foo.fire)
|
||||
}
|
||||
cur, _ = cur.Parent() // nil after ascending above FileDescriptor
|
||||
cur = cur.Parent() // nil after ascending above FileDescriptor
|
||||
}
|
||||
|
||||
// Descend downwards to resolve all relative names.
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
type standaloneMessage struct{ m *StandaloneMessage }
|
||||
|
||||
func (t standaloneMessage) ParentFile() pref.FileDescriptor { return nil }
|
||||
func (t standaloneMessage) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (t standaloneMessage) Parent() pref.Descriptor { return nil }
|
||||
func (t standaloneMessage) Index() int { return 0 }
|
||||
func (t standaloneMessage) Syntax() pref.Syntax { return t.m.Syntax }
|
||||
func (t standaloneMessage) Name() pref.Name { return t.m.FullName.Name() }
|
||||
@ -49,7 +49,7 @@ func (t standaloneMessage) ProtoInternal(pragma.DoNotImplement) {}
|
||||
type standaloneEnum struct{ e *StandaloneEnum }
|
||||
|
||||
func (t standaloneEnum) ParentFile() pref.FileDescriptor { return nil }
|
||||
func (t standaloneEnum) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (t standaloneEnum) Parent() pref.Descriptor { return nil }
|
||||
func (t standaloneEnum) Index() int { return 0 }
|
||||
func (t standaloneEnum) Syntax() pref.Syntax { return t.e.Syntax }
|
||||
func (t standaloneEnum) Name() pref.Name { return t.e.FullName.Name() }
|
||||
@ -68,7 +68,7 @@ func (t standaloneEnum) ProtoInternal(pragma.DoNotImplement) {}
|
||||
type standaloneExtension struct{ x *StandaloneExtension }
|
||||
|
||||
func (t standaloneExtension) ParentFile() pref.FileDescriptor { return nil }
|
||||
func (t standaloneExtension) Parent() (pref.Descriptor, bool) { return nil, false }
|
||||
func (t standaloneExtension) Parent() pref.Descriptor { return nil }
|
||||
func (t standaloneExtension) Index() int { return 0 }
|
||||
func (t standaloneExtension) Syntax() pref.Syntax { return pref.Proto2 }
|
||||
func (t standaloneExtension) Name() pref.Name { return t.x.FullName.Name() }
|
||||
|
@ -45,8 +45,8 @@ type Descriptor interface {
|
||||
// | MethodDescriptor | ServiceDescriptor |
|
||||
// +---------------------+-----------------------------------+
|
||||
//
|
||||
// Support for this functionality is optional and may return (nil, false).
|
||||
Parent() (Descriptor, bool)
|
||||
// Support for this functionality is optional and may return nil.
|
||||
Parent() Descriptor
|
||||
|
||||
// Index returns the the index of this descriptor within its parent.
|
||||
// It returns 0 if the descriptor does not have a parent or if the parent
|
||||
|
Loading…
x
Reference in New Issue
Block a user