From 52ec1759a437701b326351c81454b7cdb768da1e Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Mon, 5 Aug 2019 15:49:29 -0700 Subject: [PATCH] internal/filedesc, internal/filetype: rename {Desc,Type}Builder as Builder Reduce the stutter in the name since the type of Builder is obvious from the package it is from. Change-Id: I0046a5122717536cc6bb5ebdb32b67a1560cfc23 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/189020 Reviewed-by: Damien Neil --- internal/filedesc/build.go | 16 ++++++++-------- internal/filedesc/desc_init.go | 4 ++-- internal/filedesc/desc_lazy.go | 2 +- internal/filedesc/desc_test.go | 4 ++-- internal/filetype/build.go | 8 ++++---- internal/impl/legacy_file.go | 2 +- runtime/protoimpl/impl.go | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/filedesc/build.go b/internal/filedesc/build.go index 427e26e6..916b89a3 100644 --- a/internal/filedesc/build.go +++ b/internal/filedesc/build.go @@ -13,8 +13,8 @@ import ( preg "google.golang.org/protobuf/reflect/protoregistry" ) -// DescBuilder construct a protoreflect.FileDescriptor from the raw descriptor. -type DescBuilder struct { +// Builder construct a protoreflect.FileDescriptor from the raw descriptor. +type Builder struct { // GoPackagePath is the Go package path that is invoking this builder. GoPackagePath string @@ -48,15 +48,15 @@ type DescBuilder struct { } } -// resolverByIndex is an interface DescBuilder.FileRegistry may implement. +// resolverByIndex is an interface Builder.FileRegistry may implement. // If so, it permits looking up an enum or message dependency based on the -// sub-list and element index into filetype.TypeBuilder.DependencyIndexes. +// sub-list and element index into filetype.Builder.DependencyIndexes. type resolverByIndex interface { FindEnumByIndex(int32, int32, []Enum, []Message) pref.EnumDescriptor FindMessageByIndex(int32, int32, []Enum, []Message) pref.MessageDescriptor } -// Indexes of each sub-list in filetype.TypeBuilder.DependencyIndexes. +// Indexes of each sub-list in filetype.Builder.DependencyIndexes. const ( listFieldDeps int32 = iota listExtTargets @@ -65,13 +65,13 @@ const ( listMethOutDeps ) -// Build constructs a FileDescriptor given the parameters set in DescBuilder. +// Build constructs a FileDescriptor given the parameters set in Builder. // It assumes that the inputs are well-formed and panics if any inconsistencies // are encountered. // // If NumEnums+NumMessages+NumExtensions+NumServices is zero, // then Build automatically derives them from the raw descriptor. -func (db DescBuilder) Build() (out struct { +func (db Builder) Build() (out struct { File pref.FileDescriptor // Enums is all enum descriptors in "flattened ordering". @@ -113,7 +113,7 @@ func (db DescBuilder) Build() (out struct { // unmarshalCounts counts the number of enum, message, extension, and service // declarations in the raw message, which is either a FileDescriptorProto // or a MessageDescriptorProto depending on whether isFile is set. -func (db *DescBuilder) unmarshalCounts(b []byte, isFile bool) { +func (db *Builder) unmarshalCounts(b []byte, isFile bool) { for len(b) > 0 { num, typ, n := wire.ConsumeTag(b) b = b[n:] diff --git a/internal/filedesc/desc_init.go b/internal/filedesc/desc_init.go index 0bd7d380..90357bc2 100644 --- a/internal/filedesc/desc_init.go +++ b/internal/filedesc/desc_init.go @@ -16,14 +16,14 @@ import ( // fileRaw is a data struct used when initializing a file descriptor from // a raw FileDescriptorProto. type fileRaw struct { - builder DescBuilder + builder Builder allEnums []Enum allMessages []Message allExtensions []Extension allServices []Service } -func newRawFile(db DescBuilder) *File { +func newRawFile(db Builder) *File { fd := &File{fileRaw: fileRaw{builder: db}} fd.initDecls(db.NumEnums, db.NumMessages, db.NumExtensions, db.NumServices) fd.unmarshalSeed(db.RawDescriptor) diff --git a/internal/filedesc/desc_lazy.go b/internal/filedesc/desc_lazy.go index 1e316764..a9f90024 100644 --- a/internal/filedesc/desc_lazy.go +++ b/internal/filedesc/desc_lazy.go @@ -678,7 +678,7 @@ func appendOptions(dst, src []byte) []byte { // // The type of message to unmarshal to is passed as a pointer since the // vars in descopts may not yet be populated at the time this function is called. -func (db *DescBuilder) optionsUnmarshaler(p *pref.ProtoMessage, b []byte) func() pref.ProtoMessage { +func (db *Builder) optionsUnmarshaler(p *pref.ProtoMessage, b []byte) func() pref.ProtoMessage { if b == nil { return nil } diff --git a/internal/filedesc/desc_test.go b/internal/filedesc/desc_test.go index ab349c7a..08930a2b 100644 --- a/internal/filedesc/desc_test.go +++ b/internal/filedesc/desc_test.go @@ -198,14 +198,14 @@ func TestFile(t *testing.T) { if err != nil { t.Fatalf("proto.Marshal() error: %v", err) } - fd2 := filedesc.DescBuilder{RawDescriptor: b}.Build().File + fd2 := filedesc.Builder{RawDescriptor: b}.Build().File tests := []struct { name string desc pref.FileDescriptor }{ {"protodesc.NewFile", fd1}, - {"filedesc.DescBuilder.Build", fd2}, + {"filedesc.Builder.Build", fd2}, } for _, tt := range tests { tt := tt diff --git a/internal/filetype/build.go b/internal/filetype/build.go index da46141b..3b1c97e5 100644 --- a/internal/filetype/build.go +++ b/internal/filetype/build.go @@ -21,7 +21,7 @@ import ( piface "google.golang.org/protobuf/runtime/protoiface" ) -// TypeBuilder constructs type descriptors from a raw file descriptor +// Builder constructs type descriptors from a raw file descriptor // and associated Go types for each enum and message declaration. // // @@ -55,9 +55,9 @@ import ( // The traversal starts at the root file descriptor and yields each direct // declaration within each node before traversing into sub-declarations // that children themselves may have. -type TypeBuilder struct { +type Builder struct { // File is the underlying file descriptor builder. - File fdesc.DescBuilder + File fdesc.Builder // GoTypes is a unique set of the Go types for all declarations and // dependencies. Each type is represented as a zero value of the Go type. @@ -116,7 +116,7 @@ type TypeBuilder struct { } } -func (tb TypeBuilder) Build() (out struct { +func (tb Builder) Build() (out struct { File pref.FileDescriptor // Enums is all enum types in "flattened ordering". diff --git a/internal/impl/legacy_file.go b/internal/impl/legacy_file.go index b1293c6b..bccaedef 100644 --- a/internal/impl/legacy_file.go +++ b/internal/impl/legacy_file.go @@ -56,7 +56,7 @@ func legacyLoadFileDesc(b []byte) protoreflect.FileDescriptor { panic(err) } - fd := filedesc.DescBuilder{ + fd := filedesc.Builder{ RawDescriptor: b2, FileRegistry: resolverOnly{protoregistry.GlobalFiles}, // do not register back to global registry }.Build().File diff --git a/runtime/protoimpl/impl.go b/runtime/protoimpl/impl.go index 43407b1e..775f9203 100644 --- a/runtime/protoimpl/impl.go +++ b/runtime/protoimpl/impl.go @@ -62,8 +62,8 @@ type ( // being a compilation failure (guaranteed by the Go specification). EnforceVersion uint - DescBuilder = filedesc.DescBuilder - TypeBuilder = filetype.TypeBuilder + DescBuilder = filedesc.Builder + TypeBuilder = filetype.Builder Pointer = impl.Pointer MessageInfo = impl.MessageInfo MessageState = impl.MessageState