+ // Prepare the import block
+ impDecl := &ast.GenDecl{Tok: token.IMPORT, TokPos: pos, Lparen: pos, Rparen: pos}
+ for i, importPath := range importPaths {
+ var name *ast.Ident
+ if importPath.Name == "_" || strings.Contains(importPath.Path, ".") {
+ name = &ast.Ident{Name: importPath.Name, NamePos: pos}
+ }
+ value := strconv.Quote(importPath.Path)
+ if i < len(importPaths)-1 {
+ if getImportClass(importPath.Path) != getImportClass(importPaths[i+1].Path) {
+ value += "\n"
+ }
+ }
+ impDecl.Specs = append(impDecl.Specs, &ast.ImportSpec{
+ Name: name,
+ Path: &ast.BasicLit{Kind: token.STRING, Value: value, ValuePos: pos},
+ EndPos: pos,
+ })
+ }
+
+ file.Decls = append([]ast.Decl{impDecl}, file.Decls...)
+ }
+ // Reformat source code
+ var out bytes.Buffer
+ cfg := &printer.Config{
+ Mode: printer.TabIndent | printer.UseSpaces,
+ Tabwidth: 8,