asterisk

package module
v0.0.0-...-974c383 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 2 Imported by: 0

README

License pkg.go.dev Build Status Go Report Card

asterisk

search and manipulate go AST

Search the go AST for specific patterns, select specific nodes and manipulate them.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(f ast.Node, pms PatternMatchers)

Types

type BoolCondition

type BoolCondition func(bool) bool

type ChanDirCondition

type ChanDirCondition func(ast.ChanDir) bool

type ExprCondition

type ExprCondition func(ast.Expr) bool

func Expr

Expr check if the given ast.Expr matches the given condition.

type FilesMapCondition

type FilesMapCondition func(Files map[string]*ast.File) bool

type ImportsMapCondition

type ImportsMapCondition func(map[string]*ast.Object) bool

type Matcher

type Matcher struct {
	// contains filtered or unexported fields
}

Matcher helps to find ast portions of interest while walking through the tree.

func New

func New(conditions []NodeCondition, processMatch func()) *Matcher

New returns a new instance of a Matcher.

func (*Matcher) Match

func (pm *Matcher) Match(n ast.Node)

Walk will sequentially called detect node chains by the configured conditions. Once all conditions have matched, the ProcessMatch will be called.

type NodeCondition

type NodeCondition func(ast.Node) bool

func ArrayType

func ArrayType(elt, l NodeCondition) NodeCondition

ArrayType check if the given ast.ArrayType matches the given conditions.

func AssignStmt

func AssignStmt(lhs, rhs NodesCondition) NodeCondition

AssignStmt check if the given ast.AssignStmt matches the given conditions.

func BadDecl

func BadDecl() NodeCondition

BadDecl check if the given values type matches *ast.BadDecl.

func BadExpr

func BadExpr() NodeCondition

BadExpr check if the given ast.Node is a ast.BadExpr.

func BadStmt

func BadStmt() NodeCondition

BadStmt check if the given ast.Node is a ast.BadStmt.

func BasicLit

func BasicLit(value string) NodeCondition

BasicLit check if the given ast.BasicLit matches the given conditions.

func BinaryExpr

func BinaryExpr(x, y NodeCondition) NodeCondition

BinaryExpr check if the given ast.BinaryExpr matches the given conditions.

func BlockStmt

func BlockStmt(stmts NodesCondition) NodeCondition

BlockStmt check if the given ast.BranchStmt matches the given conditions.

func BranchStmt

func BranchStmt(label NodeCondition) NodeCondition

BranchStmt check if the given ast.BranchStmt matches the given conditions.

func CallExpr

func CallExpr(fun NodeCondition, args NodesCondition) NodeCondition

CallExpr check if the given ast.CallExpr matches the given conditions.

func CaseClause

func CaseClause(list NodesCondition, body NodesCondition) NodeCondition

CaseClause check if the given ast.CaseClause matches the given conditions.

func ChanType

ChanType check if the given ast.ChanType matches the given conditions.

func CommClause

func CommClause(comm NodeCondition, body NodesCondition) NodeCondition

CommClause check if the given ast.CommClause matches the given conditions.

func CompositeLit

func CompositeLit(t NodeCondition, args NodesCondition) NodeCondition

CompositeLit check if the given ast.ParenExpr matches the given conditions.

func DeclStmt

func DeclStmt(decl NodeCondition) NodeCondition

DeclStmt check if the given ast.DeclStmt matches the given conditions.

func DeferStmt

func DeferStmt(call NodeCondition) NodeCondition

DeferStmt check if the given ast.DeferStmt matches the given conditions.

func Ellipsis

func Ellipsis(elem NodeCondition) NodeCondition

Ellipsis check if the given ast.Ellipsis matches the given conditions.

func EmptyStmt

func EmptyStmt(implicit BoolCondition) NodeCondition

EmptyStmt check if the given ast.EmptyStmt matches the given conditions.

func ExprStmt

func ExprStmt(x NodeCondition) NodeCondition

ExprStmt check if the given ast.ExprStmt matches the given conditions.

func File

