typesutil

package
v1.19.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 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

func IsMethod(o types.Object) bool

IsMethod returns true if the passed object is a method.

func OffsetOf

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

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

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

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

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

func (*Map[Val]) Delete

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

func (*Map[Val]) Len

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

func (*Map[Val]) Set

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

func (*Map[Val]) String

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

type Selection

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

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

NewSelection creates a new selection.

type Signature

type Signature struct {
	Sig *types.Signature
}

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

func (Signature) HasNamedResults

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

func (st Signature) HasResults() bool

HasResults returns true if the function signature returns something.

func (Signature) Param

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

func (st Signature) RequiredParams() int

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

func (Signature) VariadicType

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

type TypeList []types.Type

TypeList an ordered list of types.

func (TypeList) Equal

func (tl TypeList) Equal(other TypeList) bool

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

func (TypeList) String

func (tl TypeList) String() string

type TypeNames

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

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

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