names

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application added in v1.3.0

type Application map[*est.Package]*Resolution

Application presents all resolved names throughout the Application

func (Application) PackageLevelRef added in v1.3.0

func (a Application) PackageLevelRef(inFile *est.File, node ast.Node) (pkgPath string, objName string, indexArguments []ast.Expr)

PackageLevelRef resolves the given ast.Node to a package path, object name and index arguments. In the case it fails to resolve, it will return ("", "", nil).

If the given node is a index or index list, then the index arguments will be extracted. These could either be type arguments, or map access arguments.

If the given node is: - an ident, then it is resolved to a package level deceleration in the same file as the ident. - a selector, then it is resolved to an exported ident from the selected package. - any other node will result in nothing being returned

Note:

  • This function accounts for scoping and variable shadowing. (i.e. it will not mistake a variable "foo" in a function for the package imported as "foo").
  • This function does not validate the existence of the objName for objects referenced in other packages. As such it can return references for objects in Go Modules as long as those packages are marked to be tracked by the parser.

type File

type File struct {
	PathToName map[string]string    // path -> local name
	NameToPath map[string]string    // local name -> path
	Idents     map[*ast.Ident]*Name // ident -> resolved
	Calls      []*ast.CallExpr
}

File provides file-level name resolution results.

type Name

type Name struct {
	Package    bool   // package symbol
	Local      bool   // locally defined symbol
	ImportPath string // non-zero indicates it resolves to the package with the given import path
}

Name provides metadata for a single identifier.

type PkgDecl

type PkgDecl struct {
	Name string
	File *est.File
	Pos  token.Pos
	Type token.Token   // CONST, TYPE, VAR, FUNC
	Func *ast.FuncDecl // for Type == FUNC
	Spec ast.Spec      // for other types
	Doc  string
}

PkgDecl provides metadata for a package-level declaration.

type Resolution

type Resolution struct {
	Decls map[string]*PkgDecl // package-level declarations, keyed by name
	Files map[*est.File]*File
}

Resolution represents the name resolution results.

func Resolve

func Resolve(fset *token.FileSet, track TrackedPackages, pkg *est.Package) (*Resolution, error)

Resolve resolves information about the names (idents) in the given package. The reported error is of type scanner.ErrorList if non-nil.

type TrackedPackages

type TrackedPackages map[string]string

TrackedPackages defines the set of packages to track, defined as a map from import path to package name.

It is used to allow Resolve to efficiently determine the name of a package given its import path, as one otherwise needs to parse the package source to find it.

Jump to

Keyboard shortcuts

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