Documentation
¶
Index ¶
- func GenerateInterface(c GenerateInterfaceConfig)
- func ParseImports(imports []*ast.ImportSpec) *map[string]*PackageInfo
- func Run(inputs []string, output string, ignore []string, interfaces ...string)
- type GenerateInterfaceConfig
- type Generator
- type PackageInfo
- type ParsedField
- type ParsedFile
- type ParsedInterface
- func (i *ParsedInterface) ListFields() []*ParsedField
- func (f *ParsedInterface) PrintAstField(i int, field *ast.Field, printName bool) string
- func (f *ParsedInterface) PrintAstFields(implFile io.Writer, fields []*ast.Field, printName bool)
- func (f *ParsedInterface) PrintMethodHeader(file io.Writer, methodName string, field *ParsedField)
- func (f *ParsedInterface) WriteMethodParams(implFile io.Writer, params []*ast.Field)
- func (f *ParsedInterface) WriteMethodResults(implFile io.Writer, results []*ast.Field)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateInterface ¶ added in v0.3.0
func GenerateInterface(c GenerateInterfaceConfig)
func ParseImports ¶
func ParseImports(imports []*ast.ImportSpec) *map[string]*PackageInfo
Types ¶
type GenerateInterfaceConfig ¶ added in v0.3.0
type Generator ¶
type Generator struct { FileSet *token.FileSet MockPackageName string // contains filtered or unexported fields }
Generator is the controller for the whole module, caching files and holding metadata.
func NewGenerator ¶
NewGenerator will create a new mock generator for the specified module.
func (*Generator) GenerateFile ¶ added in v0.3.0
type PackageInfo ¶
type PackageInfo struct { Ref *ast.ImportSpec Alias string Name string Path string }
func ParsePackageInfo ¶
func ParsePackageInfo(importPath string) (*PackageInfo, bool)
ParsePackageInfo parses the specified package and returns its package name and import path.
type ParsedField ¶
type ParsedField struct { Interface *ParsedInterface Ref *ast.Field Name string Type string }
type ParsedFile ¶
type ParsedFile struct { Generator *Generator Size int Ref *ast.File PkgPath string PkgName string Imports map[string]*imports.ImportEntry OriginalImports map[string]*imports.ImportEntry ImportsPathMap map[string]*imports.ImportEntry UsedImports map[string]struct{} // contains filtered or unexported fields }
func (*ParsedFile) FindInterfaceByName ¶
func (f *ParsedFile) FindInterfaceByName(name string) *ParsedInterface
func (*ParsedFile) ListInterfaces ¶
func (f *ParsedFile) ListInterfaces(names ...string) []*ParsedInterface
type ParsedInterface ¶
type ParsedInterface struct { ParsedFile *ParsedFile Type *ast.TypeSpec Ref *ast.InterfaceType Name string GenericsTypes []string GenericsNames []string // TranslateGenericNames translates generic type names from any imported interfaces. // Example: // type A[T any] interface{ B[T] } // type B[J any] interface{ Method() J } // it should have method Method() T when implementing A mock. TranslateGenericNames []string // contains filtered or unexported fields }
func (*ParsedInterface) ListFields ¶
func (i *ParsedInterface) ListFields() []*ParsedField
func (*ParsedInterface) PrintAstField ¶
func (*ParsedInterface) PrintAstFields ¶
func (*ParsedInterface) PrintMethodHeader ¶
func (f *ParsedInterface) PrintMethodHeader(file io.Writer, methodName string, field *ParsedField)
func (*ParsedInterface) WriteMethodParams ¶
func (f *ParsedInterface) WriteMethodParams(implFile io.Writer, params []*ast.Field)
func (*ParsedInterface) WriteMethodResults ¶
func (f *ParsedInterface) WriteMethodResults(implFile io.Writer, results []*ast.Field)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.