func File(
	doc,
	name NodeCondition,
	decls NodesCondition,
	scope ScopeCondition,
	imports,
	unresolved NodesCondition,
	comments NodesCondition) NodeCondition

File check if the given ast.File matches the given conditions.

func ForStmt

func ForStmt(init, cond, post, body NodeCondition) NodeCondition

ForStmt check if the given ast.ForStmt matches the given conditions.

func FuncDecl

func FuncDecl(doc, recv, name, t, body NodeCondition) NodeCondition

FuncDecl check if the given ast.FuncDecl matches the given conditions.

func FuncLit

func FuncLit(t, block NodeCondition) NodeCondition

FuncLit check if the given ast.FuncLit matches the given conditions.

func FuncType

func FuncType(params, results NodeCondition) NodeCondition

FuncType check if the given ast.FuncType matches the given conditions.

func GenDecl

func GenDecl(doc NodeCondition, specs NodesCondition) NodeCondition

GenDecl check if the given ast.GenDecl matches the given conditions.

func GoStmt

func GoStmt(call NodeCondition) NodeCondition

GoStmt check if the given ast.GoStmt matches the given conditions.

func Ident

func Ident(name string) NodeCondition

Ident check if the given ast.Ident name matches the requested one.

func IdentExpr

func IdentExpr(name string) NodeCondition

IdentExpr check if the given ast.IdentExpr name matches the requested one.

func IfStmt

func IfStmt(init, body, cond, els NodeCondition) NodeCondition

IfStmt check if the given ast.IfStmt matches the given conditions.

func IgnoreNode

func IgnoreNode() NodeCondition

IgnoreNode always returns true.

func ImportSpec

func ImportSpec(doc, name, importPath, comment NodeCondition) NodeCondition

ImportSpec check if the given ast.ImportSpec matches the given conditions.

func IncDecStmt

func IncDecStmt(x NodeCondition) NodeCondition

IncDecStmt check if the given ast.IncDecStmt matches the given conditions.

func IndexExpr

func IndexExpr(x, index NodeCondition) NodeCondition

IndexExpr check if the given ast.IndexExpr matches the given conditions.

func InterfaceType

func InterfaceType(methods NodeCondition, incomplete BoolCondition) NodeCondition

InterfaceType check if the given ast.InterfaceType matches the given conditions.

func KeyValueExpr

func KeyValueExpr(k, v NodeCondition) NodeCondition

KeyValueExpr check if the given ast.KeyValueExpr matches the given conditions.

func LabeledStmt

func LabeledStmt(label, stmt NodeCondition) NodeCondition

LabeledStmt check if the given ast.LabeledStmt matches the given conditions.

func MapType

func MapType(k, v NodeCondition) NodeCondition

MapType check if the given ast.MapType matches the given conditions.

func Package

Package check if the given ast.Package matches the given conditions.

func ParenExpr

func ParenExpr(x NodeCondition) NodeCondition

ParenExpr check if the given ast.ParenExpr matches the given conditions.

func RangeStmt

func RangeStmt(k, v, x, body NodeCondition) NodeCondition

RangeStmt check if the given ast.RangeStmt matches the given conditions.

func ReturnStmt

func ReturnStmt(results NodesCondition) NodeCondition

ReturnStmt check if the given ast.ReturnStmt matches the given conditions.

func SelectStmt

func SelectStmt(body NodeCondition) NodeCondition

SelectStmt check if the given ast.SelectStmt matches the given conditions.

func SelectorExpr

func SelectorExpr(x, sel NodeCondition) NodeCondition

SelectorExpr check if the given ast.SelectorExpr matches the given conditions.

func SendStmt

func SendStmt(channel, val NodeCondition) NodeCondition

SendStmt check if the given ast.SendStmt matches the given conditions.

func SliceExpr

func SliceExpr(x, low, high, max NodeCondition) NodeCondition

SliceExpr check if the given ast.SliceExpr matches the given conditions.

func Spec

func Spec() NodeCondition

Spec check if the given values type matches the requested one.

func StarExpr

func StarExpr(x NodeCondition) NodeCondition

