// AddImport adds the import path to the file f, if absent. func AddImport(fset *token.FileSet, f *ast.File, path string) (added bool) { … } // AddNamedImport adds the import with the given name and path to the file f, if absent. // If name is not empty, it is used to rename the import. // // For example, calling // // AddNamedImport(fset, f, "pathpkg", "path") // // adds // // import pathpkg "path" func AddNamedImport(fset *token.FileSet, f *ast.File, name, path string) (added bool) { … } func isThirdParty(importPath string) bool { … } // DeleteImport deletes the import path from the file f, if present. // If there are duplicate import declarations, all matching ones are deleted. func DeleteImport(fset *token.FileSet, f *ast.File, path string) (deleted bool) { … } // DeleteNamedImport deletes the import with the given name and path from the file f, if present. // If there are duplicate import declarations, all matching ones are deleted. func DeleteNamedImport(fset *token.FileSet, f *ast.File, name, path string) (deleted bool) { … } // RewriteImport rewrites any import of path oldPath to path newPath. func RewriteImport(fset *token.FileSet, f *ast.File, oldPath, newPath string) (rewrote bool) { … } // UsesImport reports whether a given import is used. func UsesImport(f *ast.File, path string) (used bool) { … } type visitFn … func (fn visitFn) Visit(node ast.Node) ast.Visitor { … } // imports reports whether f has an import with the specified name and path. func imports(f *ast.File, name, path string) bool { … } // importSpec returns the import spec if f imports path, // or nil otherwise. func importSpec(f *ast.File, path string) *ast.ImportSpec { … } // importName returns the name of s, // or "" if the import is not named. func importName(s *ast.ImportSpec) string { … } // importPath returns the unquoted import path of s, // or "" if the path is not properly quoted. func importPath(s *ast.ImportSpec) string { … } // declImports reports whether gen contains an import of path. func declImports(gen *ast.GenDecl, path string) bool { … } // matchLen returns the length of the longest path segment prefix shared by x and y. func matchLen(x, y string) int { … } // isTopName returns true if n is a top-level unresolved identifier with the given name. func isTopName(n ast.Expr, name string) bool { … } // Imports returns the file imports grouped by paragraph. func Imports(fset *token.FileSet, f *ast.File) [][]*ast.ImportSpec { … }