Documentation
¶
Index ¶
- Constants
- func CheckPackage(modPkg string, pkg string) string
- func PackagePath(pkgName string, typeName string) string
- func ParseIt(modPkg string, pkgPath string) bool
- type AstHandler
- type Element
- func (b *Element) Clone(i ...int) *Element
- func (b *Element) ElementsAll(elementType ElementType) []*Element
- func (b *Element) Generic() bool
- func (b *Element) GetRType() reflect.Type
- func (b *Element) GetRValue() reflect.Value
- func (b *Element) GetTag() reflect.StructTag
- func (b *Element) GetValue() any
- func (b *Element) MustGetElement(elementType ElementType) *Element
- func (b *Element) Private() bool
- func (b *Element) SetRType(t reflect.Type)
- func (b *Element) SetRValue(value reflect.Value)
- func (b *Element) SetValue(i any)
- func (b *Element) Signature() string
- func (b *Element) String() string
- func (b *Element) VisitElements(elementType ElementType, check func(element *Element) bool, ...)
- func (b *Element) VisitElementsAll(elementType ElementType, f func(element *Element))
- type ElementType
- type File
- type FindHandler
- type Import
- type Parser
- func (p *Parser) AddIgnorePkg(pkg string) *Parser
- func (p *Parser) IgnorePkg(pkg string) bool
- func (p *Parser) Load(f string)
- func (p *Parser) Parse(fa ...string)
- func (p *Parser) SetParseFunctions(b bool) *Parser
- func (p *Parser) VisitStruct(check func(element *Element) bool, f func(element *Element))
- func (p *Parser) WriteOut(filename string) error
- type PkgType
Constants ¶
View Source
const ( PackageBuiltIn = "builtin" PackageThisPackage = "this" PackageOther = "other" PackageThird = "third" PackageIgnore = "ignore" )
Variables ¶
This section is empty.
Functions ¶
func CheckPackage ¶ added in v0.2.0
CheckPackage 返回某个包是何种类型的包
func PackagePath ¶ added in v0.2.0
Types ¶
type AstHandler ¶ added in v0.2.0
type AstHandler struct {
// contains filtered or unexported fields
}
AstHandler ast树解析类,一个代表一个go文件
func NewAstHandler ¶ added in v0.2.0
func NewAstHandler(f *File, modPkg string, astFile *ast.File, findHandler FindHandler) *AstHandler
func (*AstHandler) HandleElements ¶ added in v0.2.0
func (a *AstHandler) HandleElements() *AstHandler
func (*AstHandler) HandleImports ¶ added in v0.2.0
func (a *AstHandler) HandleImports() *AstHandler
func (*AstHandler) HandlePackages ¶ added in v0.2.0
func (a *AstHandler) HandlePackages() *AstHandler
func (*AstHandler) Result ¶ added in v0.2.0
func (a *AstHandler) Result() (*File, string)
Result 返回 File 对象
type Element ¶ added in v0.2.0
type Element struct {
Name string `json:",omitempty" yaml:",omitempty"`
PackagePath string `json:",omitempty" yaml:",omitempty"` //包路径
PackageName string `json:",omitempty" yaml:",omitempty"` //包名
ElementType ElementType `json:",omitempty" yaml:",omitempty"` //当前元素类型
ItemType ElementType `json:",omitempty" yaml:",omitempty"` //Item的元素类型
Item *Element `json:",omitempty" yaml:",omitempty"`
IsItemSlice bool `json:",omitempty" yaml:",omitempty"`
Index int
TagString string `json:",omitempty" yaml:",omitempty"`
TypeString string `json:",omitempty" yaml:",omitempty"` //字段类型名
ElementString string `json:",omitempty" yaml:",omitempty"`
Docs []string `json:",omitempty" yaml:",omitempty"` //上方的文档
Comment string `json:",omitempty" yaml:",omitempty"` //后方的注释
Value any `json:",omitempty" yaml:",omitempty"` //值 一般为枚举时用到
FromParent bool //表示当前元素 包含从父级继承而来的字段、方法、文档 或者 表示当前元素是继承而来
Elements map[ElementType][]*Element // 子成员 比如字段 方法 泛型类型
// contains filtered or unexported fields
}
func (*Element) ElementsAll ¶ added in v0.2.0
func (b *Element) ElementsAll(elementType ElementType) []*Element
func (*Element) MustGetElement ¶ added in v0.2.0
func (b *Element) MustGetElement(elementType ElementType) *Element
func (*Element) VisitElements ¶ added in v0.2.0
func (b *Element) VisitElements(elementType ElementType, check func(element *Element) bool, f func(element *Element))
func (*Element) VisitElementsAll ¶ added in v0.2.0
func (b *Element) VisitElementsAll(elementType ElementType, f func(element *Element))
type ElementType ¶ added in v0.2.0
type ElementType string
const ( ElementNone ElementType = "NONE" ElementStruct ElementType = "STRUCT" ElementArrayStruct ElementType = "ARRAY_STRUCT" ElementField ElementType = "FIELD" ElementConst ElementType = "CONST" ElementVar ElementType = "VAR" ElementFunc ElementType = "FUNC" ElementInterface ElementType = "INTERFACE" ElementMethod ElementType = "METHOD" ElementEnum ElementType = "ENUM" ElementReceiver ElementType = "RECEIVER" ElementGeneric ElementType = "TYPE_PARAM" ElementParam ElementType = "PARAM" ElementResult ElementType = "RESULT" ElementConstrain ElementType = "CONSTRAIN" )
type File ¶
type File struct {
Name string `json:",omitempty" yaml:",omitempty"` //文件名
FilePath string `json:",omitempty" yaml:",omitempty"` //文件路径
PackageName string `json:",omitempty" yaml:",omitempty"` //包名
PackagePath string `json:",omitempty" yaml:",omitempty"` //包路径
Docs []string `json:",omitempty" yaml:",omitempty"` //文档
Comments []string `json:",omitempty" yaml:",omitempty"` //注释
Imports []*Import `json:",omitempty" yaml:",omitempty"` //导入
Consts []*Element `json:",omitempty" yaml:",omitempty"` //常量
Vars []*Element `json:",omitempty" yaml:",omitempty"` //变量
Structs []*Element `json:",omitempty" yaml:",omitempty"` //结构体
Methods []*Element `json:"-"` //结构体方法
Funcs []*Element `json:",omitempty" yaml:",omitempty"` //函数
}
File 代表一个已解析的go文件
type FindHandler ¶ added in v0.2.0
type Import ¶
type Import struct {
Name string //名称
Alias string //别名
ImportPath string //导入路径
IsIgnore bool //是否 _ 隐式导入
}
Import 导入
type Parser ¶
func (*Parser) AddIgnorePkg ¶ added in v0.2.3
func (*Parser) SetParseFunctions ¶ added in v0.2.3
func (*Parser) VisitStruct ¶ added in v0.2.0
Click to show internal directories.
Click to hide internal directories.