Documentation ¶
Overview ¶
Package genutil contains helper functions for autogenerating code.
Index ¶
- func AutogenString() string
- func IsAutogen(filename string) bool
- func WriteAutogen(filename string, data []byte) error
- type Package
- func (p *Package) ASTFiles() map[string]*ast.File
- func (p *Package) Dir() string
- func (p *Package) ExportedTypes(include *regexp.Regexp, exclude *regexp.Regexp) []*types.Named
- func (p *Package) FileSet() *token.FileSet
- func (p *Package) Info() *types.Info
- func (p *Package) SelectedTypes(include *regexp.Regexp, exclude *regexp.Regexp, names []string) ([]*types.Named, error)
- func (p *Package) Types(include *regexp.Regexp, exclude *regexp.Regexp) []*types.Named
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutogenString ¶
func AutogenString() string
AutogenString returns the string which makes gondola identify this file as autogenerated.
func IsAutogen ¶
IsAutogen returns wheter the given filename exists and was autogenerated by a gondola tool.
func WriteAutogen ¶
WriteAutogen writes the given autogenerated data to the given filename. Code will be first formatted using go/format. It will only overwrite the existing file if it was autogenerated. Tools autogenerating code should always use this function to avoid overwriting files which are not autogenerated.
Types ¶
type Package ¶
Package represents a parsed package with all its dependencies. Use NewPackage to create a Package.
func NewPackage ¶
NewPackage returns a new Package struct, which can be used to generate code related to the package. The package might be given as either an absolute path or an import path. If the package can't be found or the package is not compilable, this function returns an error.
func (*Package) ExportedTypes ¶
ExportedTypes works like Types, but only returns types that are exported.
func (*Package) SelectedTypes ¶
func (p *Package) SelectedTypes(include *regexp.Regexp, exclude *regexp.Regexp, names []string) ([]*types.Named, error)
SelectedTypes works similarly to Types, but tests all types if include != nil or exclude != nil, otherwise it acts like p.ExportedTypes(nil, nil). Types explicitely named in the names argument are always included in the returned value. If any of the named types does not exist, an error is returned.