Documentation ¶
Index ¶
- func ErrorHandler(f func(error)) option
- func WithCommentLocator() option
- type ChanDir
- type Importer
- func (i *Importer) FileSet() *token.FileSet
- func (i *Importer) Import(path string) (Type, error)
- func (i *Importer) ImportBuild(path 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 Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
func ErrorHandler(f func(error)) option
ErrorHandler returns the error handler option
func WithCommentLocator ¶ added in v0.0.3
func WithCommentLocator() option
WithCommentLocator sets comment locator
Types ¶
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.0.3
ImportFile returns go package scope
func (*Importer) ImportPackage ¶ added in v0.0.3
ImportPackage returns go package scope
type Kind ¶
type Kind uint8
const ( Invalid Kind = iota Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Uintptr Float32 Float64 Complex64 Complex128 String Byte Rune Error // Built-in combination Array Chan Func Interface Map Ptr Slice Struct // Special Field // Struct Field Var // Scope // package or func body )
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 Var, Array, Chan, Map, Ptr, or Slice. Elem() 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
- 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_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
- types_var.go