methodsets

package
v0.0.0-...-b73abcb Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package methodsets defines an incremental, serializable index of method-set information that allows efficient 'implements' queries across packages of the workspace without using the type checker.

This package provides only the "global" (all workspace) search; the "local" search within a given package uses a different implementation based on type-checker data structures for a single package plus variants; see ../implementation.go. The local algorithm is more precise as it tests function-local types too.

A global index of function-local types is challenging since they may reference other local types, for which we would need to invent stable names, an unsolved problem described in passing in Go issue 57497. The global algorithm also does not index anonymous interface types, even outside function bodies.

Consequently, global results are not symmetric: applying the operation twice may not get you back where you started.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsurePointer

func EnsurePointer(T types.Type) types.Type

EnsurePointer wraps T in a types.Pointer if T is a named, non-interface type. This is useful to make sure you consider a named type's full method set.

Types

type Index

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

An Index records the non-empty method sets of all package-level types in a package in a form that permits assignability queries without the type checker.

func Decode

func Decode(data []byte) *Index

Decode decodes the given gob-encoded data as an Index.

func NewIndex

func NewIndex(fset *token.FileSet, pkg *types.Package) *Index

NewIndex returns a new index of method-set information for all package-level types in the specified package.

func (*Index) Encode

func (index *Index) Encode() []byte

Encode encodes the receiver as gob-encoded data.

func (*Index) Search

func (index *Index) Search(key Key, methodID string) []Result

Search reports each type that implements (or is implemented by) the type that produced the search key. If methodID is nonempty, only that method of each type is reported.

The result does not include the error.Error method. TODO(adonovan): give this special case a more systematic treatment.

type Key

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

A Key represents the method set of a given type in a form suitable to pass to the (*Index).Search method of many different Indexes.

func KeyOf

func KeyOf(t types.Type) (Key, bool)

KeyOf returns the search key for the method sets of a given type. It returns false if the type has no methods.

type Location

type Location struct {
	Filename   string
	Start, End int // byte offsets
}

A Location records the extent of an identifier in byte-offset form.

Conversion to protocol (UTF-16) form is done by the caller after a search, not during index construction.

type Result

type Result struct {
	Location Location // location of the type or method

	// methods only:
	PkgPath    string          // path of declaring package (may differ due to embedding)
	ObjectPath objectpath.Path // path of method within declaring package
}

A Result reports a matching type or method in a method-set search.

Jump to

Keyboard shortcuts

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