slicer

package
v0.0.0-...-b6cd071 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringSliceContainsString

func StringSliceContainsString(slice []string, str string) bool

StringSliceContainsString returns true if str is contained within slice.

func StringSliceDiff

func StringSliceDiff(slice1 []string, slice2 []string) []string

StringSliceDiff performs a set difference on two slices of strings.

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 NewGenerator

func NewGenerator() *Generator

NewGenerator creates a Generator.

func (*Generator) AddAstAnalyzer

func (generator *Generator) AddAstAnalyzer(inspector AstAnalyser)

AddAstAnalyzer adds an AstAnalyzer to the list of Analysers.

func (*Generator) Generate

func (generator *Generator) Generate(name string) (err error)

Generate passes a single file to every AstAnalyzer and then calls AstAnalyzer.Analyse

func (*Generator) GenerateDirectory

func (generator *Generator) GenerateDirectory(rootPath string, directory string) error

GenerateDirectory passes all files within a directory to each AstAnalyzer.

func (*Generator) GenerateDirectoryTree

func (generator *Generator) GenerateDirectoryTree(rootPath string) error

GenerateDirectoryTree traverses a directory tree passing each file to each AstAnalyzer concurrently.

type Inspector

type Inspector func(node ast.Node) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL