فهرست منبع

protoc-gen-go: more standard import organization (#719)

Split imports into standard library and third-party imports. Decide
between the two based on the presence of a ".", which is the same
heuristic used by goimports.

Allow plugins to register packages to import, so gRPC imports don't sit
awkwardly in a separate import () block.
Damien Neil 7 سال پیش
والد
کامیت
7b180878bf
38فایلهای تغییر یافته به همراه109 افزوده شده و 62 حذف شده
  1. 2 1
      conformance/internal/conformance_proto/conformance.pb.go
  2. 2 1
      jsonpb/jsonpb_test_proto/more_test_objects.pb.go
  3. 2 1
      jsonpb/jsonpb_test_proto/test_objects.pb.go
  4. 2 1
      proto/proto3_proto/proto3.pb.go
  5. 2 1
      proto/test_proto/test.pb.go
  6. 2 1
      protoc-gen-go/descriptor/descriptor.pb.go
  7. 36 11
      protoc-gen-go/generator/generator.go
  8. 3 11
      protoc-gen-go/grpc/grpc.go
  9. 1 3
      protoc-gen-go/testdata/deprecated/deprecated.pb.go
  10. 2 1
      protoc-gen-go/testdata/extension_base/extension_base.pb.go
  11. 2 1
      protoc-gen-go/testdata/extension_extra/extension_extra.pb.go
  12. 2 1
      protoc-gen-go/testdata/extension_user/extension_user.pb.go
  13. 1 3
      protoc-gen-go/testdata/grpc/grpc.pb.go
  14. 2 1
      protoc-gen-go/testdata/import_public/a.pb.go
  15. 2 1
      protoc-gen-go/testdata/import_public/b.pb.go
  16. 2 1
      protoc-gen-go/testdata/import_public/sub/a.pb.go
  17. 2 1
      protoc-gen-go/testdata/import_public/sub/b.pb.go
  18. 2 1
      protoc-gen-go/testdata/imports/fmt/m.pb.go
  19. 2 1
      protoc-gen-go/testdata/imports/test_a_1/m1.pb.go
  20. 2 1
      protoc-gen-go/testdata/imports/test_a_1/m2.pb.go
  21. 2 1
      protoc-gen-go/testdata/imports/test_a_2/m3.pb.go
  22. 2 1
      protoc-gen-go/testdata/imports/test_a_2/m4.pb.go
  23. 2 1
      protoc-gen-go/testdata/imports/test_b_1/m1.pb.go
  24. 2 1
      protoc-gen-go/testdata/imports/test_b_1/m2.pb.go
  25. 2 1
      protoc-gen-go/testdata/imports/test_import_a1m1.pb.go
  26. 2 1
      protoc-gen-go/testdata/imports/test_import_a1m2.pb.go
  27. 2 1
      protoc-gen-go/testdata/imports/test_import_all.pb.go
  28. 2 1
      protoc-gen-go/testdata/multi/multi1.pb.go
  29. 2 1
      protoc-gen-go/testdata/multi/multi2.pb.go
  30. 2 1
      protoc-gen-go/testdata/multi/multi3.pb.go
  31. 2 1
      protoc-gen-go/testdata/my_test/test.pb.go
  32. 2 1
      protoc-gen-go/testdata/proto3/proto3.pb.go
  33. 2 1
      ptypes/any/any.pb.go
  34. 2 1
      ptypes/duration/duration.pb.go
  35. 2 1
      ptypes/empty/empty.pb.go
  36. 2 1
      ptypes/struct/struct.pb.go
  37. 2 1
      ptypes/timestamp/timestamp.pb.go
  38. 2 1
      ptypes/wrappers/wrappers.pb.go

+ 2 - 1
conformance/internal/conformance_proto/conformance.pb.go

@@ -5,6 +5,8 @@ package conformance
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	any "github.com/golang/protobuf/ptypes/any"
 	any "github.com/golang/protobuf/ptypes/any"
 	duration "github.com/golang/protobuf/ptypes/duration"
 	duration "github.com/golang/protobuf/ptypes/duration"
@@ -12,7 +14,6 @@ import (
 	timestamp "github.com/golang/protobuf/ptypes/timestamp"
 	timestamp "github.com/golang/protobuf/ptypes/timestamp"
 	wrappers "github.com/golang/protobuf/ptypes/wrappers"
 	wrappers "github.com/golang/protobuf/ptypes/wrappers"
 	field_mask "google.golang.org/genproto/protobuf/field_mask"
 	field_mask "google.golang.org/genproto/protobuf/field_mask"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
jsonpb/jsonpb_test_proto/more_test_objects.pb.go

@@ -5,8 +5,9 @@ package jsonpb
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
jsonpb/jsonpb_test_proto/test_objects.pb.go

@@ -5,13 +5,14 @@ package jsonpb
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	any "github.com/golang/protobuf/ptypes/any"
 	any "github.com/golang/protobuf/ptypes/any"
 	duration "github.com/golang/protobuf/ptypes/duration"
 	duration "github.com/golang/protobuf/ptypes/duration"
 	_struct "github.com/golang/protobuf/ptypes/struct"
 	_struct "github.com/golang/protobuf/ptypes/struct"
 	timestamp "github.com/golang/protobuf/ptypes/timestamp"
 	timestamp "github.com/golang/protobuf/ptypes/timestamp"
 	wrappers "github.com/golang/protobuf/ptypes/wrappers"
 	wrappers "github.com/golang/protobuf/ptypes/wrappers"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
proto/proto3_proto/proto3.pb.go

@@ -5,10 +5,11 @@ package proto3_proto
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	test_proto "github.com/golang/protobuf/proto/test_proto"
 	test_proto "github.com/golang/protobuf/proto/test_proto"
 	any "github.com/golang/protobuf/ptypes/any"
 	any "github.com/golang/protobuf/ptypes/any"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
proto/test_proto/test.pb.go

@@ -5,8 +5,9 @@ package test_proto
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/descriptor/descriptor.pb.go

@@ -5,8 +5,9 @@ package descriptor
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 36 - 11
protoc-gen-go/generator/generator.go

@@ -420,6 +420,7 @@ type Generator struct {
 	packageNames     map[GoImportPath]GoPackageName // Imported package names in the current file.
 	packageNames     map[GoImportPath]GoPackageName // Imported package names in the current file.
 	usedPackages     map[GoImportPath]bool          // Packages used in current file.
 	usedPackages     map[GoImportPath]bool          // Packages used in current file.
 	usedPackageNames map[GoPackageName]bool         // Package names used in the current file.
 	usedPackageNames map[GoPackageName]bool         // Package names used in the current file.
+	addedImports     map[GoImportPath]bool          // Additional imports to emit.
 	typeNameToObject map[string]Object              // Key is a fully-qualified name in input syntax.
 	typeNameToObject map[string]Object              // Key is a fully-qualified name in input syntax.
 	init             []string                       // Lines to emit in the init function.
 	init             []string                       // Lines to emit in the init function.
 	indent           string
 	indent           string
@@ -542,6 +543,13 @@ func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName {
 	return name
 	return name
 }
 }
 
 
+// AddImport adds a package to the generated file's import section.
+// It returns the name used for the package.
+func (g *Generator) AddImport(importPath GoImportPath) GoPackageName {
+	g.addedImports[importPath] = true
+	return g.GoPackageName(importPath)
+}
+
 var globalPackageNames = map[GoPackageName]bool{
 var globalPackageNames = map[GoPackageName]bool{
 	"fmt":   true,
 	"fmt":   true,
 	"math":  true,
 	"math":  true,
@@ -1109,6 +1117,7 @@ func (g *Generator) generate(file *FileDescriptor) {
 	g.usedPackages = make(map[GoImportPath]bool)
 	g.usedPackages = make(map[GoImportPath]bool)
 	g.packageNames = make(map[GoImportPath]GoPackageName)
 	g.packageNames = make(map[GoImportPath]GoPackageName)
 	g.usedPackageNames = make(map[GoPackageName]bool)
 	g.usedPackageNames = make(map[GoPackageName]bool)
+	g.addedImports = make(map[GoImportPath]bool)
 	for name := range globalPackageNames {
 	for name := range globalPackageNames {
 		g.usedPackageNames[name] = true
 		g.usedPackageNames[name] = true
 	}
 	}
@@ -1266,14 +1275,7 @@ func (g *Generator) weak(i int32) bool {
 
 
 // Generate the imports
 // Generate the imports
 func (g *Generator) generateImports() {
 func (g *Generator) generateImports() {
-	g.P("import (")
-	// We almost always need a proto import.  Rather than computing when we
-	// do, which is tricky when there's a plugin, just import it and
-	// reference it later. The same argument applies to the fmt and math packages.
-	g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
-	g.P(g.Pkg["fmt"] + ` "fmt"`)
-	g.P(g.Pkg["math"] + ` "math"`)
-	imports := make(map[GoImportPath]bool)
+	imports := make(map[GoImportPath]GoPackageName)
 	for i, s := range g.file.Dependency {
 	for i, s := range g.file.Dependency {
 		fd := g.fileByName(s)
 		fd := g.fileByName(s)
 		importPath := fd.importPath
 		importPath := fd.importPath
@@ -1286,10 +1288,9 @@ func (g *Generator) generateImports() {
 			continue
 			continue
 		}
 		}
 		// Do not import a package twice.
 		// Do not import a package twice.
-		if imports[importPath] {
+		if _, ok := imports[importPath]; ok {
 			continue
 			continue
 		}
 		}
-		imports[importPath] = true
 		// We need to import all the dependencies, even if we don't reference them,
 		// We need to import all the dependencies, even if we don't reference them,
 		// because other code and tools depend on having the full transitive closure
 		// because other code and tools depend on having the full transitive closure
 		// of protocol buffer types in the binary.
 		// of protocol buffer types in the binary.
@@ -1297,7 +1298,31 @@ func (g *Generator) generateImports() {
 		if _, ok := g.usedPackages[importPath]; !ok {
 		if _, ok := g.usedPackages[importPath]; !ok {
 			packageName = "_"
 			packageName = "_"
 		}
 		}
-		g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
+		imports[importPath] = packageName
+	}
+	for importPath := range g.addedImports {
+		imports[importPath] = g.GoPackageName(importPath)
+	}
+	g.P("import (")
+	// Standard library imports.
+	g.P(g.Pkg["fmt"] + ` "fmt"`)
+	g.P(g.Pkg["math"] + ` "math"`)
+	for importPath, packageName := range imports {
+		if !strings.Contains(string(importPath), ".") {
+			g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
+		}
+	}
+	g.P()
+	// Third-party imports.
+	//
+	// We almost always need a proto import.  Rather than computing when we
+	// do, which is tricky when there's a plugin, just import it and
+	// reference it later. The same argument applies to the fmt and math packages.
+	g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
+	for importPath, packageName := range imports {
+		if strings.Contains(string(importPath), ".") {
+			g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
+		}
 	}
 	}
 	g.P(")")
 	g.P(")")
 	g.P()
 	g.P()

+ 3 - 11
protoc-gen-go/grpc/grpc.go

@@ -36,7 +36,6 @@ package grpc
 
 
 import (
 import (
 	"fmt"
 	"fmt"
-	"path"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
@@ -83,8 +82,6 @@ var (
 // Init initializes the plugin.
 // Init initializes the plugin.
 func (g *grpc) Init(gen *generator.Generator) {
 func (g *grpc) Init(gen *generator.Generator) {
 	g.gen = gen
 	g.gen = gen
-	contextPkg = generator.RegisterUniquePackageName("context", nil)
-	grpcPkg = generator.RegisterUniquePackageName("grpc", nil)
 }
 }
 
 
 // Given a type name defined in a .proto, return its object.
 // Given a type name defined in a .proto, return its object.
@@ -108,6 +105,9 @@ func (g *grpc) Generate(file *generator.FileDescriptor) {
 		return
 		return
 	}
 	}
 
 
+	contextPkg = string(g.gen.AddImport(contextPkgPath))
+	grpcPkg = string(g.gen.AddImport(grpcPkgPath))
+
 	g.P("// Reference imports to suppress errors if they are not otherwise used.")
 	g.P("// Reference imports to suppress errors if they are not otherwise used.")
 	g.P("var _ ", contextPkg, ".Context")
 	g.P("var _ ", contextPkg, ".Context")
 	g.P("var _ ", grpcPkg, ".ClientConn")
 	g.P("var _ ", grpcPkg, ".ClientConn")
@@ -126,14 +126,6 @@ func (g *grpc) Generate(file *generator.FileDescriptor) {
 
 
 // GenerateImports generates the import declaration for this file.
 // GenerateImports generates the import declaration for this file.
 func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
 func (g *grpc) GenerateImports(file *generator.FileDescriptor) {
-	if len(file.FileDescriptorProto.Service) == 0 {
-		return
-	}
-	g.P("import (")
-	g.P(contextPkg, " ", generator.GoImportPath(path.Join(string(g.gen.ImportPrefix), contextPkgPath)))
-	g.P(grpcPkg, " ", generator.GoImportPath(path.Join(string(g.gen.ImportPrefix), grpcPkgPath)))
-	g.P(")")
-	g.P()
 }
 }
 
 
 // reservedClientName records whether a client name is reserved on the client side.
 // reservedClientName records whether a client name is reserved on the client side.

+ 1 - 3
protoc-gen-go/testdata/deprecated/deprecated.pb.go

@@ -7,11 +7,9 @@ package deprecated
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
-)
 
 
-import (
+	proto "github.com/golang/protobuf/proto"
 	context "golang.org/x/net/context"
 	context "golang.org/x/net/context"
 	grpc "google.golang.org/grpc"
 	grpc "google.golang.org/grpc"
 )
 )

+ 2 - 1
protoc-gen-go/testdata/extension_base/extension_base.pb.go

@@ -5,8 +5,9 @@ package extension_base
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/extension_extra/extension_extra.pb.go

@@ -5,8 +5,9 @@ package extension_extra
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/extension_user/extension_user.pb.go

@@ -5,10 +5,11 @@ package extension_user
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	extension_base "github.com/golang/protobuf/protoc-gen-go/testdata/extension_base"
 	extension_base "github.com/golang/protobuf/protoc-gen-go/testdata/extension_base"
 	extension_extra "github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra"
 	extension_extra "github.com/golang/protobuf/protoc-gen-go/testdata/extension_extra"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 1 - 3
protoc-gen-go/testdata/grpc/grpc.pb.go

@@ -5,11 +5,9 @@ package testing
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
-)
 
 
-import (
+	proto "github.com/golang/protobuf/proto"
 	context "golang.org/x/net/context"
 	context "golang.org/x/net/context"
 	grpc "google.golang.org/grpc"
 	grpc "google.golang.org/grpc"
 )
 )

+ 2 - 1
protoc-gen-go/testdata/import_public/a.pb.go

@@ -5,9 +5,10 @@ package import_public
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
 	sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/import_public/b.pb.go

@@ -5,9 +5,10 @@ package import_public
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
 	sub "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/import_public/sub/a.pb.go

@@ -5,8 +5,9 @@ package sub
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/import_public/sub/b.pb.go

@@ -5,8 +5,9 @@ package sub
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/fmt/m.pb.go

@@ -5,8 +5,9 @@ package fmt
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_a_1/m1.pb.go

@@ -5,8 +5,9 @@ package test_a_1
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_a_1/m2.pb.go

@@ -5,8 +5,9 @@ package test_a_1
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_a_2/m3.pb.go

@@ -5,8 +5,9 @@ package test_a_2
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_a_2/m4.pb.go

@@ -5,8 +5,9 @@ package test_a_2
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_b_1/m1.pb.go

@@ -5,8 +5,9 @@ package beta
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_b_1/m2.pb.go

@@ -5,8 +5,9 @@ package beta
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_import_a1m1.pb.go

@@ -5,9 +5,10 @@ package imports
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_import_a1m2.pb.go

@@ -5,9 +5,10 @@ package imports
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/imports/test_import_all.pb.go

@@ -5,12 +5,13 @@ package imports
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	fmt1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/fmt"
 	fmt1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/fmt"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
 	test_a_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_1"
 	test_a_2 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_2"
 	test_a_2 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_a_2"
 	test_b_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_b_1"
 	test_b_1 "github.com/golang/protobuf/protoc-gen-go/testdata/imports/test_b_1"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/multi/multi1.pb.go

@@ -5,8 +5,9 @@ package multitest
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/multi/multi2.pb.go

@@ -5,8 +5,9 @@ package multitest
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/multi/multi3.pb.go

@@ -5,8 +5,9 @@ package multitest
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/my_test/test.pb.go

@@ -7,9 +7,10 @@ package test
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
+	math "math"
+
 	proto "github.com/golang/protobuf/proto"
 	proto "github.com/golang/protobuf/proto"
 	_ "github.com/golang/protobuf/protoc-gen-go/testdata/multi"
 	_ "github.com/golang/protobuf/protoc-gen-go/testdata/multi"
-	math "math"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
protoc-gen-go/testdata/proto3/proto3.pb.go

@@ -5,8 +5,9 @@ package proto3
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/any/any.pb.go

@@ -5,8 +5,9 @@ package any
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/duration/duration.pb.go

@@ -5,8 +5,9 @@ package duration
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/empty/empty.pb.go

@@ -5,8 +5,9 @@ package empty
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/struct/struct.pb.go

@@ -5,8 +5,9 @@ package structpb
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/timestamp/timestamp.pb.go

@@ -5,8 +5,9 @@ package timestamp
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.

+ 2 - 1
ptypes/wrappers/wrappers.pb.go

@@ -5,8 +5,9 @@ package wrappers
 
 
 import (
 import (
 	fmt "fmt"
 	fmt "fmt"
-	proto "github.com/golang/protobuf/proto"
 	math "math"
 	math "math"
+
+	proto "github.com/golang/protobuf/proto"
 )
 )
 
 
 // Reference imports to suppress errors if they are not otherwise used.
 // Reference imports to suppress errors if they are not otherwise used.