Documentation ¶
Overview ¶
Package importmgr provides the ImportMgr type for tracking a go file's imports when generating code by manipulating the Go AST.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ImportMgr ¶
type ImportMgr struct {
// contains filtered or unexported fields
}
ImportMgr maintains state on the imports for a file.
func NewImportMgr ¶
NewImportMgr constructs an empty ImportMgr for the package-set provided.
func (*ImportMgr) GetPkgIdent ¶
GetPkgIdent adds an appropriate import for the import if necessary and returns an *ast.Ident referencing that package. The return value should only be used once within an AST, as the source location fields within an Ident (or any ast node) must be unique.
func (*ImportMgr) GetPkgIdentWithLoadFallback ¶
func (i *ImportMgr) GetPkgIdentWithLoadFallback( ctx context.Context, path string) (*ast.Ident, error)
GetPkgIdentWithLoadFallback calls GetPkgIdent, and if it returns nil, uses golang.org/x/tools/packages.Load to lookup the package name.
func (*ImportMgr) ImportFile ¶
ImportFile imports the existing imports/import-objects from an existing ast.File.
func (*ImportMgr) Specs ¶
func (i *ImportMgr) Specs() []*ast.ImportSpec
Specs returns a slice of *ast.ImportSpecs appropriate for insertion into an ast.File.Imports.