types

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2020 License: BSD-3-Clause Imports: 15 Imported by: 47

Documentation

Overview

Types infers source locations and types from Go expressions. and allows enumeration of the type's method or field members.

Index

Constants

This section is empty.

Variables

View Source
var Debug = false

When Debug is true, log messages will be printed.

View Source
var FileSet = token.NewFileSet()

When DefaultImporter is called, it adds any files to FileSet.

View Source
var Panic = true

Functions

func DeclPos

func DeclPos(obj *ast.Object) token.Pos

DeclPos computes the source position of the declaration of an object name. The result may be an invalid position if it cannot be computed (obj.Decl may be nil or not correct). This should be called ast.Object.Pos.

func DefaultImportPathToName

func DefaultImportPathToName(path, srcDir string) (string, error)

DefaultImportPathToName returns the package identifier for the given import path.

func DefaultImporter

func DefaultImporter(path string, srcDir string) *ast.Package

DefaultImporter looks for the package; if it finds it, it parses and returns it. If no package was found, it returns nil.

Types

type Importer

type Importer func(path string, srcDir string) *ast.Package

type MultiValue

type MultiValue struct {
	Types []ast.Expr
}

MultiValue represents a multiple valued Go expression - the result of a function that returns more than one value.

func (MultiValue) End

func (MultiValue) End() token.Pos

func (MultiValue) Pos

func (MultiValue) Pos() token.Pos

type Type

type Type struct {
	// Parse-tree representation of the expression's type.
	Node ast.Node

	// The kind of the expression.
	Kind ast.ObjKind

	// The path of the package that the type is relative to.
	Pkg string
	// contains filtered or unexported fields
}

Type represents the type of a Go expression. It can represent a Go package and a Go type as well as the usual expression types.

func ExprType

func ExprType(e ast.Expr, importer Importer, fs *token.FileSet) (obj *ast.Object, typ Type)

ExprType returns the type for the given expression, and the object that represents it, if there is one. All variables, methods, top level functions, packages, struct and interface members, and types have objects. The returned object can be used with DeclPos to find out the source location of the definition of the object.

func (Type) Iter

func (t Type) Iter() <-chan *ast.Object

Iter returns a channel, sends on it all the members of the type, then closes it. Members at a shallower depth will be sent first.

func (Type) Member

func (t Type) Member(name string) *ast.Object

Member looks for a member with the given name inside the type. For packages, the member can be any exported top level declaration inside the package.

func (Type) String

func (t Type) String() string

String is for debugging purposes.

func (Type) Underlying

func (typ Type) Underlying(all bool) Type

If typ represents a named type, Underlying returns the type that it was defined as. If all is true, it repeats this process until the type is not a named type.

Jump to

Keyboard shortcuts

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