types

package
v0.0.0-...-30a8ca0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

Variables

This section is empty.

Functions

func ExtractCommentTags

func ExtractCommentTags(lines []string, markers ...byte) (tags map[string][]string, otherLines []string)

ExtractCommentTags parses comments for lines of the form:

'marker' + "key=value".

Values are optional; "" is the default. A tag can be specified more than one time and all values are returned. If the resulting map has an entry for a key, the value (a slice) is guaranteed to have at least 1 element.

Example: if you pass '+' or '@' for 'marker', and the following lines are in the comments:

+foo=value1
+bar
+foo value2
+baz="qux"

Then this function will return:

map[string][]string{"foo":{"value1, "value2"}, "bar": {"true"}, "baz": {"qux"}}

func StringifyNode

func StringifyNode(fset *token.FileSet, node ast.Node) string

Types

type ModInfo

type ModInfo struct {
	Module  string
	Require map[string]string
}

type Module

type Module struct {
	packages.Module
}

type Package

type Package interface {
	// Pkg of go package
	Pkg() *types.Package
	// Imports of go package
	Imports() map[string]Package

	// Module of go package
	Module() *packages.Module
	// SourceDir code source absolute dir
	SourceDir() string
	// Files ast files of package
	Files() []*ast.File
	// Doc comment tags and leading comments for pos
	Doc(pos token.Pos) (map[string][]string, []string)
	// Comment trailing comments for pos
	Comment(pos token.Pos) []string

	// Eval eval expr in package
	Eval(expr ast.Expr) (types.TypeAndValue, error)

	// Constant get constant by name
	Constant(name string) *types.Const
	// Constants get all constants of package
	Constants() map[string]*types.Const
	// Type get type by name
	Type(name string) *types.TypeName
	// Types get all types of package
	Types() map[string]*types.TypeName
	// Function get function by name
	Function(name string) *types.Func
	// Functions get all signatures of package
	Functions() map[string]*types.Func
	// MethodsOf get methods of types.TypeName
	MethodsOf(n *types.Named, canPtr bool) []*types.Func
	// ResultsOf get possible resolveFuncResults of function
	ResultsOf(tpe *types.Func) (results Results, resultN int)
	// Position get position of pos
	Position(pos token.Pos) token.Position
	// ObjectOf get object of ident
	ObjectOf(id *ast.Ident) types.Object
}

type Results

type Results []TypeAndValues

func (Results) Flatten

func (results Results) Flatten() Results

func (Results) String

func (results Results) String() string

type TypeAndValue

type TypeAndValue struct {
	// Type
	Type types.Type
	// Value not nil if can be static value
	Value constant.Value
	// Expr TypeOrValue assigned by Expr
	Expr ast.Expr
	// if Expr == *ast.CallExpr, will use this to pick value
	At int
	// if Expr == *ast.CallExpr, record all available results
	From Results
}

func (TypeAndValue) String

func (r TypeAndValue) String() string

type TypeAndValues

type TypeAndValues []TypeAndValue

func (TypeAndValues) String

func (typeOrValues TypeAndValues) String() string

type TypeName

type TypeName interface {
	Pkg() *types.Package
	Name() string
	String() string
	Exported() bool
}

func MustParseRef

func MustParseRef(ref string) TypeName

func ParseRef

func ParseRef(ref string) (TypeName, error)

func Ref

func Ref(pkgPath string, name string) TypeName

type Universe

type Universe map[string]Package

func Load

func Load(patterns []string) (Universe, map[string]bool, error)

func (Universe) LocateInPackage

func (u Universe) LocateInPackage(pos token.Pos) Package

func (Universe) Package

func (u Universe) Package(pkgPath string) Package

Jump to

Keyboard shortcuts

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