parser

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImportPathAndTypeNameFromTypesType added in v0.5.0

func GetImportPathAndTypeNameFromTypesType(typesType types.Type) (string, string, string)

GetImportPathAndTypeNameFromTypesType 从types.Type解析出导入路径、类型名称、带短路径的类型 获取带path类型 如从github.com/pkg/errors.Frame解析出errors.Frame 或从*github.com/pkg/errors.Frame解析出*errors.Frame 或从[]github.com/pkg/errors.Frame解析出[]errors.Frame 或从[4]github.com/pkg/errors.Frame解析出[4]errors.Frame 或从map[github.com/pkg/errors.Frame]github.com/pkg/errors.Frame解析出map[errors.Frame]errors.Frame

Types

type Attr added in v0.2.0

type Attr string

Attr 属性

func (Attr) GetJoinTyp added in v0.2.0

func (attr Attr) GetJoinTyp(parser *Parser, pkgPath string, structs []Struct) (joinTyp, joinTypField, joinTypWithPath, joinTypFieldTyp string)

GetJoinTyp 获取join类型信息

type Command

type Command struct {
	Name  string // 名称,如:list
	Attr  Attr   // 属性,如: column
	Extra string // 额外,如: deriveType
}

Command 指令

type CommandList

type CommandList []Command

CommandList 列表

func (CommandList) ExistCommand

func (list CommandList) ExistCommand(name string) bool

ExistCommand 存在指令

func (CommandList) ExistCommandAttr

func (list CommandList) ExistCommandAttr(name string, attr Attr) bool

ExistCommandAttr 存在指令

func (CommandList) GetExtraTyp added in v0.3.0

func (list CommandList) GetExtraTyp(parser *Parser) (extraTyp, extraTypWithPath string)

GetExtraTyp 获取额外信息

func (CommandList) GetJoinTyp added in v0.2.0

func (list CommandList) GetJoinTyp(parser *Parser, pkgPath string, structs []Struct) (joinTyp, joinTypField, joinTypWithPath, joinTypFieldTyp string)

GetJoinTyp 获取join类型信息

type Field

type Field struct {
	Info
}

Field 字段

type ImportPathMap

type ImportPathMap map[string][]string

ImportPathMap 路径映射

func (ImportPathMap) Keys

func (m ImportPathMap) Keys() []string

Keys 键

func (ImportPathMap) MergeKey

func (m ImportPathMap) MergeKey(om ImportPathMap) ImportPathMap

MergeKey 合并,如果有重复键,om里的值将会覆盖m的

type Info

type Info struct {
	Name string // 名称,如:Info

	Anonymous bool // 是否匿名

	// 可以使用这个字段来断言到具体的类型,如go/types.Struct
	TypesType types.Type // go/types.Type接口

	// 如果是导入的第三方包,会包含包路径,如:github.com/pkg/errors.fundamental
	Type string // 类型,表面类型

	// 如type Status int的底下类型就是int
	UnderType string // 底下类型

	ImportPath      string // 导入路径
	TypName         string // 类型名,如果是结构体则与Name相同,如果是字段,则是字段的类型
	TypNameWithPath string // 带有导入路径的类型名称,如:parser.Info
	CanUseAsMapKey  bool   // 字段类型是否可作为map的键

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

	Commands CommandList // 指令,如list, list column, list map, list slicemap等中的一个或多个
}

Info 信息

func (Info) GetImportPathAndTypeName

func (info Info) GetImportPathAndTypeName(typesType types.Type) (
	string,
	string,
	string,
)

GetImportPathAndTypeName 获取导入路径和类型名称

func (Info) GetNotEmptyImportPathMap

func (info Info) GetNotEmptyImportPathMap() ImportPathMap

GetNotEmptyImportPathMap 获取非空导入路径映射

func (Info) GetTypNameWithPath

func (info Info) GetTypNameWithPath(pkgImportPath string) string

GetTypNameWithPath 获取带路径类型名称

func (Info) GetTypesTypeStructField added in v0.4.0

func (info Info) GetTypesTypeStructField(fieldName string) (
	typName string, typNameWithPath string,
)

GetTypesTypeStructField 获取结构体字段信息

func (*Info) InitWithTypes

func (info *Info) InitWithTypes(name, pkgPath, doc, comment string, typ types.Type)

InitWithTypes 初始化

type Option

type Option struct {
	IgnoreFileSuffix []string // 忽略文件名含有指定后缀的文件
}

Option 选项

type Parser

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

Parser 解析器,用于解析源码

func New

func New(opts ...Option) *Parser

New 新建

func (*Parser) ParsePkg

func (p *Parser) ParsePkg(pkg string) (Pkg, error)

ParsePkg 解析包,如:github.com/pkg/errors,返回包信息

type Pkg

type Pkg struct {
	Name       string // 包名
	Dir        string // 包目录
	ImportPath string // 包导入路径
	Structs    []Struct
}

Pkg 包

type Struct

type Struct struct {
	Info
	Fields []Field
}

Struct 结构体

type StructList added in v0.2.0

type StructList []Struct

StructList 列表

func (StructList) Find added in v0.2.0

func (list StructList) Find(name string) Struct

Find 找出指定名称的结构体

func (StructList) FindField added in v0.2.0

func (list StructList) FindField(name, fieldName string) Field

FindField 找出指定结构体的指定字段

Jump to

Keyboard shortcuts

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