pkgwalk

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package buildutil provides utilities related to the go/build package in the standard library.

All I/O is done via the build.Context file system interface, which must be concurrency-safe.

Index

Constants

This section is empty.

Variables

View Source
var ObjKindName = []string{"none", "package", "packagex", "import",
	"type", "interface", "struct",
	"const", "var", "field",
	"func", "method",
	"label", "builtin", "nil", "implicit", "unknown"}

Functions

func AllPackages

func AllPackages(ctxt *build.Context) []string

AllPackages returns the package path of each Go package in any source directory of the specified build context (e.g. $GOROOT or an element of $GOPATH). Errors are ignored. The results are sorted. All package paths are canonical, and thus may contain "/vendor/".

The result may include import paths for directories that contain no *.go files, such as "archive" (in $GOROOT/src).

All I/O is done via the build.Context file system interface, which must be concurrency-safe.

func ExpandPatterns

func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool

ExpandPatterns returns the set of packages matched by patterns, which may have the following forms:

golang.org/x/tools/cmd/guru     # a single package
golang.org/x/tools/...          # all packages beneath dir
...                             # the entire workspace.

Order is significant: a pattern preceded by '-' removes matching packages from the set. For example, these patterns match all encoding packages except encoding/xml:

encoding/... -encoding/xml

func ForEachPackage

func ForEachPackage(ctxt *build.Context, found func(importPath string, err error))

ForEachPackage calls the found function with the package path of each Go package it finds in any source directory of the specified build context (e.g. $GOROOT or an element of $GOPATH). All package paths are canonical, and thus may contain "/vendor/".

If the package directory exists but could not be read, the second argument to the found function provides the error.

All I/O is done via the build.Context file system interface, which must be concurrency-safe.

func ImportPackage

func ImportPackage(w *PkgWalker, pkgPath string, conf *PkgConfig) (*types.Package, error)

func IsSameObject

func IsSameObject(a, b types.Object) bool

func IsSamePkg

func IsSamePkg(a, b *types.Package) bool

func ReadDir

func ReadDir(ctxt *build.Context, path string) ([]os.FileInfo, error)

Types

type FileCursor

type FileCursor struct {
	// contains filtered or unexported fields
}

type Importer

type Importer struct {
	// contains filtered or unexported fields
}

func (*Importer) Import

func (im *Importer) Import(name string) (pkg *types.Package, err error)

type ObjKind

type ObjKind int
const (
	ObjNone ObjKind = iota
	ObjPackage
	ObjPackageX
	ObjPkgName //import
	ObjTypeName
	ObjInterface
	ObjStruct
	ObjConst
	ObjVar
	ObjField
	ObjFunc
	ObjMethod
	ObjLabel
	ObjBuiltin
	ObjNil
	ObjImplicit
	ObjUnknown
	ObjComment
)

func ParserObjectKind

func ParserObjectKind(ident *ast.Ident, obj types.Object, conf *PkgConfig) (ObjKind, error)

func (ObjKind) String

func (k ObjKind) String() string

type ObjList

type ObjList struct {
	Kind        ObjKind
	Ident       *ast.Ident
	Obj         types.Object
	List        []int
	IsTestFunc  bool
	IsAnonymous bool
}

func LookupObjList

func LookupObjList(w *PkgWalker, pkg *types.Package, conf *PkgConfig) []*ObjList

func NewObjList

func NewObjList(kind ObjKind, ident *ast.Ident, obj types.Object) *ObjList

func (*ObjList) String

func (o *ObjList) String() string

type PkgConfig

type PkgConfig struct {
	IgnoreFuncBodies bool
	AllowBinary      bool
	WithTestFiles    bool
	Cursor           *FileCursor
	Pkg              *types.Package
	XPkg             *types.Package
	Info             *types.Info
	XInfo            *types.Info
	Files            []*ast.File
	TestFiles        []*ast.File
	XTestFiles       []*ast.File
	Dir              string
}

func DefaultPkgConfig

func DefaultPkgConfig() *PkgConfig

type PkgWalker

type PkgWalker struct {
	FileSet *token.FileSet
	Context *build.Context
	// contains filtered or unexported fields
}

func NewPkgWalker

func NewPkgWalker(context *build.Context) *PkgWalker

func (*PkgWalker) CheckIsImport

func (w *PkgWalker) CheckIsImport(cursor *FileCursor) *ast.ImportSpec

func (*PkgWalker) FindDeclForPos

func (w *PkgWalker) FindDeclForPos(p token.Pos) (*ast.File, ast.Decl)

func (*PkgWalker) FindImportEndPos

func (w *PkgWalker) FindImportEndPos(ast *ast.File) token.Pos

func (*PkgWalker) FindImportName

func (w *PkgWalker) FindImportName(ast *ast.File, path string) string

func (*PkgWalker) Import

func (w *PkgWalker) Import(parentDir string, name string, conf *PkgConfig) (pkg *types.Package, err error)

func (*PkgWalker) LookupCursor

func (w *PkgWalker) LookupCursor(pkg *types.Package, conf *PkgConfig, cursor *FileCursor)

func (*PkgWalker) LookupIdentComment

func (w *PkgWalker) LookupIdentComment(value token.Pos) *ast.CommentGroup

func (*PkgWalker) LookupImport

func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec)

func (*PkgWalker) LookupMethodRecvObject

func (w *PkgWalker) LookupMethodRecvObject(fn *types.Func) types.Object

func (*PkgWalker) LookupObjects

func (w *PkgWalker) LookupObjects(conf *PkgConfig, cursor *FileCursor)

func (*PkgWalker) LookupStructFromField

func (w *PkgWalker) LookupStructFromField(info *types.Info, cursorPkg *types.Package, cursorObj types.Object, cursorPos token.Pos) types.Object

type Rename

type Rename struct {
	Old string
	New string
}

Jump to

Keyboard shortcuts

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