Documentation ¶
Index ¶
- func Equal(t0 Type, t1 Type) bool
- func Identical(t0, t1 Type) bool
- func IdenticalIgnoreTags(t0, t1 Type) bool
- func Implements(t Type, inter Type) bool
- type ChanDir
- type Importer
- func (i *Importer) FileSet() *token.FileSet
- func (i *Importer) Import(path, src string) (Type, error)
- func (i *Importer) ImportBuild(path string, src string) (*build.Package, error)
- func (i *Importer) ImportFile(path string, f *ast.File) (Type, error)
- func (i *Importer) ImportPackage(path string, pkg *ast.Package) (Type, error)
- func (i *Importer) ImportSource(path string, src []byte) (Type, error)
- type Kind
- type Option
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IdenticalIgnoreTags ¶ added in v0.4.2
IdenticalIgnoreTags reports whether t0 and t1 are identical types if tags are ignored.
func Implements ¶ added in v0.4.2
Implements reports whether type inter implements interface t.
Types ¶
type ChanDir ¶
type ChanDir int
ChanDir represents a channel type's direction.
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer Go source type analyzer
func (*Importer) ImportBuild ¶
ImportBuild returns details about the Go package named by the import path.
func (*Importer) ImportFile ¶ added in v0.1.0
ImportFile returns go package scope
func (*Importer) ImportPackage ¶ added in v0.1.0
ImportPackage returns go package scope
type Kind ¶
type Kind uint8
Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind.
const ( Invalid Kind = iota Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Uintptr Float32 Float64 Complex64 Complex128 String Byte Rune Error Array Chan Func Interface Map Ptr Slice Struct Field // a Struct Field Scope // package or func body Declaration // a top-level function, variable, or constant. )
Define kind
type Option ¶ added in v0.4.2
type Option func(i *Importer)
Option some basic options
func ErrorHandler ¶
ErrorHandler returns the error handler option
func WithCommentLocator ¶ added in v0.1.0
func WithCommentLocator() Option
WithCommentLocator sets comment locator
type Type ¶
type Type interface { // String returns a string representation of the type. // The string representation may use shortened package names // (e.g., base64 instead of "encoding/base64") and is not // guaranteed to be unique among types. To test for type identity, // compare the Types directly. String() string // PkgPath returns a named type's package path, that is, the import path // that uniquely identifies the package, such as "encoding/base64". // If the type was predeclared (string, error) or unnamed (*T, struct{}, []int), // the package path will be the empty string. PkgPath() string // IsGoroot returns package is found in Go root IsGoroot() bool // Name returns the type's name within its package. // It returns an empty string for unnamed types. Name() string // Kind returns the specific kind of this type. Kind() Kind // Key returns a map type's key type. // It panics if the type's Kind is not Map. Key() Type // Elem returns a type's element type. // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice. Elem() Type // Declaration returns a type's declaration. // It panics if the type's Kind is not declaration. Declaration() Type // Tag returns a field type's tag. // It panics if the type's Kind is not Field. Tag() reflect.StructTag // Len returns an array type's length. // It panics if the type's Kind is not Array. Len() int // Value returns a type's value. // Only get constants Value() string // ChanDir returns a channel type's direction. // It panics if the type's Kind is not Chan. ChanDir() ChanDir // Out returns the type of a function type's i'th output parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumOut()). Out(int) Type // NumOut returns a function type's output parameter count. // It panics if the type's Kind is not Func. NumOut() int // In returns the type of a function type's i'th input parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumIn()). In(int) Type // NumIn returns a function type's input parameter count. // It panics if the type's Kind is not Func. NumIn() int // IsVariadic reports whether a function type's final input parameter // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's // implicit actual type []T. // // For concreteness, if t represents func(x int, y ... float64), then // // t.NumIn() == 2 // t.In(0) is the reflect.Type for "int" // t.In(1) is the reflect.Type for "[]float64" // t.IsVariadic() == true // // IsVariadic panics if the type's Kind is not Func. IsVariadic() bool // Field returns a struct type's i'th field. // It panics if the type's Kind is not Struct. // It panics if i is not in the range [0, NumField()). Field(int) Type // FieldByName returns the struct field with the given name // and a boolean indicating if the field was found. FieldByName(string) (Type, bool) // NumField returns a struct type's field count. // It panics if the type's Kind is not Struct. NumField() int // IsAnonymous returns is an embedded field // It panics if the type's Kind is not Field. IsAnonymous() bool // Method returns the i'th method in the type's method set. // Not contain anonymo // It panics if i is not in the range [0, NumMethod()). // // For a non-interface type T or *T, the returned Method's Type and Func // fields describe a function whose first argument is the receiver. // // For an interface type, the returned Method's Type field gives the // method signature, without a receiver, and the Func field is nil. Method(int) Type // MethodByName returns the method with that name in the type's // method set and a boolean indicating if the method was found. // // For a non-interface type T or *T, the returned Method's Type and Func // fields describe a function whose first argument is the receiver. // // For an interface type, the returned Method's Type field gives the // method signature, without a receiver, and the Func field is nil. MethodByName(string) (Type, bool) // NumMethod returns the number of exported methods in the type's method set. // Not contain anonymo NumMethod() int // Child returns a scope type's i'th child. // It panics if i is not in the range [0, NumChild()). Child(int) Type // ChildByName returns the scope with the given name // and a boolean indicating if the child was found. ChildByName(string) (Type, bool) // NumChild returns a scope type's child count. NumChild() int // Origin returns the type's origin data within its package. Origin() ast.Node // Doc returns the type's doc within its package. Doc() *ast.CommentGroup // Comment returns the type's comment within its package. Comment() *ast.CommentGroup }
Type is the representation of a Go type.
Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic.
Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types.
Source Files ¶
- builtinfunc.go
- builtinfunc_string.go
- chandir.go
- chandir_string.go
- check.go
- constant.go
- importer.go
- info.go
- kind.go
- kind_string.go
- misc.go
- option.go
- parser.go
- parser_types.go
- types.go
- types_alias.go
- types_array.go
- types_builtin.go
- types_chan.go
- types_comment_locator.go
- types_declaration.go
- types_func.go
- types_importer.go
- types_interface.go
- types_map.go
- types_named.go
- types_origin.go
- types_ptr.go
- types_scope.go
- types_selector.go
- types_slice.go
- types_struct.go
- types_struct_field.go
- types_tuple.go
- types_value_bind.go
- types_value_pair.go