goast

package
v0.0.0-...-4a2aed3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIgnoreStmt = errors.New("render not supported for this kind of ast.Stmt")
)

Functions

func Assert

func Assert(condition bool, errmsg string)

func FindFunction

func FindFunction(pkgs map[string]*ast.Package, funcName string) (*ast.FuncDecl, error)

ReceiverTypeOrPackageName the function to analyze, like main.main or main.(*helloworldServiceImpl).Hello

func FindMethod

func FindMethod(pkgs map[string]*ast.Package, recvType, funcName string) *ast.FuncDecl

BUG: recvType是否只检查了接受者类型,没有检查package名?

func FindPackageExportedFunction

func FindPackageExportedFunction(pkgs map[string]*ast.Package, pkgName, funcName string) (*ast.FuncDecl, error)

TODO how to seperate *Student and Student

func FindServiceExportedFunction

func FindServiceExportedFunction(pkgs map[string]*ast.Package, pkgName, recvType, funcName string) (*ast.FuncDecl, error)

func FunctionContainsStmt

func FunctionContainsStmt(fset *token.FileSet, stmt ast.Stmt) (*ast.FuncDecl, error)

FunctionContainsStmt 返回包含语句stmt的函数全名$xxx.$func

func FunctionFullName

func FunctionFullName(fset *token.FileSet, fn *ast.FuncDecl) (string, error)

FunctionFullName 返回完整函数名,如果是方法,则返回$receiver.$func,如果是包导出函数,则返回$package.$func

func FunctionNameContainsStmt

func FunctionNameContainsStmt(fset *token.FileSet, stmt ast.Stmt) (string, error)

FunctionNameContainsStmt 返回包含语句stmt的函数全名$xxx.$func

func Functions

func Functions(fset *token.FileSet, file *ast.File, filter Filter) ([]*ast.FuncDecl, error)

Functions 解析file中对应的functions,如果filter不为nil,则filter(node)返回true时才返回

func MethodReceiverTypeName

func MethodReceiverTypeName(fn *ast.FuncDecl) (string, error)

MethodReceiverTypeName 返回方法接收器类型

func PackageNameContainsFunc

func PackageNameContainsFunc(fset *token.FileSet, fn *ast.FuncDecl) (string, error)

PackageNameContainsFunc 返回方法所在包名

func PackageNameContainsStmt

func PackageNameContainsStmt(fset *token.FileSet, stmt ast.Stmt) (string, error)

PackageNameContainsStmt 返回包含语句stmt的package名

func ParseDir

func ParseDir(dir string, recursive bool) (*token.FileSet, map[string]*ast.Package, error)

ParseDir 解析目录对应package,如果recursive为true则递归解析子目录对应package, 返回map结构key为package名,value为对应的*ast.Package语法树结构.

func ParseFile

func ParseFile(file string) (*token.FileSet, *ast.File, error)

ParseFile 解析源文件返回对应fileset、astfile,如果遇到错误返回error

func PosToString

func PosToString(fset *token.FileSet, begin, end token.Pos) (string, error)

PosToString 将pos转换成对应字符串

token.NoPos==0, otherwise, token.Pos>0

func Print

func Print(filename string) error

Print print AST of `filename`

func ReceiverTypeOrPackageName

func ReceiverTypeOrPackageName(fset *token.FileSet, selectorExpr *ast.SelectorExpr) (typ string, err error)

func RenderForStmt

func RenderForStmt(fset *token.FileSet, stmt *ast.ForStmt, buf *bytes.Buffer) error

RenderForStmt 渲染forstmt,在plantuml中显示

func RenderForStmtWithConsole

func RenderForStmtWithConsole(fset *token.FileSet, stmt *ast.ForStmt) error

RenderForStmtWithConsole 渲染forstmt,在console中显示

Deprecated

func RenderFunction

func RenderFunction(funcDecl *ast.FuncDecl, fset *token.FileSet, pkgs map[string]*ast.Package) (*bytes.Buffer, error)

RenderFunction 渲染一个函数,在plantuml中显示

func RenderIfStmt

func RenderIfStmt(fset *token.FileSet, stmt *ast.IfStmt, depth int, buf *bytes.Buffer) error

RenderIfStmt 渲染ifstmt语句,在plantuml中显示

TODO: if条件,使用条件表达式,代替源码位置

func RenderIfStmtWithConsole

func RenderIfStmtWithConsole(fset *token.FileSet, stmt *ast.IfStmt, depth int) error

RenderIfStmtWithConsole 渲染ifstmt语句,在console中显示

Deprecated

func RenderStmt

func RenderStmt(fset *token.FileSet, stmt ast.Stmt) ([]byte, error)

RenderStmt render ast.Stmt with plantuml

func RenderStmtWithConsole

func RenderStmtWithConsole(fset *token.FileSet, stmt ast.Stmt) error

RenderStmtWithConsole render ast.Stmt

Deprecated

func RenderSwitchStmt

func RenderSwitchStmt(fset *token.FileSet, stmt *ast.SwitchStmt, buf *bytes.Buffer) error

RenderSwitchStmtWithConsole 渲染switchstmt,在console中显示

func RenderSwitchStmtWithConsole

func RenderSwitchStmtWithConsole(fset *token.FileSet, stmt *ast.SwitchStmt) error

RenderSwitchStmtWithConsole 渲染switchstmt,在console中显示

Deprecated

func RenderXSelStmt

func RenderXSelStmt(fset *token.FileSet, stmt ast.Stmt, depth int, buf *bytes.Buffer) error

Types

type Filter

type Filter func(fn *ast.FuncDecl) bool

Filter 如果希望过滤出该函数,则返回true

Jump to

Keyboard shortcuts

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