Package grinder defines the API for individual grinding bits.



    View Source
    const (
    	Insert = 1 + iota


    This section is empty.


    func BlockList

    func BlockList(x ast.Node) []ast.Stmt

      BlockList returns the list of statements contained by the block x, when x is an *ast.BlockStmt, *ast.CommClause, or *ast.CaseClause. Otherwise BlockList returns nil.

      func Diff

      func Diff(old, new string) []byte

      func GrindFuncDecls

      func GrindFuncDecls(ctxt *Context, pkg *Package, fn func(ctxt *Context, pkg *Package, edit *EditBuffer, decl *ast.FuncDecl))

      func IsGotoTarget

      func IsGotoTarget(blocks *block.Graph, x ast.Stmt) bool

      func IsTerminatingStmt

      func IsTerminatingStmt(blocks *block.Graph, x ast.Stmt) bool

      func Unlabel

      func Unlabel(x ast.Stmt) ast.Stmt


      type Context

      type Context struct {
      	Logf     func(format string, args ...interface{})
      	Errors   bool
      	Grinders []Func

      func (*Context) Errorf

      func (ctxt *Context) Errorf(format string, args ...interface{})

      func (*Context) GrindFiles

      func (ctxt *Context) GrindFiles(files ...string) *Package

      func (*Context) GrindPackage

      func (ctxt *Context) GrindPackage(path string) *Package

      type EditBuffer

      type EditBuffer struct {
      	// contains filtered or unexported fields

      func NewEditBuffer

      func NewEditBuffer(pkg *Package, filename string, f *ast.File) *EditBuffer

      func (*EditBuffer) Apply

      func (b *EditBuffer) Apply() string

      func (*EditBuffer) BeforeComments

      func (b *EditBuffer) BeforeComments(start token.Pos) token.Pos

        BeforeComments rewinds start past any blank lines or line comments and return the result. It does not rewind past leading blank lines: the returned position, if changed, is always the start of a non-blank line.

        func (*EditBuffer) CopyLine

        func (b *EditBuffer) CopyLine(startp, endp, insertp token.Pos)

        func (*EditBuffer) Delete

        func (b *EditBuffer) Delete(startp, endp token.Pos)

        func (*EditBuffer) DeleteLine

        func (b *EditBuffer) DeleteLine(startp, endp token.Pos)

        func (*EditBuffer) End

        func (b *EditBuffer) End(x ast.Node) token.Pos

          End returns x.End() except that it works around buggy results from the implementation of *ast.LabeledStmt and *ast.EmptyStmt. The node x must be located within b's source file. See

          func (*EditBuffer) Insert

          func (b *EditBuffer) Insert(p token.Pos, text string)

          func (*EditBuffer) NumEdits

          func (b *EditBuffer) NumEdits() int

          func (*EditBuffer) Replace

          func (b *EditBuffer) Replace(start, end token.Pos, text string)

          func (*EditBuffer) TextAt

          func (b *EditBuffer) TextAt(start, end token.Pos) string

          type Func

          type Func func(*Context, *Package)

          type Package

          type Package struct {
          	ImportPath string
          	Files      []*ast.File
          	Filenames  []string
          	FileSet    *token.FileSet
          	Types      *types.Package
          	TypesError error
          	Info       types.Info
          	// contains filtered or unexported fields

          func (*Package) LookupAtPos

          func (pkg *Package) LookupAtPos(fn *ast.FuncDecl, pos token.Pos, name string) types.Object

          func (*Package) Modified

          func (p *Package) Modified(name string) bool

          func (*Package) OrigSrc

          func (p *Package) OrigSrc(name string) string

          func (*Package) Rewrite

          func (p *Package) Rewrite(name, content string)

          func (*Package) Src

          func (p *Package) Src(name string) string