package typeindex
import "golang.org/x/tools/internal/typesinternal/typeindex"
Package typeindex provides an Index of type information for a package, allowing efficient lookup of, say, whether a given symbol is referenced and, if so, where from; or of the cursor.Cursor for the declaration of a particular types.Object symbol.
Index ¶
- type Index
- func New(inspect *inspector.Inspector, pkg *types.Package, info *types.Info) *Index
- func (ix *Index) Calls(callee types.Object) iter.Seq[cursor.Cursor]
- func (ix *Index) Def(obj types.Object) (cursor.Cursor, bool)
- func (ix *Index) Object(path, name string) types.Object
- func (ix *Index) Package(path string) *types.Package
- func (ix *Index) Selection(path, typename, name string) types.Object
- func (ix *Index) Used(objs ...types.Object) bool
- func (ix *Index) Uses(obj types.Object) iter.Seq[cursor.Cursor]
Types ¶
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
An Index holds an index mapping types.Object symbols to their syntax. In effect, it is the inverse of types.Info.
func New ¶
New constructs an Index for the package of type-annotated syntax
TODO(adonovan): accept a FileSet too? We regret not requiring one in inspector.New.
func (*Index) Calls ¶
Calls returns the sequence of cursors for *ast.CallExpr nodes that call the specified callee, as defined by typeutil.Callee. If callee is nil, the sequence is empty.
func (*Index) Def ¶
Def returns the Cursor of the *ast.Ident in this package that declares the specified object, if any.
func (*Index) Object ¶
Object returns the package-level symbol name within the package of the specified path, or nil if the package or symbol does not exist or is not visible from this package.
func (*Index) Package ¶
Package returns the package of the specified path, or nil if it is not referenced from this package.
func (*Index) Selection ¶
Selection returns the named method or field belonging to the package-level type returned by Object(path, typename).
func (*Index) Used ¶
Used reports whether any of the specified objects are used, in other words, obj != nil && Uses(obj) is non-empty for some obj in objs.
(This treatment of nil allows Used to be called directly on the result of Index.Object so that analyzers can conveniently skip packages that don't use a symbol of interest.)
func (*Index) Uses ¶
Uses returns the sequence of Cursors of [*ast.Ident]s in this package that refer to obj. If obj is nil, the sequence is empty.
Source Files ¶
typeindex.go
- Version
- v0.32.0 (latest)
- Published
- Apr 8, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 32 minutes ago –
Tools for package owners.