typesutil

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: BSD-2-Clause Imports: 4 Imported by: 66

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsJsObject

func IsJsObject(t types.Type) bool

func IsJsPackage

func IsJsPackage(pkg *types.Package) bool

func IsMethod added in v1.20.0

func IsMethod(o types.Object) bool

IsMethod returns true if the passed object is a method.

func OffsetOf added in v1.20.0

func OffsetOf(sizes types.Sizes, sel Selection) int64

OffsetOf returns byte offset of a struct field specified by the provided selection.

Adapted from go/types.Config.offsetof().

func RecvAsFirstArg added in v1.20.0

func RecvAsFirstArg(sig *types.Signature) *types.Signature

RecvAsFirstArg takes a method signature and returns a function signature with receiver as the first parameter.

func RecvType added in v1.20.0

func RecvType(sig *types.Signature) *types.Named

RecvType returns a named type of a method receiver, or nil if it's not a method.

For methods on a pointer receiver, the underlying named type is returned.

Types

type Map added in v1.20.0

type Map[Val any] struct {
	// contains filtered or unexported fields
}

Map is a type-safe wrapper around golang.org/x/tools/go/types/typeutil.Map.

func (*Map[Val]) At added in v1.20.0

func (m *Map[Val]) At(key types.Type) Val

func (*Map[Val]) Delete added in v1.20.0

func (m *Map[Val]) Delete(key types.Type) bool

func (*Map[Val]) Len added in v1.20.0

func (m *Map[Val]) Len() int

func (*Map[Val]) Set added in v1.20.0

func (m *Map[Val]) Set(key types.Type, value Val) (prev Val)

func (*Map[Val]) String added in v1.20.0

func (m *Map[Val]) String() string

type Selection added in v1.20.0

type Selection interface {
	Kind() types.SelectionKind
	Recv() types.Type
	Index() []int
	Obj() types.Object
	Type() types.Type
}

Selection is a common interface for go/types.Selection and our custom-constructed method and field selections.

func NewSelection added in v1.20.0

func NewSelection(kind types.SelectionKind, recv types.Type, index []int, obj types.Object, typ types.Type) Selection

NewSelection creates a new selection.

type Signature added in v1.20.0

type Signature struct {
	Sig *types.Signature
}

Signature is a helper that provides convenient access to function signature type information.

func (Signature) HasNamedResults added in v1.20.0

func (st Signature) HasNamedResults() bool

HasNamedResults returns true if the function signature returns something and returned results are names (e.g. `func () (val int, err error)`).

func (Signature) HasResults added in v1.20.0

func (st Signature) HasResults() bool

HasResults returns true if the function signature returns something.

func (Signature) Param added in v1.20.0

func (st Signature) Param(i int, ellipsis bool) types.Type

Param returns the expected argument type for the i'th argument position.

This function is able to return correct expected types for variadic calls both when ellipsis syntax (e.g. myFunc(requiredArg, optionalArgSlice...)) is used and when optional args are passed individually.

The returned types may differ from the actual argument expression types if there is an implicit type conversion involved (e.g. passing a struct into a function that expects an interface).

func (Signature) RequiredParams added in v1.20.0

func (st Signature) RequiredParams() int

RequiredParams returns the number of required parameters in the function signature.

func (Signature) VariadicType added in v1.20.0

func (st Signature) VariadicType() types.Type

VariadicType returns the slice-type corresponding to the signature's variadic parameter, or nil of the signature is not variadic. With the exception of the special-case `append([]byte{}, "string"...)`, the returned type is `*types.Slice` and `.Elem()` method can be used to get the type of individual arguments.

type TypeList added in v1.20.0

type TypeList []types.Type

TypeList an ordered list of types.

func (TypeList) Equal added in v1.20.0

func (tl TypeList) Equal(other TypeList) bool

Equal returns true if both lists of type arguments are identical.

func (TypeList) String added in v1.20.0

func (tl TypeList) String() string

type TypeNames added in v1.20.0

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

TypeNames implements an ordered set of *types.TypeName pointers.

The set is ordered to ensure deterministic behavior across compiler runs.

func (*TypeNames) Add added in v1.20.0

func (tn *TypeNames) Add(name *types.TypeName)

Add a type name to the set. If the type name has been previously added, this operation is a no-op. Two type names are considered equal iff they have the same memory address.

func (*TypeNames) Slice added in v1.20.0

func (tn *TypeNames) Slice() []*types.TypeName

Slice returns set elements in the order they were first added to the set.

Jump to

Keyboard shortcuts

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