Documentation ¶
Index ¶
Constants ¶
const Doc = `stub methods analyzer
This analyzer generates method stubs for concrete types
in order to implement a target interface`
Variables ¶
Functions ¶
func RelativeToFiles ¶
func RelativeToFiles(concPkg *types.Package, concFile *ast.File, ifaceImports []*ast.ImportSpec, missingImport func(name, path string)) types.Qualifier
RelativeToFiles returns a types.Qualifier that formats package names according to the import environments of the files that define the concrete type and the interface type. (Only the imports of the latter file are provided.)
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 importEnv in case an import is missing from concFile but is present among importEnv.
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