Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringSliceContainsString ¶
StringSliceContainsString returns true if str is contained within slice.
Types ¶
type AstAnalyser ¶
type AstAnalyser interface { // GenerateInspector generates an ast.Inspector that gathers specific information about the abstract syntax tree // GenerateInspector is called within a go-routine and therefore any state changes will need to protected with locks. GenerateInspector(filePath string) Inspector // Analyse uses the information gathered from the in the. It is called after the abstract syntax tree of a file // is processed with the file name. When Analyse is called nothing may have been found and so it is up to the // implementation to keep state across multiple Analyse calls. Analyse is also called within a go-routine so // any state changes must be protected with locks. Analyse() }
AstAnalyser is an interface whose implementations are expected to examine an abstract syntax tree for various purposes. AstAnalyers are used in multiple go-routines. GenerateInspector is called within a go-routine and therefore, any implementations of AstAnalyse will need to ensure thread-safety.
type Generator ¶
type Generator struct { // Analysers is a slice that is used to examine the abstract syntax tree. Analysers []AstAnalyser // contains filtered or unexported fields }
Generator consists of one more more Analyzers, which examined an abstract syntax tree for single piece of information.
func (*Generator) AddAstAnalyzer ¶
func (generator *Generator) AddAstAnalyzer(inspector AstAnalyser)
AddAstAnalyzer adds an AstAnalyzer to the list of Analysers.
func (*Generator) Generate ¶
Generate passes a single file to every AstAnalyzer and then calls AstAnalyzer.Analyse
func (*Generator) GenerateDirectory ¶
GenerateDirectory passes all files within a directory to each AstAnalyzer.
type Inspector ¶
Inspector is the function that is passed to ast.Inspect
type StructExistsInspector ¶
type StructExistsInspector struct { Struct *map[string]*structInfo StructLock *sync.RWMutex // contains filtered or unexported fields }
StructExistsInspector is an AstAnalyzer that examines an abstract syntax tree for the existence of a structure by a given name.
func NewStructExistsInspector ¶
func NewStructExistsInspector(structNameList ...string) *StructExistsInspector
NewStructExistsInspector creates an AstAnalyzer that examines an abstract syntax tree for the existence of a structure by a given name.
func (*StructExistsInspector) Analyse ¶
func (findStructInspector *StructExistsInspector) Analyse()
Analyse examines the results from the inspector and determines what has changed since the last time Analyse was called. If any changes are found, the appropriate source files are generated.
func (*StructExistsInspector) GenerateInspector ¶
func (findStructInspector *StructExistsInspector) GenerateInspector(filePath string) Inspector
GenerateInspector returns a function that when passed to ast.Inspect will populate the corresponding values in the map if the structure is found while traversing the abstract syntax tree.
type TestInspector ¶
type TestInspector struct { }
TestInspector can be used to aid in understanding abstract syntax trees
func NewTestInspector ¶
func NewTestInspector() *TestInspector
NewTestInspector creates a test inspector that can be used to better understand an abstract syntax tree.
func (*TestInspector) Analyse ¶
func (testInspector *TestInspector) Analyse()
Analyse for a TestInspector does nothing.
func (*TestInspector) GenerateInspector ¶
func (testInspector *TestInspector) GenerateInspector(filePath string) Inspector
GenerateInspector return a function that accepts an ast.Node and prints out its type. Useful in debugging purposes.