cmd/protog-gen-go: rename File to fileInfo
In preparation for factoring out the protoc-gen-go implementation into an
importable package, change exported names (just File) to unexported ones.
Change-Id: I2c65913332447e75c0dc7622a56f5dc09ff90116
Reviewed-on: https://go-review.googlesource.com/137017
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/main.go b/cmd/protoc-gen-go/main.go
index 893f3ed..f10b7fc 100644
--- a/cmd/protoc-gen-go/main.go
+++ b/cmd/protoc-gen-go/main.go
@@ -50,7 +50,7 @@
})
}
-type File struct {
+type fileInfo struct {
*protogen.File
locationMap map[string][]*descpb.SourceCodeInfo_Location
descriptorVar string // var containing the gzipped FileDescriptorProto
@@ -60,7 +60,7 @@
}
func genFile(gen *protogen.Plugin, file *protogen.File) {
- f := &File{
+ f := &fileInfo{
File: file,
locationMap: make(map[string][]*descpb.SourceCodeInfo_Location),
}
@@ -151,7 +151,7 @@
}
}
-func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, imp protoreflect.FileImport) {
+func genImport(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, imp protoreflect.FileImport) {
impFile, ok := gen.FileByName(imp.Path())
if !ok {
return
@@ -193,7 +193,7 @@
}
}
-func genFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File) {
+func genFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
// Trim the source_code_info from the descriptor.
// Marshal and gzip it.
descProto := proto.Clone(f.Proto).(*descpb.FileDescriptorProto)
@@ -231,7 +231,7 @@
g.P()
}
-func genEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, enum *protogen.Enum) {
+func genEnum(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, enum *protogen.Enum) {
genComment(g, f, enum.Path)
g.P("type ", enum.GoIdent, " int32",
deprecationComment(enumOptions(gen, enum).GetDeprecated()))
@@ -320,7 +320,7 @@
return string(fdesc.Package()) + "." + enum.GoIdent.GoName
}
-func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, message *protogen.Message) {
+func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message) {
if message.Desc.IsMapEntry() {
return
}
@@ -743,7 +743,7 @@
return string(field.Desc.Name()) + ",omitempty"
}
-func genExtension(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, extension *protogen.Extension) {
+func genExtension(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, extension *protogen.Extension) {
// Special case for proto2 message sets: If this extension is extending
// proto2.bridge.MessageSet, and its final name component is "message_set_extension",
// then drop that last component.
@@ -782,7 +782,7 @@
}
// extensionVar returns the var holding the ExtensionDesc for an extension.
-func extensionVar(f *File, extension *protogen.Extension) protogen.GoIdent {
+func extensionVar(f *fileInfo, extension *protogen.Extension) protogen.GoIdent {
name := "E_"
if extension.ParentMessage != nil {
name += extension.ParentMessage.GoIdent.GoName + "_"
@@ -796,7 +796,7 @@
// genInitFunction generates an init function that registers the types in the
// generated file with the proto package.
-func genInitFunction(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File) {
+func genInitFunction(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo) {
if len(f.allMessages) == 0 && len(f.allEnums) == 0 && len(f.allExtensions) == 0 {
return
}
@@ -852,7 +852,7 @@
g.P()
}
-func genRegisterExtension(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, extension *protogen.Extension) {
+func genRegisterExtension(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, extension *protogen.Extension) {
g.P(protogen.GoIdent{
GoImportPath: protoPackage,
GoName: "RegisterExtension",
@@ -869,7 +869,7 @@
}
}
-func genComment(g *protogen.GeneratedFile, f *File, path []int32) (hasComment bool) {
+func genComment(g *protogen.GeneratedFile, f *fileInfo, path []int32) (hasComment bool) {
for _, loc := range f.locationMap[pathKey(path)] {
if loc.LeadingComments == nil {
continue
diff --git a/cmd/protoc-gen-go/oneof.go b/cmd/protoc-gen-go/oneof.go
index dbb91a2..13a1aee 100644
--- a/cmd/protoc-gen-go/oneof.go
+++ b/cmd/protoc-gen-go/oneof.go
@@ -10,7 +10,7 @@
)
// genOneofField generates the struct field for a oneof.
-func genOneofField(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, message *protogen.Message, oneof *protogen.Oneof) {
+func genOneofField(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message, oneof *protogen.Oneof) {
if genComment(g, f, oneof.Path) {
g.P("//")
}
@@ -26,7 +26,7 @@
//
// 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 *File, message *protogen.Message, oneof *protogen.Oneof) {
+func genOneofTypes(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message, oneof *protogen.Oneof) {
ifName := oneofInterfaceName(message, oneof)
g.P("type ", ifName, " interface {")
g.P(ifName, "()")
@@ -60,7 +60,7 @@
}
// genOneofFuncs generates the XXX_OneofFuncs method for a message.
-func genOneofFuncs(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, message *protogen.Message) {
+func genOneofFuncs(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileInfo, message *protogen.Message) {
protoMessage := g.QualifiedGoIdent(protogen.GoIdent{
GoImportPath: protoPackage,
GoName: "Message",