Documentation ¶
Index ¶
- func CreateFileAndFolders(filePath string) (*os.File, error)
- func FormatCode(in []byte) []byte
- func GetPackagePath(fset *token.FileSet, filename string) (string, error)
- func ListGoFiles(dirPath string, ignore []string) ([]string, error)
- func ParseImports(imports []*ast.ImportSpec) map[string]*PackageInfo
- func Run(inputs []string, output string, ignore []string)
- func WriteHeader(w io.Writer, packageName string)
- type Generator
- func (g *Generator) ListInterfaceFields(i *ParsedInterface, imports map[string]*PackageInfo) []*ParsedField
- func (g *Generator) ParseFile(input string) *ParsedFile
- func (g *Generator) ParseInterface(ident *ast.SelectorExpr, usedImports map[string]struct{}, ...) *ParsedInterface
- func (g *Generator) WriteFile(input, output string) bool
- type PackageInfo
- type ParsedField
- type ParsedFile
- type ParsedInterface
- func (i *ParsedInterface) GetGenericsInfo() ([]string, []string)
- 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 (i *ParsedInterface) WriteAssertExpectations(w io.Writer)
- func (i *ParsedInterface) WriteGenericsHeader() string
- func (i *ParsedInterface) WriteGenericsNameHeader() string
- func (i *ParsedInterface) WriteInitializer(w io.Writer)
- func (i *ParsedInterface) WriteMethod(w io.Writer, methodName string, f *ParsedField)
- func (f *ParsedInterface) WriteMethodParams(implFile io.Writer, params []*ast.Field)
- func (f *ParsedInterface) WriteMethodResults(implFile io.Writer, results []*ast.Field)
- func (i *ParsedInterface) WriteMock(w io.Writer)
- func (i *ParsedInterface) WriteOnMethod(w io.Writer, methodName string, f *ParsedField)
- func (i *ParsedInterface) WriteStruct(w io.Writer)
- func (i *ParsedInterface) WriteStructMethods(file io.Writer)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateFileAndFolders ¶
CreateFileAndFolders creates a file and the necessary folders if they don't exist.
func FormatCode ¶
func GetPackagePath ¶
GetPackagePath returns the full package path from a given *ast.File.
func ListGoFiles ¶
ListGoFiles lists all Go files under a directory.
func ParseImports ¶
func ParseImports(imports []*ast.ImportSpec) map[string]*PackageInfo
func WriteHeader ¶
Types ¶
type Generator ¶
func NewGenerator ¶
func (*Generator) ListInterfaceFields ¶
func (g *Generator) ListInterfaceFields(i *ParsedInterface, imports map[string]*PackageInfo) []*ParsedField
func (*Generator) ParseFile ¶
func (g *Generator) ParseFile(input string) *ParsedFile
func (*Generator) ParseInterface ¶
func (g *Generator) ParseInterface(ident *ast.SelectorExpr, usedImports map[string]struct{}, imports map[string]*PackageInfo) *ParsedInterface
type PackageInfo ¶
type PackageInfo struct { Ref *ast.ImportSpec Name string ImportPath 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 }
func (*ParsedField) UpdateImports ¶
func (f *ParsedField) UpdateImports()
type ParsedFile ¶
type ParsedFile struct { Generator *Generator Ref *ast.File PkgPath string PkgName string Imports map[string]*PackageInfo UsedImports map[string]struct{} }
func (*ParsedFile) FindInterfaceByName ¶
func (f *ParsedFile) FindInterfaceByName(name string) (*ParsedInterface, map[string]*PackageInfo)
func (*ParsedFile) ListInterfaces ¶
func (f *ParsedFile) ListInterfaces() []*ParsedInterface
func (*ParsedFile) WriteImports ¶
func (f *ParsedFile) WriteImports(w io.Writer)
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 }
func (*ParsedInterface) GetGenericsInfo ¶
func (i *ParsedInterface) GetGenericsInfo() ([]string, []string)
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) WriteAssertExpectations ¶
func (i *ParsedInterface) WriteAssertExpectations(w io.Writer)
func (*ParsedInterface) WriteGenericsHeader ¶
func (i *ParsedInterface) WriteGenericsHeader() string
func (*ParsedInterface) WriteGenericsNameHeader ¶
func (i *ParsedInterface) WriteGenericsNameHeader() string
func (*ParsedInterface) WriteInitializer ¶
func (i *ParsedInterface) WriteInitializer(w io.Writer)
func (*ParsedInterface) WriteMethod ¶
func (i *ParsedInterface) WriteMethod(w io.Writer, methodName string, f *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)
func (*ParsedInterface) WriteMock ¶
func (i *ParsedInterface) WriteMock(w io.Writer)
func (*ParsedInterface) WriteOnMethod ¶
func (i *ParsedInterface) WriteOnMethod(w io.Writer, methodName string, f *ParsedField)
func (*ParsedInterface) WriteStruct ¶
func (i *ParsedInterface) WriteStruct(w io.Writer)
func (*ParsedInterface) WriteStructMethods ¶
func (i *ParsedInterface) WriteStructMethods(file io.Writer)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.