rewrite

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNameList added in v0.6.2

func GetNameList(ids []*ast.Ident) (names []string)

func PrintNodes

func PrintNodes(objs ...interface{})

func TrimComment

func TrimComment(c string) string

Types

type CodeParser

type CodeParser struct {
	DeclNodes   []*DeclNode
	DeclIndexes map[string][]int
	*CodeSource
}

func NewCodeParser

func NewCodeParser() *CodeParser

func NewFileParser

func NewFileParser(filename string) (cp *CodeParser, err error)

func NewSourceParser

func NewSourceParser(source []byte) (cp *CodeParser, err error)

func (*CodeParser) AllDeclNode

func (cp *CodeParser) AllDeclNode(kind string) []*DeclNode

func (*CodeParser) GetDeclNode

func (cp *CodeParser) GetDeclNode(kind string, offset int) *DeclNode

func (*CodeParser) ParseDecls

func (cp *CodeParser) ParseDecls(kind string, limit int) bool

type CodeSource

type CodeSource struct {
	Fileast    *ast.File
	Fileset    *token.FileSet
	Source     []byte
	Alternates []PosAlt // Source 只能替换一次,然后必须重新解析 Fileast
	*printer.Config
}

func NewCodeSource

func NewCodeSource() *CodeSource

func ResetImports added in v0.6.4

func ResetImports(cs *CodeSource, imports map[string]string) (*CodeSource, error)

func WithImports added in v0.6.4

func WithImports(pkg string, source []byte, imports map[string]string) (*CodeSource, error)

func (*CodeSource) AddCode

func (cs *CodeSource) AddCode(code []byte) error

func (*CodeSource) AddImport

func (cs *CodeSource) AddImport(path, alias string) bool

func (*CodeSource) AddReplace added in v0.6.3

func (cs *CodeSource) AddReplace(first, last ast.Node, code string)

func (*CodeSource) AddStringCode

func (cs *CodeSource) AddStringCode(code string) error

func (*CodeSource) AltSource added in v0.6.3

func (cs *CodeSource) AltSource() ([]byte, bool)

func (*CodeSource) DelImport

func (cs *CodeSource) DelImport(path, alias string) bool

func (*CodeSource) GetComment

func (cs *CodeSource) GetComment(c *ast.CommentGroup, trim bool) string

func (*CodeSource) GetContent

func (cs *CodeSource) GetContent() ([]byte, error)

func (*CodeSource) GetNodeCode

func (cs *CodeSource) GetNodeCode(node ast.Node) string

func (*CodeSource) GetPackage

func (cs *CodeSource) GetPackage() string

func (*CodeSource) GetPackageOffset added in v0.6.4

func (cs *CodeSource) GetPackageOffset() int

func (*CodeSource) SetPackage

func (cs *CodeSource) SetPackage(name string) (err error)

func (*CodeSource) SetSource

func (cs *CodeSource) SetSource(source []byte) (err error)

func (*CodeSource) WriteSource added in v0.6.3

func (cs *CodeSource) WriteSource(filename string) error

func (*CodeSource) WriteTo

func (cs *CodeSource) WriteTo(filename string) error

type DeclNode

type DeclNode struct {
	Token   token.Token
	Kinds   []string
	Names   []string
	Fields  []*FieldNode
	Comment *ast.CommentGroup
	Offset  int
	ast.Decl
}

func NewDeclNode

func NewDeclNode(decl ast.Decl, offset int, position token.Pos) (n *DeclNode, err error)

func (DeclNode) GetKind added in v0.6.2

func (n DeclNode) GetKind() string

func (DeclNode) GetName added in v0.6.2

func (n DeclNode) GetName() string

func (*DeclNode) ParseFunDecl

func (n *DeclNode) ParseFunDecl(fun *ast.FuncDecl) (err error)

func (*DeclNode) ParseGenDecl

func (n *DeclNode) ParseGenDecl(gen *ast.GenDecl) (err error)

func (*DeclNode) ParseStruct

func (n *DeclNode) ParseStruct(fields []*ast.Field) (err error)

type FieldNode

type FieldNode struct {
	Names   []string
	Comment *ast.CommentGroup
	*ast.Field
}

func (*FieldNode) GetTag

func (n *FieldNode) GetTag() reflect.StructTag

type PosAlt added in v0.6.3

type PosAlt struct {
	Pos, End  token.Position
	Alternate []byte
}

替换位置

Jump to

Keyboard shortcuts

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