stubmethods

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package stubmethods provides the analysis logic for the quick fix to "Declare missing methods of TYPE" errors. (The fix logic lives in golang.stubMethodsFixer.)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallStubInfo

type CallStubInfo struct {
	Fset       *token.FileSet             // the FileSet used to type-check the types below
	Receiver   typesinternal.NamedOrAlias // the method's receiver type
	MethodName string
	After      types.Object // decl after which to insert the new decl
	// contains filtered or unexported fields
}

CallStubInfo represents a missing method that a receiver type is about to generate which has "type X has no field or method Y" error

func GetCallStubInfo

func GetCallStubInfo(fset *token.FileSet, info *types.Info, path []ast.Node, pos token.Pos) *CallStubInfo

GetCallStubInfo extracts necessary information to generate a method definition from a CallExpr.

func (*CallStubInfo) Emit

func (si *CallStubInfo) Emit(out *bytes.Buffer, qual types.Qualifier) error

Emit writes to out the missing method based on type info of si.Receiver and CallExpr.

type IfaceStubInfo

type IfaceStubInfo struct {
	// Interface is the interface that the client wants to implement.
	// When the interface is defined, the underlying object will be a TypeName.
	// Note that we keep track of types.Object instead of types.Type in order
	// to keep a reference to the declaring object's package and the ast file
	// in the case where the concrete type file requires a new import that happens to be renamed
	// in the interface file.
	// TODO(marwan-at-work): implement interface literals.
	Fset      *token.FileSet // the FileSet used to type-check the types below
	Interface *types.TypeName
	Concrete  typesinternal.NamedOrAlias
	// contains filtered or unexported fields
}

IfaceStubInfo represents a concrete type that wants to stub out an interface type

func GetIfaceStubInfo

func GetIfaceStubInfo(fset *token.FileSet, info *types.Info, path []ast.Node, pos token.Pos) *IfaceStubInfo

GetIfaceStubInfo determines whether the "missing method error" can be used to deduced what the concrete and interface types are.

TODO(adonovan): this function (and its following 5 helpers) tries to deduce a pair of (concrete, interface) types that are related by an assignment, either explicitly or through a return statement or function call. This is essentially what the refactor/satisfy does, more generally. Refactor to share logic, after auditing 'satisfy' for safety on ill-typed code.

func (*IfaceStubInfo) Emit

func (si *IfaceStubInfo) Emit(out *bytes.Buffer, qual types.Qualifier) error

Emit writes to out the missing methods of si.Concrete required for it to implement si.Interface

Jump to

Keyboard shortcuts

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