Просмотр исходного кода

protoc-gen-go: put all imports in one section (#720)

Keep plugin imports and non-plugin imports in the same section, but
don't try to split stdlib and non-stdlib imports into different
sections. Consistent with using astutil to insert all imports from a
blank slate.

Change-Id: Iede57a803c4a20baa1f903504df89f02b8b951c0
Cherry-Pick: github.com/golang/protobuf@7011d38ac0d201eeddff4a4085a657c3da322d75
Original-Author: Damien Neil <neild@users.noreply.github.com>
Reviewed-on: https://go-review.googlesource.com/c/151421
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai 7 лет назад
Родитель
Сommit
6aa1dc7623
1 измененных файлов с 4 добавлено и 15 удалено
  1. 4 15
      protoc-gen-go/generator/generator.go

+ 4 - 15
protoc-gen-go/generator/generator.go

@@ -1304,26 +1304,15 @@ func (g *Generator) generateImports() {
 	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("import (")
+	g.P(g.Pkg["fmt"] + ` "fmt"`)
+	g.P(g.Pkg["math"] + ` "math"`)
 	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(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
 	}
 	g.P(")")
 	g.P()