parser

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 25 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(fileName, content string, formatOnly bool) (string, error)

func LcFirst

func LcFirst(str string) string

func ReplaceNameof added in v0.35.0

func ReplaceNameof(pkg string)

func UcFirst

func UcFirst(str string) string

Types

type DeclResult

type DeclResult struct {
	// contains filtered or unexported fields
}

func MakeDeclResult

func MakeDeclResult() DeclResult

type ExprResult

type ExprResult struct {
	Fields []Field
	// contains filtered or unexported fields
}

func MakeExprResult

func MakeExprResult() ExprResult

func (ExprResult) Merge

func (er ExprResult) Merge(oer ExprResult) (ner ExprResult)

type Field

type Field struct {
	Id        string // 唯一标志
	Name      string // 名称
	Anonymous bool   // 是否匿名

	TypesType types.Type // 原始类型
	Type      string     // 类型,包含包导入路径

	Tag         string        `json:"tag"` // 结构体字段的tag
	TagBasicLit *ast.BasicLit // ast的tag类型

	Doc     string // 文档
	Comment string // 注释
}

Field 字段

type FieldResult

type FieldResult struct {
	RecvName string

	Fields []Field
}

func MakeFieldResult

func MakeFieldResult() FieldResult

type FileResult

type FileResult struct {
	// contains filtered or unexported fields
}

func MakeFileResult

func MakeFileResult() FileResult

type Func

type Func struct {
	Origin *types.Func

	PkgPath   string // 包路径
	Recv      string // 方法的receiver
	Name      string
	Signature string

	Calls []Func // 调用的函数/方法
}

func (Func) PrintCallGraph

func (f Func) PrintCallGraph(ignore []string, depth int)

PrintCallGraph 打印调用图,用ignore忽略包,用depth指定深度

func (*Func) Set

func (f *Func) Set(fm map[string]Func, depth int)

type IIIIIIIInfo

type IIIIIIIInfo = Field // 别名测试注释

IIIIIIIInfo 别名测试

type ImportPath

type ImportPath struct {
}

func (*ImportPath) FindAllModule

func (p *ImportPath) FindAllModule(dir string) (mods []Module, err error)

FindAllModule find all module in dir

func (*ImportPath) GetByCurrentDir

func (p *ImportPath) GetByCurrentDir() (path string, err error)

GetCurrentDirPath get import path in current directory

func (*ImportPath) GetCurrentDirModFilePath

func (p *ImportPath) GetCurrentDirModFilePath() (modDir, modPath string, err error)

func (*ImportPath) GetModFilePath

func (p *ImportPath) GetModFilePath(dir string) (modDir, modPath string, err error)

func (*ImportPath) SplitImportPathWithType

func (p *ImportPath) SplitImportPathWithType(importPathWithType string) (string, string)

type ImportPathAlias

type ImportPathAlias = ImportPath

type InspectOption

type InspectOption struct {
	Parser *Parser
}

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

func NewInspector

func NewInspector(opt InspectOption) *Inspector

func (*Inspector) InspectFile

func (ins *Inspector) InspectFile(file *ast.File) (result FileResult)

func (*Inspector) InspectPkg

func (ins *Inspector) InspectPkg(pkg *packages.Package) Package

type Interface

type Interface struct {
	*types.Interface

	PkgPath string
	PkgName string
	Name    string
	Methods []Method // 方法列表
}

func (Interface) MakeMock

func (s Interface) MakeMock() (string, map[string]struct{})

type Method

type Method = Func

type Module

type Module struct {
	modfile.Module

	RelDir string
}

type Op

type Op string
const (
	OpReplace           Op = "replace"
	OpMock              Op = "mock"
	OpImpl              Op = "impl"
	OpInterface         Op = "interface"
	OpCallgraph         Op = "callgraph"
	OpGenProject        Op = "genproject"
	OpGenProxy          Op = "genproxy"
	OpFind              Op = "find"
	OpGenStructFromSQL  Op = "sql2struct"
	OpGenDataForTable   Op = "gendata"
	OpGenStructFromJSON Op = "json2struct"
)

type Option

type Option struct {
	Op Op // 操作,如生成接口,生成实现等

	Filter            func(os.FileInfo) bool // 过滤器
	UseSourceImporter bool                   // 使用源码importer

	ReplaceImportPath bool // 替换导入路径
	FromPath          string
	ToPath            string
	Output            io.Writer

	NeedCall bool // 需要记录调用了哪些函数/方法

	ReplaceCallExpr bool // 替换调用表达式
}

type Package

type Package struct {
	*packages.Package

	Funcs      []Func
	Structs    []Struct
	Interfaces []Interface
}

func (Package) NewGoFileWithSuffix

func (pkg Package) NewGoFileWithSuffix(suffix string) (file string)

func (Package) SaveInterface

func (pkg Package) SaveInterface(file string) error

func (Package) SaveMock

func (pkg Package) SaveMock(file string) error

type Packages

type Packages struct {
	Patterns []string
	Pkgs     []Package
}

func (Packages) LookupPkg

func (pkgs Packages) LookupPkg(name string) (Package, bool)

type Parser

type Parser struct {
	PkgInfo
	// contains filtered or unexported fields
}

Parser 解析器 解析指定的包导入路径,获取go源码信息

func NewParser

func NewParser(opt Option) *Parser

func (*Parser) GetPkgInfo

func (p *Parser) GetPkgInfo() PkgInfo

func (*Parser) GetStandardPackages

func (p *Parser) GetStandardPackages() []string

func (*Parser) ParseByGoPackages

func (p *Parser) ParseByGoPackages(patterns ...string) (result Packages, err error)

ParseByGoPackages 使用x/tools/go/packages解析指定导入路径

type PkgInfo

type PkgInfo struct {
	// contains filtered or unexported fields
}

func (PkgInfo) GetDir

func (i PkgInfo) GetDir() string

func (PkgInfo) GetPkgName

func (i PkgInfo) GetPkgName() string

type SpecResult

type SpecResult struct {
	// contains filtered or unexported fields
}

func MakeSpecResult

func MakeSpecResult() SpecResult

type StmtResult

type StmtResult struct {
	// contains filtered or unexported fields
}

func MakeStmtResult

func MakeStmtResult() StmtResult

func (StmtResult) Merge

func (er StmtResult) Merge(oer StmtResult) (ner StmtResult)

func (StmtResult) MergeExprResult

func (er StmtResult) MergeExprResult(oer ExprResult) (ner StmtResult)

type Struct

type Struct struct {
	// 如:github.com/pkg/errors
	PkgPath string `json:"pkgPath" toml:"pkg_path"` // 包路径

	// 如: errors
	PkgName string // 包名

	Field

	Fields  []Field  // 字段列表
	Methods []Method // 方法列表
}

Struct 结构体

func (Struct) Demo

func (s Struct) Demo(in types.Array) types.Basic

func (Struct) MakeInterface

func (s Struct) MakeInterface() string

MMakeInterface 根据结构体的方法生成相应接口

func (*Struct) PointerMethod

func (s *Struct) PointerMethod(in types.Basic) types.Slice

func (Struct) String

func (s Struct) String(f Field, ip ImportPath)

让它传入本包里的另外一个结构体 传入本项目其它包的结构体

func (Struct) TypeAlias

func (s Struct) TypeAlias(p IIIIIIIInfo, ip ImportPathAlias)

type TokenResult

type TokenResult struct {
}

Jump to

Keyboard shortcuts

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