parser

package
v0.44.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LcFirst added in v0.6.0

func LcFirst(str string) string

func UcFirst added in v0.6.0

func UcFirst(str string) string

Types

type DeclResult added in v0.5.0

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

func MakeDeclResult added in v0.5.0

func MakeDeclResult() DeclResult

type ExprResult added in v0.5.0

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

func MakeExprResult added in v0.5.0

func MakeExprResult() ExprResult

func (ExprResult) Merge added in v0.6.0

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 added in v0.5.0

type FieldResult struct {
	RecvName string

	Fields []Field
}

func MakeFieldResult added in v0.5.0

func MakeFieldResult() FieldResult

type FileResult added in v0.5.0

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

func MakeFileResult added in v0.5.0

func MakeFileResult() FileResult

type Func added in v0.6.0

type Func struct {
	Origin *types.Func

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

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

func (Func) PrintCallGraph added in v0.6.0

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

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

func (*Func) Set added in v0.6.0

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

type IIIIIIIInfo

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

IIIIIIIInfo 别名测试

type IInspector added in v0.5.0

type IInspector interface {
	InspectFile(file *ast.File) (result FileResult)
	InspectPkg(pkg *packages.Package) Package
}

type IInspectorMock added in v0.5.0

type IInspectorMock interface {
	InspectFile(file *ast.File) (result FileResult)
	InspectPkg(pkg *packages.Package) Package
}

type IInterface added in v0.5.0

type IInterface interface{ MakeMock() string }

type IInterfaceMock added in v0.5.0

type IInterfaceMock interface{ MakeMock() string }

type IPackage added in v0.5.0

type IPackage interface {
	NewGoFileWithSuffix(suffix string) (file string)
	SaveInterface(file string) error
	SaveMock(file string) error
}

type IPackageMock added in v0.5.0

type IPackageMock interface {
	NewGoFileWithSuffix(suffix string) (file string)
	SaveInterface(file string) error
	SaveMock(file string) error
}

type IPackages added in v0.5.0

type IPackages interface {
	LookupPkg(name string) (Package, bool)
}

type IPackagesMock added in v0.5.0

type IPackagesMock interface {
	LookupPkg(name string) (Package, bool)
}

type IParser

type IParser interface {
	GetPkgInfo() PkgInfo
	ParseAST(importPath string) (structs []Struct, err error)
	ParseByGoPackages(patterns ...string) (result Packages, err error)
}

type IParserMock added in v0.5.0

type IParserMock interface {
	GetPkgInfo() PkgInfo
	ParseAST(importPath string) (structs []Struct, err error)
	ParseByGoPackages(patterns ...string) (result Packages, err error)
}

type IPkgInfo

type IPkgInfo interface {
	GetDir() string
	GetPkgName() string
}

type IPkgInfoMock added in v0.5.0

type IPkgInfoMock interface {
	GetDir() string
	GetPkgName() string
}

type IStruct

type IStruct interface {
	Demo(in types.Array) types.Basic
	MakeInterface() string
	PointerMethod(in types.Basic) types.Slice
	String(f Field, ip importpath.ImportPath)
	TypeAlias(p Field, ip importpath.ImportPath)
}

type IStructMock added in v0.5.0

type IStructMock interface {
	Demo(in types.Array) types.Basic
	MakeInterface() string
	PointerMethod(in types.Basic) types.Slice
	String(f Field, ip importpath.ImportPath)
	TypeAlias(p Field, ip importpath.ImportPath)
}

type ImportPathAlias

type ImportPathAlias = importpath.ImportPath

type InspectOption added in v0.5.0

type InspectOption struct {
	Parser *Parser
}

type Inspector added in v0.5.0

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

func NewInspector added in v0.5.0

func NewInspector(opt InspectOption) *Inspector

func (*Inspector) InspectFile added in v0.5.0

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

func (*Inspector) InspectPkg added in v0.5.0

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

type InspectorMock added in v0.5.0

type InspectorMock struct {
	InspectFileFunc func(file *ast.File) (result FileResult)

	InspectPkgFunc func(pkg *packages.Package) Package
}

func (*InspectorMock) InspectFile added in v0.5.0

func (mockRecv *InspectorMock) InspectFile(file *ast.File) (result FileResult)

func (*InspectorMock) InspectPkg added in v0.5.0

func (mockRecv *InspectorMock) InspectPkg(pkg *packages.Package) Package

type InspectorMockMock added in v0.5.0

type InspectorMockMock struct {
	InspectFileFunc func(file *ast.File) (result FileResult)

	InspectPkgFunc func(pkg *packages.Package) Package
}

func (*InspectorMockMock) InspectFile added in v0.5.0

func (mockRecv *InspectorMockMock) InspectFile(file *ast.File) (result FileResult)

func (*InspectorMockMock) InspectPkg added in v0.5.0

func (mockRecv *InspectorMockMock) InspectPkg(pkg *packages.Package) Package

type Interface added in v0.5.0

type Interface struct {
	*types.Interface

	PkgPath    string
	PkgName    string
	Name       string
	TypeParams *ast.FieldList
	Methods    []Method // 方法列表
}

func (Interface) MakeMock added in v0.5.0

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

func (Interface) RemoveFirst added in v0.31.1

func (s Interface) RemoveFirst(c string) string

type InterfaceMock added in v0.5.0

type InterfaceMock struct {
	MakeMockFunc func() string
}

func (*InterfaceMock) MakeMock added in v0.5.0

func (mockRecv *InterfaceMock) MakeMock() string

type InterfaceMockMock added in v0.5.0

type InterfaceMockMock struct {
	MakeMockFunc func() string
}

func (*InterfaceMockMock) MakeMock added in v0.5.0

func (mockRecv *InterfaceMockMock) MakeMock() string

type Ivisitor

type Ivisitor interface {
	Visit(node ast.Node) (w ast.Visitor)
}

type IvisitorMock added in v0.5.0

type IvisitorMock interface {
	Visit(node ast.Node) (w ast.Visitor)
}

type Method

type Method = Func

type Op added in v0.6.0

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"
	OpProxy             Op = "proxy"
)

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 // 替换调用表达式

	Mode string // 模式:normal offsite
}

