gorefactor

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2019 License: MIT Imports: 9 Imported by: 0

README

GoRefactor

this module provides some basic utilities for you to do code migration on large code base written in golang.

Build Status Go Report Card Coverage Status golang godoc GitHub license GitHub release

Installation

$ go get -u github.com/ZhengHe-MD/gorefactor

Examples

API

parse src
ParseSrcFile(filename string) (df *dst.File, err error)
ParseSrcFileFromBytes(src []byte) (df *dst.File, err error)
write src
FprintFile(out io.Writer, df *dst.File) error
function body utilities
HasStmtInsideFuncBody(df *dst.File, funcName string, stmt dst.Stmt) (ret bool)
DeleteStmtFromFuncBody(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)
AddStmtToFuncBody(df *dst.File, funcName string, stmt dst.Stmt, pos int) (modified bool)
AddStmtToFuncBodyStart(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)
AddStmtToFuncBodyEnd(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)
AddStmtToFuncBodyBefore(df *dst.File, funcName string, stmt, refStmt dst.Stmt) (modified bool) 
AddStmtToFuncBodyAfter(df *dst.File, funcName string, stmt, refStmt dst.Stmt) (modified bool)
function lit utilities
AddStmtToFuncLitBody(df *dst.File, scope Scope, stmt dst.Stmt, pos int) (modified bool)
AddFieldToFuncLitParams(df *dst.File, scope Scope, field *dst.Field, pos int) (modified bool)
function call utilities
HasArgInCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr) (ret bool)
DeleteArgFromCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr) (modified bool)
AddArgToCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr, pos int) (modified bool)
SetMethodOnReceiver(df *dst.File, scope Scope, receiver, oldMethod, newMethod string) (modified bool)
function declaration utilities
HasFieldInFuncDeclParams(df *dst.File, funcName string, field *dst.Field) (ret bool)
DeleteFieldFromFuncDeclParams(df *dst.File, funcName string, field *dst.Field) (modified bool)
AddFieldToFuncDeclParams(df *dst.File, funcName string, field *dst.Field, pos int) (modified bool)

TODO

-[ ] support scope

Documentation

Overview

Package gorefactor provides some basic utilities for you to do code migration on large code base written in golang.

Index

Constants

This section is empty.

Variables

View Source
var EmptyScope = Scope{}

Functions

func AddArgToCallExpr

func AddArgToCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr, pos int) (modified bool)

AddArgToCallExpr adds given arg, to the function call's argument list, in the given position

func AddFieldToFuncDeclParams

func AddFieldToFuncDeclParams(df *dst.File, funcName string, field *dst.Field, pos int) (modified bool)

AddFieldToFuncDeclParams adds given field, to the declaration params of the function, in the given position

func AddFieldToFuncLitParams added in v0.0.7

func AddFieldToFuncLitParams(df *dst.File, scope Scope, field *dst.Field, pos int) (modified bool)

AddFieldToFuncLitParams add statement to anonymous function params

func AddStmtToFuncBody

func AddStmtToFuncBody(df *dst.File, funcName string, stmt dst.Stmt, pos int) (modified bool)

AddStmtToFuncBody adds given statement, to the body of function, in the given position

func AddStmtToFuncBodyAfter added in v0.0.2

func AddStmtToFuncBodyAfter(df *dst.File, funcName string, stmt, refStmt dst.Stmt) (modified bool)

AddStmtToFuncBodyAfter adds given statement, to the function body, after the position of refStmt, if refStmt not found, nothing will happen

func AddStmtToFuncBodyBefore added in v0.0.2

func AddStmtToFuncBodyBefore(df *dst.File, funcName string, stmt, refStmt dst.Stmt) (modified bool)

AddStmtToFuncBodyBefore adds given statement, to the function body, before the position of refStmt. if refStmt not found, nothing will happen

func AddStmtToFuncBodyEnd

func AddStmtToFuncBodyEnd(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)

AddStmtToFuncBodyEnd adds given statement, to the end of function body

func AddStmtToFuncBodyStart

func AddStmtToFuncBodyStart(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)

AddStmtToFuncBodyStart adds given statement, to the start of function body

func AddStmtToFuncLitBody added in v0.0.7

func AddStmtToFuncLitBody(df *dst.File, scope Scope, stmt dst.Stmt, pos int) (modified bool)

AddStmtToFuncLitBody add statement to anonymous function body

func DeleteArgFromCallExpr

func DeleteArgFromCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr) (modified bool)

DeleteArgFromCallExpr deletes any arg, in the function call's argument list, that is semantically equal to the given arg.

func DeleteFieldFromFuncDeclParams

func DeleteFieldFromFuncDeclParams(df *dst.File, funcName string, field *dst.Field) (modified bool)

DeleteFieldFromFuncDeclParams deletes any field, in the declaration params of the function, that is semantically equal to given field

func DeleteSelectorExprFromFuncBody added in v0.0.4

func DeleteSelectorExprFromFuncBody(df *dst.File, funcName string, selectorExpr dst.Expr) (modified bool)

DeleteCallExprFromFuncBody deletes any SelectorExpr equal to the given one, inside the body of function.

func DeleteStmtFromFuncBody

func DeleteStmtFromFuncBody(df *dst.File, funcName string, stmt dst.Stmt) (modified bool)

DeleteStmtFromFuncBody deletes any statement, inside the body of function, that is semantically equal to the given statement.

func FprintFile

func FprintFile(out io.Writer, df *dst.File) error

FprintFile writes the *dst.File out to io.Writer

func HasArgInCallExpr

func HasArgInCallExpr(df *dst.File, scope Scope, funcName string, arg dst.Expr) (ret bool)

HasArgInCallExpr checks if the arguments of the function call has given arg

func HasFieldInFuncDeclParams

func HasFieldInFuncDeclParams(df *dst.File, funcName string, field *dst.Field) (ret bool)

HasFieldInFuncDeclParams checks if the declaration params of the function, contains the given field

func HasStmtInsideFuncBody

func HasStmtInsideFuncBody(df *dst.File, funcName string, stmt dst.Stmt) (ret bool)

HasStmtInsideFuncBody checks if the body of function has given statement

func ParseSrcFile

func ParseSrcFile(filename string) (df *dst.File, err error)

ParseSrcFile parses the given go src filename, in the form of valid path, into *dst.File

func ParseSrcFileFromBytes

func ParseSrcFileFromBytes(src []byte) (df *dst.File, err error)

ParseSrcFileFromBytes parses the given go src file, in the form of bytes, into *dst.File

func SetMethodOnReceiver added in v0.0.7

func SetMethodOnReceiver(df *dst.File, scope Scope, receiver, oldMethod, newMethod string) (modified bool)

Types

type Scope added in v0.0.8

type Scope struct {
	FuncName string
	// contains filtered or unexported fields
}

func (Scope) IsInScope added in v0.0.8

func (s Scope) IsInScope() bool

func (*Scope) TryEnterScope added in v0.0.8

func (s *Scope) TryEnterScope(node dst.Node) (ok bool)

func (*Scope) TryLeaveScope added in v0.0.8

func (s *Scope) TryLeaveScope(node dst.Node) (ok bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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