tree

package
v0.0.0-...-19249b1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2016 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVarMustString = errors.New("variable type must be a string")
	ErrVarNotFound   = errors.New("variable not found")
)

Functions

func DiscoverList

func DiscoverList(list []*ast.Field) []*ast.Field

DiscoverList builds clean lists for ast

func DiscoverType

func DiscoverType(express ast.Expr) ast.Expr

DiscoverType builds clean fields for ast

Types

type CommentVisitor

type CommentVisitor struct {
	Tree *Tree
}

func (*CommentVisitor) Visit

func (v *CommentVisitor) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for CommentVisitor

type ConstVisitor

type ConstVisitor struct {
	Name  string
	Value string
	Err   error
}

func (*ConstVisitor) Visit

func (v *ConstVisitor) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for ConstVisitor

type StructChanger

type StructChanger struct {
	Name     string
	Fields   []*ast.Field
	Comments *ast.CommentGroup
	Ok       bool
}

func (*StructChanger) Visit

func (v *StructChanger) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for StructChanger

type StructCopier

type StructCopier struct {
	Name     string
	Fields   []*ast.Field
	Comments *ast.CommentGroup
	Ok       bool
}

func (*StructCopier) Visit

func (v *StructCopier) Visit(n ast.Node) (w ast.Visitor)

Visit walks the tree for StructCopier

type Tree

type Tree struct {
	FileSet    *token.FileSet
	File       *ast.File
	CommentMap ast.CommentMap
}

func Load

func Load(filepath string, mode parser.Mode) (*Tree, error)

Load creates a Go package tree from a file

func New

func New(name string) *Tree

New creates a new Go package tree

func (*Tree) AddHelloMainFunc

func (gt *Tree) AddHelloMainFunc()

AddHelloMainFunc adds a main func the outputs: hello world

func (*Tree) AddImport

func (gt *Tree) AddImport(imp string)

AddImport adds an import

func (*Tree) AddImportSection

func (gt *Tree) AddImportSection(imports []string)

AddImport adds an import section with import paths

func (*Tree) Bytes

func (gt *Tree) Bytes(doFormat bool) ([]byte, error)

Bytes returns the code as a byte array

func (*Tree) ChangeConstString

func (gt *Tree) ChangeConstString(varName string, varValue string) error

ChangeConstString changes the value of a named const

func (*Tree) ChangeStruct

func (gt *Tree) ChangeStruct(varName string, varValue []*ast.Field, varComments *ast.CommentGroup) error

ChangeStruct changes the struct field list

func (*Tree) PrintComments

func (gt *Tree) PrintComments() error

PrintComments prints all the comments and locations

func (*Tree) SetPackageName

func (gt *Tree) SetPackageName(name string)

SetPackageName sets the package name

func (*Tree) StructFields

func (gt *Tree) StructFields(varName string) ([]*ast.Field, *ast.CommentGroup, error)

StructFields returns the struct fields

func (*Tree) WriteFile

func (gt *Tree) WriteFile(filepath string, doFormat bool, dirPerm os.FileMode, filePerm os.FileMode) error

WriteFile writes the code to a file and create the folder structure

Jump to

Keyboard shortcuts

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