astx

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package astx provides utilities and builders for go/ast package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldsNames added in v0.3.0

func FieldsNames(fields []*ast.Field) []string

FieldsNames returns all field names flattened into a single list.

func FieldsNamesEmbed added in v0.3.0

func FieldsNamesEmbed(fields []*ast.Field) []string

FieldsNamesEmbed returns all field names or names of embedded types (if not anonymous).

func FileAppend

func FileAppend(file *ast.File, decl ...ast.Decl)

FileAppend appends provided declarations to the file.

func MergeFiles

func MergeFiles(dst *ast.File, files []*ast.File)

MergeFiles merge multiple files into a single file and merge the imports.

func PkgFiles

func PkgFiles(pkg *ast.Package) []*ast.File

PkgFiles returns a list of package files sorted by filenames.

func PkgNames

func PkgNames(pkgs map[string]*ast.Package) []string

PkgNames returns a sorted list of package names.

func SelectPkg

func SelectPkg(pkgs map[string]*ast.Package) (*ast.Package, error)

SelectPkg searches for non-test packages int the package set. Returns an error if no non-test package or multiple packages are found.

Types

type FieldMatcher added in v0.3.0

type FieldMatcher struct {
	FieldNames func(fields []*ast.Field) []string
	NameEq     func(a, b string) bool
}

FieldMatcher is a configurable matcher for field lists.

func (FieldMatcher) Filter added in v0.3.0

func (fm FieldMatcher) Filter(name string, fields []*ast.Field) []*ast.Field

Filter returns fields which match the given name.

func (FieldMatcher) Match added in v0.3.0

func (fm FieldMatcher) Match(name string, fields []*ast.Field) bool

Match returns true if any field matches the given name.

func (FieldMatcher) Select added in v0.3.0

func (fm FieldMatcher) Select(name string, fields []*ast.Field) *ast.Field

Select returns field, which matches the given name or nil.

type ValBuilder

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

ValBuilder provides utilities to build a single key-value expression.

func Val

func Val() *ValBuilder

Val creates a new new value builder.

func (*ValBuilder) Decl

func (vb *ValBuilder) Decl() *ast.GenDecl

Decl generate a key-value declaration.

func (*ValBuilder) Field

func (vb *ValBuilder) Field() *ast.Field

Field generates a simple field type declaration from value.

func (*ValBuilder) Spec

func (vb *ValBuilder) Spec() *ast.ValueSpec

Spec generates the key-value spec.

func (*ValBuilder) WithName

func (vb *ValBuilder) WithName(name string) *ValBuilder

WithName sets name for the value.

func (*ValBuilder) WithNameNode

func (vb *ValBuilder) WithNameNode(name *ast.Ident) *ValBuilder

WithNameNode uses provided ident node as a name for the value.

func (*ValBuilder) WithType

func (vb *ValBuilder) WithType(t *ast.Ident) *ValBuilder

WithType sets type for the value.

func (*ValBuilder) WithValue

func (vb *ValBuilder) WithValue(value ast.Expr) *ValBuilder

WithValue sets values for the value spec.

Jump to

Keyboard shortcuts

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