Option 选项

type Package added in v0.5.0

type Package struct {
	*packages.Package

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

func (Package) NewGoFileWithSuffix added in v0.5.0

func (pkg Package) NewGoFileWithSuffix(mode, dir, suffix string) (file string)

func (Package) SaveInterface added in v0.5.0

func (pkg Package) SaveInterface(file string) error

func (Package) SaveMock added in v0.5.0

func (pkg Package) SaveMock(mode, dir, file string) error

type PackageMock added in v0.5.0

type PackageMock struct {
	NewGoFileWithSuffixFunc func(suffix string) (file string)

	SaveInterfaceFunc func(file string) error

	SaveMockFunc func(file string) error
}

func (*PackageMock) NewGoFileWithSuffix added in v0.5.0

func (mockRecv *PackageMock) NewGoFileWithSuffix(suffix string) (file string)

func (*PackageMock) SaveInterface added in v0.5.0

func (mockRecv *PackageMock) SaveInterface(file string) error

func (*PackageMock) SaveMock added in v0.5.0

func (mockRecv *PackageMock) SaveMock(file string) error

type PackageMockMock added in v0.5.0

type PackageMockMock struct {
	NewGoFileWithSuffixFunc func(suffix string) (file string)

	SaveInterfaceFunc func(file string) error

	SaveMockFunc func(file string) error
}

func (*PackageMockMock) NewGoFileWithSuffix added in v0.5.0

func (mockRecv *PackageMockMock) NewGoFileWithSuffix(suffix string) (file string)

func (*PackageMockMock) SaveInterface added in v0.5.0

func (mockRecv *PackageMockMock) SaveInterface(file string) error

func (*PackageMockMock) SaveMock added in v0.5.0

func (mockRecv *PackageMockMock) SaveMock(file string) error

type Packages added in v0.5.0

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

func (Packages) LookupPkg added in v0.5.0

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

type PackagesMock added in v0.5.0

type PackagesMock struct {
	LookupPkgFunc func(name string) (Package, bool)
}

func (*PackagesMock) LookupPkg added in v0.5.0

func (mockRecv *PackagesMock) LookupPkg(name string) (Package, bool)

type PackagesMockMock added in v0.5.0

type PackagesMockMock struct {
	LookupPkgFunc func(name string) (Package, bool)
}

func (*PackagesMockMock) LookupPkg added in v0.5.0

func (mockRecv *PackagesMockMock) LookupPkg(name string) (Package, bool)

type Parser

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

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

func New

func New(opt Option) *Parser

New 新建

func (*Parser) GetPkgInfo

func (p *Parser) GetPkgInfo() PkgInfo

func (*Parser) GetStandardPackages added in v0.6.0

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

func (*Parser) ParseAST

func (p *Parser) ParseAST(importPath string) (structs []Struct, err error)

ParseAST 解析导入路径的ast,返回目录里的结构体信息

func (*Parser) ParseByGoPackages added in v0.5.0

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

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

type ParserMock added in v0.5.0

type ParserMock struct {
	GetPkgInfoFunc func() PkgInfo

	ParseASTFunc func(importPath string) (structs []Struct, err error)

	ParseByGoPackagesFunc func(patterns ...string) (result Packages, err error)
}

func (*ParserMock) GetPkgInfo added in v0.5.0

func (mockRecv *ParserMock) GetPkgInfo() PkgInfo

func (*ParserMock) ParseAST added in v0.5.0

func (mockRecv *ParserMock) ParseAST(importPath string) (structs []Struct, err error)

func (*ParserMock) ParseByGoPackages added in v0.5.0

func (mockRecv *ParserMock) ParseByGoPackages(patterns ...string) (result Packages, err error)

type ParserMockMock added in v0.5.0

type ParserMockMock struct {
	GetPkgInfoFunc func() PkgInfo

	ParseASTFunc func(importPath string) (structs []Struct, err error)

	ParseByGoPackagesFunc func(patterns ...string) (result Packages, err error)
}

func (*ParserMockMock) GetPkgInfo added in v0.5.0

func (mockRecv *ParserMockMock) GetPkgInfo() PkgInfo

func (*ParserMockMock) ParseAST added in v0.5.0

func (mockRecv *ParserMockMock) ParseAST(importPath string) (structs []Struct, err error)

func (*ParserMockMock) ParseByGoPackages added in v0.5.0

func (mockRecv *ParserMockMock) ParseByGoPackages(patterns ...string) (result Packages, err error)

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 PkgInfoMock added in v0.5.0

type PkgInfoMock struct {
	GetDirFunc func() string

	GetPkgNameFunc func() string
}

func (*PkgInfoMock) GetDir added in v0.5.0

func (mockRecv *PkgInfoMock) GetDir() string

func (*PkgInfoMock) GetPkgName added in v0.5.0

func (mockRecv *PkgInfoMock) GetPkgName() string

type PkgInfoMockMock added in v0.5.0

type PkgInfoMockMock struct {
	GetDirFunc func() string

	GetPkgNameFunc func() string
}

func (*PkgInfoMockMock) GetDir added in v0.5.0

func (mockRecv *PkgInfoMockMock) GetDir() string

func (*PkgInfoMockMock) GetPkgName added in v0.5.0

func (mockRecv *PkgInfoMockMock) GetPkgName() string

type SpecResult added in v0.5.0

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

func MakeSpecResult added in v0.5.0

func MakeSpecResult() SpecResult

type StmtResult added in v0.5.0

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

func MakeStmtResult added in v0.5.0

func MakeStmtResult() StmtResult

func (StmtResult) Merge added in v0.6.0

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

func (StmtResult) MergeExprResult added in v0.6.0

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 added in v0.5.0

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

func (Struct) String

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

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

func (Struct) TypeAlias

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

type StructMock added in v0.5.0

type StructMock struct {
	DemoFunc func(in types.Array) types.Basic

	MakeInterfaceFunc func() string

	PointerMethodFunc func(in types.Basic) types.Slice

	StringFunc func(f Field, ip importpath.ImportPath)

	TypeAliasFunc func(p Field, ip importpath.ImportPath)
}

func (*StructMock) Demo added in v0.5.0

func (mockRecv *StructMock) Demo(in types.Array) types.Basic

func (*StructMock) MakeInterface added in v0.5.0

func (mockRecv *StructMock) MakeInterface() string

func (*StructMock) PointerMethod added in v0.5.0

func (mockRecv *StructMock) PointerMethod(in types.Basic) types.Slice

func (*StructMock) String added in v0.5.0

func (mockRecv *StructMock) String(f Field, ip importpath.ImportPath)

func (*StructMock) TypeAlias added in v0.5.0

func (mockRecv *StructMock) TypeAlias(p Field, ip importpath.ImportPath)

type StructMockMock added in v0.5.0

type StructMockMock struct {
	DemoFunc func(in types.Array) types.Basic

	MakeInterfaceFunc func() string

	PointerMethodFunc func(in types.Basic) types.Slice

	StringFunc func(f Field, ip importpath.ImportPath)

	TypeAliasFunc func(p Field, ip importpath.ImportPath)
}

func (*StructMockMock) Demo added in v0.5.0

func (mockRecv *StructMockMock) Demo(in types.Array) types.Basic

func (*StructMockMock) MakeInterface added in v0.5.0

func (mockRecv *StructMockMock) MakeInterface() string

func (*StructMockMock) PointerMethod added in v0.5.0

func (mockRecv *StructMockMock) PointerMethod(in types.Basic) types.Slice

func (*StructMockMock) String added in v0.5.0

func (mockRecv *StructMockMock) String(f Field, ip importpath.ImportPath)

func (*StructMockMock) TypeAlias added in v0.5.0

func (mockRecv *StructMockMock) TypeAlias(p Field, ip importpath.ImportPath)

type TokenResult added in v0.5.0

type TokenResult struct {
}

func InspectToken added in v0.5.0

func InspectToken(tok token.Token) (result TokenResult)

Directories

Path Synopsis
a
b
big

Jump to

Keyboard shortcuts

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