types

package
v0.0.0-...-b1d1417 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendLabels

func AppendLabels(labelstr string, labels []string) []string

func AsImpl

func AsImpl(value ast.Expr, pkg *packages.Package) (*types.Named, bool)

func AsInterface

func AsInterface(_type ast.Expr, pkg *packages.Package) (*types.Named, bool)

func CamelCase

func CamelCase(text string) string

func Directives

func Directives(comments ast.CommentMap, pkg *packages.Package) []string

func IocGen

func IocGen(typ types.Type)

IocGen create an init function for type T.

it automatically search the dependencies tree, and fill the dependencies.

func IsError

func IsError(obj types.Type) bool

func IsErrorVar

func IsErrorVar(v *types.Var) bool

func IsInterfaceKind

func IsInterfaceKind(k TypeKind) bool

func IsStructPointerKind

func IsStructPointerKind(k TypeKind) bool

func Load

func Load(path string) *packages.Package

func SearchDirectives

func SearchDirectives(flagSet *flag.FlagSet, directives []string, patterns []string, name string, defaultValue string) string

func TypeName

func TypeName(typ types.Type) string

func TypePkg

func TypePkg(typ types.Type) *types.Package

Types

type Directive

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

func (*Directive) Cmd

func (d *Directive) Cmd() string

func (*Directive) Parse

func (d *Directive) Parse(fn func(*flag.Flag)) error

type Func

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

func NewFunc

func NewFunc(obj types.Object) (*Func, error)

func (*Func) Exported

func (f *Func) Exported() bool

func (*Func) FullName

func (f *Func) FullName() string

func (*Func) Id

func (f *Func) Id() string

func (*Func) IsValid

func (f *Func) IsValid() bool

func (*Func) Kind

func (f *Func) Kind() string

func (*Func) Labels

func (f *Func) Labels() string

func (*Func) Name

func (f *Func) Name() string

func (*Func) Param

func (f *Func) Param(i int) (*types.Var, error)

func (*Func) ParamPvd

func (f *Func) ParamPvd(param string) string

func (*Func) ParamType

func (f *Func) ParamType(i int) (types.Type, error)

func (*Func) Params

func (f *Func) Params() *types.Tuple

func (*Func) Parent

func (f *Func) Parent() *types.Scope

func (*Func) Pkg

func (f *Func) Pkg() *types.Package

func (*Func) PvdName

func (f *Func) PvdName() string

func (*Func) Recv

func (f *Func) Recv() *types.Var

func (*Func) RecvTypeParams

func (f *Func) RecvTypeParams() *types.TypeParamList

func (*Func) Result

func (f *Func) Result(i int) (*types.Var, bool)

func (*Func) ResultType

func (f *Func) ResultType(i int) (types.Type, bool)

func (*Func) Results

func (f *Func) Results() *types.Tuple

func (*Func) ReturnError

func (f *Func) ReturnError() bool

func (*Func) SetDirectives

func (f *Func) SetDirectives(directives []string)

func (*Func) SignatureString

func (f *Func) SignatureString() string

func (*Func) String

func (f *Func) String() string

func (*Func) TypeParams

func (f *Func) TypeParams() *types.TypeParamList

func (*Func) Underlying

func (f *Func) Underlying() types.Type

func (*Func) Variadic

func (f *Func) Variadic() bool

type ImplementStmt

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

ImplementStmt denote that user explicitly specify type x implements interface y

it is direvied from ast with blow convention boilerplate.

  1. var _ liu.Namer = (*guan.Guan)(nil)
  2. func (g *Guan2) Implements() liu.Namer { return g }

func NewImplementStmt

func NewImplementStmt(spec *ast.ValueSpec, pkg *packages.Package) (*ImplementStmt, bool)

func NewImplementStmtSlice

func NewImplementStmtSlice(fn *Func, pkg *packages.Package) ([]*ImplementStmt, bool)

func (*ImplementStmt) IfaceName

func (s *ImplementStmt) IfaceName() string

func (*ImplementStmt) IfacePkg

func (s *ImplementStmt) IfacePkg() *types.Package

func (*ImplementStmt) ImplName

func (s *ImplementStmt) ImplName() string

func (*ImplementStmt) ImplPkg

func (s *ImplementStmt) ImplPkg() *types.Package

func (*ImplementStmt) ImplType

func (s *ImplementStmt) ImplType() types.Type

func (*ImplementStmt) IsPointerImpl

func (s *ImplementStmt) IsPointerImpl() bool

func (*ImplementStmt) Labels

func (s *ImplementStmt) Labels() string

func (*ImplementStmt) SetDirectives

func (s *ImplementStmt) SetDirectives(directives []string)

func (*ImplementStmt) String

func (s *ImplementStmt) String() string

type Interface

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

func NewInterface

func NewInterface(obj types.Object) (*Interface, error)

func (*Interface) Complete

