Documentation ¶
Overview ¶
Package pkg provides code for loading templates, checking and generating source code.
Index ¶
- type Package
- func (p *Package) AddFile(file *ast.File)
- func (p *Package) Check() ([]error, error)
- func (p *Package) Filepath(file *ast.File) string
- func (p *Package) GenerateSource(packageName, name, source string) error
- func (p *Package) GenerateSourceAppendFile(filename *template.Template, packageName, name, source string) error
- func (p *Package) GeneratedFileset() map[*ast.File]struct{}
- func (p *Package) HasGeneratedSource(name string) bool
- func (p *Package) LoadGeneratePragmas() (messages []string)
- func (p *Package) LoadTemplates(tplr templ.Templater) (messages []string, err error)
- func (p *Package) LoadTemplatesFromFile(file *ast.File, ignoreSupportTemplates bool) []*jig
- func (p *Package) ParseDir() error
- func (p *Package) PkgSpec() []loader.PkgSpec
- func (p *Package) RemoveFileset(fileset map[*ast.File]struct{}) (messages []string, err error)
- func (p *Package) RemoveGeneratedSources() ([]string, error)
- func (p *Package) ScanForGeneratedSources(file *ast.File)
- func (Package) SuggestTypesToGenerate(errs []error) []string
- func (p *Package) Typemap() map[string]string
- func (p *Package) WriteFile(output io.Writer, file *ast.File) error
- func (p *Package) WriteFileset(fileset map[*ast.File]struct{}) (messages []string, err error)
- func (p *Package) WriteGeneratedSources() ([]string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Package ¶
type Package struct { *loader.Config // Dir is the directory where jig will look for the package files. Dir string // Name is the package name found in the first source file that is scanned from the package dir. Name string // contains filtered or unexported fields }
Package manages the package being checked for errors and where source code will be generated when errors indicate missing types etc.
func NewPackage ¶
NewPackage creates a package given a single directory where the source of the package lives.
func (*Package) AddFile ¶
AddFile is used by ParseDir() and GenerateSource(). It replaces the file stored by path in the fileset. The call is idempotent.
func (*Package) Check ¶
Check will typecheck the currently parsed package source and return all errors that were found. This will also import and parse all dependencies. After Check() has finished the package contains the contents of all imported packages and therefore LoadTemplates() may be caled to locate and load templates from those imported packages.
func (*Package) GenerateSource ¶
GenerateSource will take the passed name and source and add it to the package. You want multiple generated fragments to share a physical file on disk.
func (*Package) GenerateSourceAppendFile ¶
func (p *Package) GenerateSourceAppendFile(filename *template.Template, packageName, name, source string) error
GenerateSourceAppendFile will generate the source and append it to a shared source file. Duh!
func (*Package) GeneratedFileset ¶
GeneratedFileset returns a map containing the set of files that have generated fragments in them.
func (*Package) HasGeneratedSource ¶
HasGeneratedSource is used in the templ.PackageWriter interface to prevent fragments from being generated multiple times.
func (*Package) LoadGeneratePragmas ¶
func (*Package) LoadTemplates ¶
LoadTemplates is used to go through all the ast.File(s) in all the packages and then turn all jigs that are found in those files into templates.
func (*Package) LoadTemplatesFromFile ¶
LoadTemplatesFromFile will parse comments in a file to find //jig:template entries that declare templates and use that to determine source range of the associated template definition. Then walk the file ast and extract source in the ranges determined before and add it to the correct jig.
func (*Package) ParseDir ¶
ParseDir will add .go files found in the package directory to the internal list of files. This will also detect if a file contains previously generated source
func (*Package) PkgSpec ¶
PkgSpec returns PkgSpec instances with Path and Files correctly initialized.
func (*Package) RemoveFileset ¶
RemoveFileset will remove the passed set of files from the PkgSpec files slice.
func (*Package) RemoveGeneratedSources ¶
RemoveGeneratedSources will remove all files that contain generated source from the package dir.
func (*Package) ScanForGeneratedSources ¶
ScanForGeneratedSources looks in the comments of the file for comment pragma //jig:name and adds the name to the list of generated source fragments. This allows multiple source fragments to be stored in a single file.
func (Package) SuggestTypesToGenerate ¶
SuggestTypesToGenerate will suggest specialization signatures for types that are missing based on the error detected. e.g. if the error mentions and ObservableInt that is missing a field or method MapFloat32 then the specialization signature will become "ObservableInt MapFloat32" this signature can then be used by specialization code to generate the required type, field or method definition.
func (*Package) WriteFileset ¶
WriteFileset writes the set of files that contains generated source to disk.
func (*Package) WriteGeneratedSources ¶
WriteGeneratedSources is used to write the generated sources to file(s).