parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Id      string // 唯一标志
	Name    string // 名称
	Type    string // 类型,包含包导入路径
	Doc     string // 文档
	Comment string // 注释
}

Field 字段

type IIIIIIIInfo

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

IIIIIIIInfo 别名测试

type IParser

type IParser interface {
	GetPkgInfo() PkgInfo
	ParseAST(importPath string) (structs []Struct, err error)
}

type IPkgInfo

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

type IStruct

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

type ImportPathAlias

type ImportPathAlias = importpath.ImportPath

type Ivisitor

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

type Method

type Method struct {
	Origin    *types.Func
	Signature string
}

type Option

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

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

Option 选项

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) ParseAST

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

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

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 Struct

type Struct struct {
	// 如:github.com/pkg/errors
	PkgPath string // 包路径

	// 如: 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) String

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

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

func (Struct) TypeAlias

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

Jump to

Keyboard shortcuts

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