func (t *Interface) Complete() *types.Interface

func (*Interface) ComponentName

func (t *Interface) ComponentName() string

ComponentName return name of the component, specified by --name. default to camelCased TypeName eg: go:ioc component --name book

func (*Interface) Directives

func (t *Interface) Directives() []string

func (*Interface) EmbeddedType

func (t *Interface) EmbeddedType(i int) types.Type

func (*Interface) Empty

func (t *Interface) Empty() bool

func (*Interface) ExplicitMethod

func (t *Interface) ExplicitMethod(i int) *types.Func

func (*Interface) Exported

func (t *Interface) Exported() bool

func (*Interface) IsComparable

func (t *Interface) IsComparable() bool

func (*Interface) IsImplicit

func (t *Interface) IsImplicit() bool

func (*Interface) IsMethodSet

func (t *Interface) IsMethodSet() bool

func (*Interface) Method

func (t *Interface) Method(i int) *types.Func

func (*Interface) Name

func (t *Interface) Name() string

func (*Interface) NumEmbeddeds

func (t *Interface) NumEmbeddeds() int

func (*Interface) NumExplicitMethods

func (t *Interface) NumExplicitMethods() int

func (*Interface) NumMethods

func (t *Interface) NumMethods() int

func (*Interface) Parent

func (t *Interface) Parent() *types.Scope

func (*Interface) Pkg

func (t *Interface) Pkg() *types.Package

func (*Interface) SetDirectives

func (t *Interface) SetDirectives(directives []string)

func (*Interface) String

func (t *Interface) String() string

func (*Interface) Type

func (t *Interface) Type() types.Type

func (*Interface) Underlying

func (t *Interface) Underlying() types.Type

type Labels

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

func (*Labels) Append

func (l *Labels) Append(labels string) *Labels

func (*Labels) Labeled

func (l *Labels) Labeled(label string) bool

type ObjectKind

type ObjectKind int
const (
	KindStruct ObjectKind = iota
	KindInterface
	KindFunc
	KindVar
	KindOther
)

func Kind

func Kind(obj types.Object) ObjectKind

type Struct

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

func LoadStructs

func LoadStructs(pkg string) []*Struct

func NewStruct

func NewStruct(obj types.Object) (*Struct, error)

func (*Struct) Autowire

func (s *Struct) Autowire() bool

func (*Struct) ComponentName

func (s *Struct) ComponentName() string

ComponentName return name of the component, specified by --name. default to camelCased TypeName eg: go:ioc component --name book

func (*Struct) Exported

func (s *Struct) Exported() bool

func (*Struct) Field

func (s *Struct) Field(i int) *types.Var

func (*Struct) Fields

func (s *Struct) Fields() iter.Seq2[int, *Var]

func (*Struct) IsComponent

func (s *Struct) IsComponent() bool

func (*Struct) Method

func (s *Struct) Method(i int) *types.Func

func (*Struct) Name

func (s *Struct) Name() string

func (*Struct) NumFields

func (s *Struct) NumFields() int

func (*Struct) NumMethods

func (s *Struct) NumMethods() int

func (*Struct) Origin

func (s *Struct) Origin() *types.Named

func (*Struct) ParentScope

func (s *Struct) ParentScope() *types.Scope

func (*Struct) Pkg

func (s *Struct) Pkg() *types.Package

func (*Struct) SetDirectives

func (s *Struct) SetDirectives(directives []string)

func (*Struct) String

func (s *Struct) String() string

func (*Struct) Tag

func (s *Struct) Tag(i int) reflect.StructTag

func (*Struct) Type

func (s *Struct) Type() types.Type

func (*Struct) TypeArgs

func (s *Struct) TypeArgs() *types.TypeList

func (*Struct) TypeParams

func (s *Struct) TypeParams() *types.TypeParamList

type TypeKind

type TypeKind int
const (
	TypeKindStruct TypeKind = 1 << iota
	TypeKindPointer
	TypeKindInterface
	TypeKindFunc
	TypeKindBasic
	TypeKindNestedPointer
	TypeKindOther
	//
	TypeKindStructPointer = (TypeKindStruct | TypeKindPointer)
)

func TypeKindOf

func TypeKindOf(typ types.Type) TypeKind

type Var

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

func NewVar

func NewVar(obj types.Object) (*Var, error)

func (*Var) Directives

func (v *Var) Directives() []string

func (*Var) Name

func (v *Var) Name() string

func (*Var) SetDirectives

func (v *Var) SetDirectives(directives []string)

func (*Var) Type

func (v *Var) Type() types.Type

func (*Var) TypeKind

func (v *Var) TypeKind() TypeKind

对于func的参数和返回值来说,只应该接受部分类型, 其他一律不处理

func (*Var) TypeName

func (v *Var) TypeName() string

func (*Var) TypePkg

func (v *Var) TypePkg() *types.Package

Jump to

Keyboard shortcuts

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