Documentation ¶
Index ¶
- func CleanType(t string) string
- func FindChildNode[T any](node ast.Node) T
- func FindChildNodes[T any](node ast.Node) []T
- func ReplaceScopedNames(s, packageName string, scopedNames map[string]bool) string
- type Field
- type Fields
- func (fields Fields) AddPointers(s string, asInterface bool) string
- func (fields Fields) AsArgs(includeParenthesis bool) string
- func (fields Fields) AsInterface(includeParenthesis bool) string
- func (fields Fields) AsParams() string
- func (fields Fields) AsTypes(includeParenthesis bool) string
- func (fields Fields) Generic(append bool) (string, string)
- type FileString
- type MethodData
- type Parser
- func (p *Parser) CreateBaseStructData(name string) *StructData
- func (p *Parser) Parse()
- func (p *Parser) ParseDir(dir string)
- func (p *Parser) ParseFile()
- func (p *Parser) ParseFuncDecl(node *ast.FuncDecl)
- func (p *Parser) ParseGenDecl(node *ast.GenDecl)
- func (p *Parser) PopulateStructData(structData *StructData, node *ast.StructType)
- type ParserArgs
- type StructData
- type StructOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindChildNode ¶
Find the first child node of the specified type
func FindChildNodes ¶
Grab the children nodes of the specified type
Types ¶
type Field ¶
A field is a name and a type. If in a struct, it can also have a tag. If a tag is in this format, `component:"$TAG"`, it will be in the TAG field.
type Fields ¶
type Fields []Field
func ConvertASTFieldList ¶
func ConvertASTFieldList(fileString FileString, node *ast.FieldList) Fields
Convert a []*ast.Field -> Fields
func ConvertTypeString ¶ added in v1.1.0
func (Fields) AddPointers ¶ added in v1.1.0
func (Fields) AsInterface ¶
Return args in format $Arg1_Name interface{}, ..., $ArgN_Name interface{}
type FileString ¶
type FileString string
Helper wrapper for strings with some additional helper methods
type MethodData ¶
Name: The name of the method. Recv: The reciever for the method. Args: List of all the args for the method. Returns: List of al lthe returns
type Parser ¶
type Parser struct { Args ParserArgs Structs map[string]*StructData PackageImports map[string]map[string]bool // List of all the imports needed for a package ScopedNames map[string]bool // Map of all the scoped names in the package // Values that get updated as the parser is walking File string // Which file is currently being parsed FileString FileString // The extracted file string corresponding to .File PackageFolder string // Which package fodler is currently being parsed PackageName string // Which package is currently being parsed ModulePath string // Go Package Path }
A parser looks through a directory and all it's children. It creates a group of StructData objects representing all the structs that should be generated.
func (*Parser) CreateBaseStructData ¶
func (p *Parser) CreateBaseStructData(name string) *StructData
Only call when parsing
func (*Parser) Parse ¶
func (p *Parser) Parse()
Parse everything in the specified directory according to the args.
func (*Parser) ParseDir ¶
Parse method that populates all the needed data for a specific package/dir.
func (*Parser) ParseFile ¶
func (p *Parser) ParseFile()
Parser method that reads an individual file and adjusts the data saved in the Structs field as data is read in.
func (*Parser) ParseFuncDecl ¶
Add method data to a struct. Also handles reading the params convert function
func (*Parser) ParseGenDecl ¶
Parse a GenDecl node and add the data to the Parser. The two node types that are relevant are the imports and the structs.
func (*Parser) PopulateStructData ¶
func (p *Parser) PopulateStructData(structData *StructData, node *ast.StructType)
Function to populate the base struct data
type ParserArgs ¶
type ParserArgs struct { /* The directory to run the parser in. All child folders will be walked through automatically. */ Directory string /* The default config to use for mockery generation commands. Will be automatically passed into all child struct generate commands. */ Config string // Regex to match against struct tags Match string }
type StructData ¶
type StructData struct { Name string // The text string representing the component as it was found Generic Fields // Represent any generic types for the struct StructFile string // The file the struct was found in PackageName string // The name of the package the struct resides in PackageFolder string // The enclosing folder of the struct file ConvertVar string // The string that represents the reciever variable in the convert function ConvertFunction string // Full text of the params.Convert function ScopedNames map[string]bool // List of names that appear in the package /* All the imports required for all the files associated with the component. This includes all methods as well. */ Imports map[string]bool Fields Fields // All the fields for this component Methods []MethodData // All the public methods for this component // Generate flags Options StructOptions }
Data corresponding to a particular struct representing a component. These structs are identified by the components package by the use of comment strings defined inside of the struct.
func (*StructData) ID ¶
func (s *StructData) ID() string
type StructOptions ¶
type StructOptions struct { Generate bool // Whether or not a "generate:component" tag was found in the comments of this struct InterfaceName string // Name of the interface once generated InterfaceFolder string // Folder for the exported interface to go InterfacePackage string // Name of the package for the generated interface. InterfaceFile string // File Name for the generated interface to go MockFolder string // Name of the generated mockery folder MockPackage string // Name of the generated mockery package MockFile string // Location of the generated mockery files SkipTestFile bool // True if the test file should be created. /* Whether or not to generate the tests file for this struct in the same package or as a "blackbox" with the "_test" extension. */ Blackbox bool // The config to use for the mockery generation Config string // Whether or not to create shortcut expecters for each mocked subcomponent Expecters []string }
Flags for the components generate function. These fields are set via a struct