importmgr

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

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

func NewImportMgr(deps *goastpkg.Package) *ImportMgr

NewImportMgr constructs an empty ImportMgr for the package-set provided.

func (*ImportMgr) GetPkgIdent

func (i *ImportMgr) GetPkgIdent(path string) *ast.Ident

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

func (i *ImportMgr) ImportFile(file *ast.File) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL