stubmethods

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Doc = `stub methods analyzer

This analyzer generates method stubs for concrete types
in order to implement a target interface`

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:             "stubmethods",
	Doc:              Doc,
	Requires:         []*analysis.Analyzer{inspect.Analyzer},
	Run:              run,
	RunDespiteErrors: true,
}

Functions

func RelativeToFiles

func RelativeToFiles(concPkg *types.Package, concFile, ifaceFile *ast.File, missingImport func(name, path string)) types.Qualifier

RelativeToFiles returns a types.Qualifier that formats package names according to the files where the concrete and interface types are defined.

This is similar to types.RelativeTo except if a file imports the package with a different name, then it will use it. And if the file does import the package but it is ignored, then it will return the original name. It also prefers package names in ifaceFile in case an import is missing from concFile but is present in ifaceFile.

Additionally, if missingImport is not nil, the function will be called whenever the concFile is presented with a package that is not imported. This is useful so that as types.TypeString is formatting a function signature, it is identifying packages that will need to be imported when stubbing an interface.

Types

type StubInfo

type StubInfo 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.
	Interface types.Object
	Concrete  *types.Named
	Pointer   bool
}

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

func GetStubInfo

func GetStubInfo(ti *types.Info, path []ast.Node, pos token.Pos) *StubInfo

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

Jump to

Keyboard shortcuts

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