StarExpr check if the given ast.TypeAssertExpr matches the given conditions.

func StructType

func StructType(fields NodeCondition, incomplete BoolCondition) NodeCondition

StructType check if the given ast.StructType matches the given conditions.

func SwitchStmt

func SwitchStmt(init, tag, body NodeCondition) NodeCondition

SwitchStmt check if the given ast.SwitchStmt matches the given conditions.

func Type

func Type(t interface{}) NodeCondition

Type check if the given values type matches the requested one.

func TypeAssertExpr

func TypeAssertExpr(x, t NodeCondition) NodeCondition

TypeAssertExpr check if the given ast.TypeAssertExpr matches the given conditions.

func TypeSpec

func TypeSpec(doc, name, t, comment NodeCondition) NodeCondition

TypeSpec check if the given ast.TypeSpec matches the given conditions.

func TypeSwitchStmt

func TypeSwitchStmt(init, assign, body NodeCondition) NodeCondition

TypeSwitchStmt check if the given ast.SwitchStmt matches the given conditions.

func UnaryExpr

func UnaryExpr(x NodeCondition) NodeCondition

UnaryExpr check if the given ast.UnaryExpr matches the given conditions.

func ValueSpec

func ValueSpec(doc, t, comment NodeCondition, names NodesCondition, values NodesCondition) NodeCondition

ValueSpec check if the given ast.ValueSpec matches the given conditions.

type NodeSelections

type NodeSelections map[string][]**ast.Node

NodeSelections contain nodes that were selected during matching. They are stored as Pointers on the existing ast.Node Pointers so they can be used to manipulate the tree in memory.

func (NodeSelections) BasicLit

func (s NodeSelections) BasicLit(key string) *ast.BasicLit

BasicLit returns a pointer to the ast.Basic that was selected using the given key.

func (NodeSelections) BlockStmt

func (s NodeSelections) BlockStmt(key string) *ast.BlockStmt

BlockStmt returns a pointer to the ast.BlockStmt that was selected using the given key.

func (NodeSelections) CallExpr

func (s NodeSelections) CallExpr(key string) *ast.CallExpr

CallExpr returns a pointer to the ast.CallExpr that was selected using the given key.

func (NodeSelections) ExprStmt

func (s NodeSelections) ExprStmt(key string) *ast.ExprStmt

ExprStmt returns a pointer to the ast.ExprStmt that was selected using the given key.

func (NodeSelections) Ident

func (s NodeSelections) Ident(key string) *ast.Ident

Ident returns a pointer to the ast.Ident that was selected using the given key.

func (NodeSelections) IfStmt

func (s NodeSelections) IfStmt(key string) *ast.IfStmt

IfStmt returns a pointer to the ast.IfStmt that was selected using the given key.

func (NodeSelections) ImportSpecs

func (s NodeSelections) ImportSpecs(key string) []*ast.ImportSpec

ExprStmt returns a pointer to the ast.ExprStmt that was selected using the given key.

func (NodeSelections) Select

Select will select the visited node for the given key if the given condition matches.

func (NodeSelections) Selects

Select will select the visited nodes for the given key if the given condition matches.

func (NodeSelections) Stmt

func (s NodeSelections) Stmt(key string) ast.Stmt

Stmt returns a pointer to the ast.Stmt that was selected using the given key.

type NodesCondition

type NodesCondition func([]ast.Node) bool

func Exprs

func Exprs(x []NodeCondition) NodesCondition

Exprs check if the given []ast.Node matches the given conditions in sequence.

func First

func IgnoreNodes

func IgnoreNodes() NodesCondition

func Last

type PatternMatchers

type PatternMatchers []*Matcher

PatternMatchers holds multiple matchers.

func (PatternMatchers) Match

func (m PatternMatchers) Match(n ast.Node)

Walk matches all matchers against the given node.

type ScopeCondition

type ScopeCondition func(*ast.Scope) bool

func IgnoreScope

func IgnoreScope() ScopeCondition

type StringCondition

type StringCondition func(string) bool

Jump to

Keyboard shortcuts

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