pkgimport: github.com/go-pkgimport/pkgimport Index | Files

package gotype

import "github.com/go-pkgimport/pkgimport"

Index

Package 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

func Equal Uses

func Equal(t0 Type, t1 Type) bool

Equal Reports whether the type type is equal

func Identical Uses

func Identical(t0, t1 Type) bool

Identical reports whether t0 and t1 are identical types.

func IdenticalIgnoreTags Uses

func IdenticalIgnoreTags(t0, t1 Type) bool

IdenticalIgnoreTags reports whether t0 and t1 are identical types if tags are ignored.

func Implements Uses

func Implements(t Type, inter Type) bool

Implements reports whether type inter implements interface t.

func IsBuiltin Uses

func IsBuiltin(t Type) bool

IsBuiltin return it is a built-in base type

type ChanDir Uses

type ChanDir int

ChanDir represents a channel type's direction.

const (
    RecvDir ChanDir = 1 << iota         // chan<-
    SendDir                             // <-chan
    BothDir ChanDir = RecvDir | SendDir // chan
)

Define channel direction

func (ChanDir) String Uses

func (i ChanDir) String() string

type Importer Uses

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

Importer Go source type analyzer

func NewImporter Uses

func NewImporter(options ...Option) *Importer

NewImporter creates a new importer

func (*Importer) FileSet Uses

func (i *Importer) FileSet() *token.FileSet

FileSet returns the FileSet

func (*Importer) Import Uses

func (i *Importer) Import(path string, src string) (Type, error)

Import returns go package scope

func (*Importer) ImportBuild Uses

func (i *Importer) ImportBuild(path string, src string) (*build.Package, error)

ImportBuild returns details about the Go package named by the import path.

func (*Importer) ImportFile Uses

func (i *Importer) ImportFile(path string, f *ast.File) (Type, error)

ImportFile returns go package scope

func (*Importer) ImportName Uses

func (i *Importer) ImportName(path string, src string) (name string, goroot bool)

ImportName returns go package name

func (*Importer) ImportPackage Uses

func (i *Importer) ImportPackage(path string, pkg *ast.Package) (Type, error)

ImportPackage returns go package scope

func (*Importer) ImportSource Uses

func (i *Importer) ImportSource(path string, src []byte) (Type, error)

ImportSource returns go package scope

type Kind Uses

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

func (Kind) String Uses

func (i Kind) String() string

type NoGoError Uses

type NoGoError struct {
    Dir string
}

NoGoError is the error used by Import to describe a directory containing no Go source files.

func (*NoGoError) Error Uses

func (e *NoGoError) Error() string

type Option Uses

type Option func(i *Importer)

Option some basic options

func ErrorHandler Uses

func ErrorHandler(f func(error)) Option

ErrorHandler returns the error handler option

func ImportHandler Uses

func ImportHandler(f func(path, src, dir string)) Option

ImportHandler returns the import handler option

func WithCommentLocator Uses

func WithCommentLocator() Option

WithCommentLocator sets comment locator

type Type Uses

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.

Package gotype imports 13 packages (graph). Updated 2020-05-21. Refresh now. Tools for package owners.