astquery

package module
v0.0.0-...-aa6ec30 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2015 License: Apache-2.0 Imports: 4 Imported by: 0

README

go-astquery

A simple library for querying the AST of a Go program. Good for writing quick, static checks to guarantee invariants in code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(nodes []ast.Node, filter Filter) []ast.Node

Find recursively searches the AST nodes passed as the first argument and returns all AST nodes that match the filter. It does not descend into matching nodes for additional matching nodes.

func GetName

func GetName(n ast.Node) (name string, exists bool)

GetName gets the name of a node's identifier. For TypeSpecs and FuncDecls, it looks at the .Name field. For SelectorExpr's, it looks at the Sel field.

Types

type Filter

type Filter interface {
	Filter(node ast.Node) bool
}

type FilterFunc

type FilterFunc func(node ast.Node) bool

FilterFunc lets you specify a function for custom filtering logic.

func (FilterFunc) Filter

func (f FilterFunc) Filter(node ast.Node) bool

type MethodFilter

type MethodFilter struct {
	// ReceiverType is the name of the receiver's type (without the '*' if a pointer).
	ReceiverType string

	// ExportedOnly is if the filter should select only exported methods.
	ExportedOnly bool
}

MethodFilter matches method declaration nodes that have the specified receiver type.

func (MethodFilter) Filter

func (f MethodFilter) Filter(node ast.Node) bool

type RegexpFilter

type RegexpFilter struct {
	// Pattern is a regular expression matching AST node names
	Pattern *regexp.Regexp

	// Type is the type of AST node to filter for
	Type reflect.Type
}

RegexpFilter matches nodes whose names match a regular expression.

func (RegexpFilter) Filter

func (s RegexpFilter) Filter(node ast.Node) bool

type SetFilter

type SetFilter struct {
	// Names is a set of names that match the filter
	Names []string

	// Type is the type of AST node to filter for
	Type reflect.Type
}

SetFilter matches nodes whose names are in the specified set of names.

func (SetFilter) Filter

func (f SetFilter) Filter(node ast.Node) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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