pkginfo

package
v1.27.6 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Name     string                 // file name ("foo.go")
	Pkg      *Package               // package it belongs to
	FSPath   paths.FS               // where the file lives on disk
	Imports  map[paths.Pkg]ast.Node // imports in the file, keyed by import path pointed at the import spec
	TestFile bool                   // whether the file is a test file
	// contains filtered or unexported fields
}

func (*File) AST

func (f *File) AST() *ast.File

AST returns the parsed AST for this file.

func (*File) ASTInspector

func (f *File) ASTInspector() *inspector.Inspector

ASTInspector returns an AST inspector that's optimized for finding nodes of particular types. See inspector.Inspector for more information.

func (*File) Contents

func (f *File) Contents() []byte

Contents returns the full file contents.

func (*File) GoString

func (f *File) GoString() string

func (*File) Names

func (f *File) Names() *FileNames

Names returns the computed file-level names.

func (*File) Token

func (f *File) Token() *token.File

type FileNames

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

FileNames contains name resolution results for a single file.

func (*FileNames) GoString

func (n *FileNames) GoString() string

func (*FileNames) ResolvePkgLevelRef

func (f *FileNames) ResolvePkgLevelRef(expr ast.Expr) (name QualifiedName, ok bool)

ResolvePkgLevelRef resolves the node to the package-level reference it refers to. Expr must be either *ast.Ident or *ast.SelectorExpr. If it doesn't refer to a package-level reference it returns ok == false.

func (*FileNames) ResolvePkgPath

func (f *FileNames) ResolvePkgPath(cause token.Pos, name string) (pkgPath paths.Pkg, ok bool)

ResolvePkgPath resolves the package path a given identifier name resolves to.

type Loader

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

A Loader provides lazy loading of package information.

func New

func New(c *parsectx.Context) *Loader

New creates a new Loader.

func (*Loader) LoadPkg

func (l *Loader) LoadPkg(cause token.Pos, pkgPath paths.Pkg) (pkg *Package, ok bool)

LoadPkg loads a package. If the package contains no Go files to build, it returns (nil, false).

func (*Loader) MainModule

func (l *Loader) MainModule() *Module

MainModule returns the parsed main module.

func (*Loader) MustLoadPkg

func (l *Loader) MustLoadPkg(cause token.Pos, pkgPath paths.Pkg) (pkg *Package)

MustLoadPkg loads a package. If the package contains no Go files, it bails out.

func (*Loader) RuntimeModule added in v1.16.0

func (l *Loader) RuntimeModule() *Module

RuntimeModule returns the parsed runtime module.

type Module

type Module struct {
	RootDir paths.FS  // the dir containing go.mod
	Path    paths.Mod // module path
	Version string    // module version
	// contains filtered or unexported fields
}

Module describes a Go module.

func (*Module) FSPathToPkg

func (m *Module) FSPathToPkg(pkgPath paths.Pkg) (path paths.FS, ok bool)

FSPathToPkg computes the filesystem path to the given package. The package must lexically live within the given module, otherwise it reports ok == false.

type Package

type Package struct {
	AST        *ast.Package
	Name       string
	Doc        string
	ImportPath paths.Pkg
	FSPath     paths.FS
	Files      []*File
	Imports    map[paths.Pkg]ast.Node // union of all imports from files
	// contains filtered or unexported fields
}

func (*Package) GoString

func (p *Package) GoString() string

func (*Package) Names

func (p *Package) Names() *PkgNames

Names returns the computed package-level names.

type PkgDeclInfo

type PkgDeclInfo struct {
	Name string
	File *File
	Pos  token.Pos
	Doc  string

	// Type describes what type of declaration this is.
	// It's one of CONST, TYPE, VAR, or FUNC.
	Type token.Token

	// Spec is the spec for this declaration and GenDecl the declaration block
	// it belongs to. They are set only when Type != FUNC.
	Spec    ast.Spec
	GenDecl *ast.GenDecl

	// Func is the function declaration, if Type == FUNC.
	Func *ast.FuncDecl // for Type == FUNC
	// Recv is the receiver type, if Type == FUNC and the function is a method.
	Recv *PkgDeclInfo
}

PkgDeclInfo provides metadata for a package-level declaration.

func (*PkgDeclInfo) QualifiedName added in v1.16.0

func (i *PkgDeclInfo) QualifiedName() QualifiedName

type PkgNames

type PkgNames struct {
	// PkgDecls contains package-level declarations, keyed by name.
	PkgDecls map[string]*PkgDeclInfo

	// Funcs are all the func declarations.
	Funcs []*PkgDeclInfo
	// contains filtered or unexported fields
}

PkgNames contains name information that's package-global.

func (*PkgNames) FuncDecl

func (n *PkgNames) FuncDecl(name string) option.Option[*ast.FuncDecl]

func (*PkgNames) GoString

func (n *PkgNames) GoString() string

type QualifiedName

type QualifiedName struct {
	PkgPath paths.Pkg
	Name    string
}

A QualifiedName is the combination of a package path and a package-level name. It can be used to uniquely reference a package-level declaration.

func Q

func Q(pkgPath paths.Pkg, name string) QualifiedName

Q is a helper function to construct a QualifiedName.

func (QualifiedName) NaiveDisplayName

func (q QualifiedName) NaiveDisplayName() string

NaiveDisplayName returns the name as "pkgname.Name" by assuming the package name is equal to the last path component.

Jump to

Keyboard shortcuts

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