ast

package
v1.4.15 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamPrefix  = "arg"
	ResultPrefix = "result"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Function

type Function struct{ *ast.Field }

Function wraps ast.Field to provide some useful methods.

func (*Function) Comment

func (f *Function) Comment() string

func (*Function) Imports

func (f *Function) Imports(pkgImports []*ast.ImportSpec) ImportGroup

Imports returns all imports of function.

func (*Function) Name

func (f *Function) Name() string

Name returns the name of the function.

func (*Function) Params

func (f *Function) Params() ValueGroup

Params returns all params of function.

func (*Function) Results

func (f *Function) Results() ValueGroup

Results returns all results of function.

func (*Function) Signature

func (f *Function) Signature() string

Signature returns the signature of function.

type Import

type Import struct{ *ast.ImportSpec }

func (*Import) String

func (i *Import) String() string

func (*Import) Usage

func (i *Import) Usage() string

Usage returns the name of the import. If the import has no name, it returns the last part of the path. For example

	 "github.com/eatmoreapple/juice"      =>  juice
     "context"						   	  =>  context
     j "github.com/eatmoreapple/juice"    =>  j

type ImportGroup

type ImportGroup []*Import

ImportGroup is a group of imports.

func (ImportGroup) String

func (ig ImportGroup) String() string

String returns the string representation of ImportGroup.

func (ImportGroup) Uniq

func (ig ImportGroup) Uniq() ImportGroup

Uniq returns a new ImportGroup with unique imports.

type Interface

type Interface struct{ *ast.InterfaceType }

func (*Interface) Imports

func (i *Interface) Imports(pkgImports []*ast.ImportSpec) ImportGroup

Imports returns all imports of interface.

func (*Interface) Methods

func (i *Interface) Methods() []*Function

Methods returns all methods of interface.

type Value

type Value struct {
	*ast.Field
	// contains filtered or unexported fields
}

Value is a value of interface, which wraps ast.Field.

func (*Value) ImportPackageName

func (v *Value) ImportPackageName() string

ImportPackageName returns the package name of the import.

func (*Value) IsBuiltInType

func (v *Value) IsBuiltInType() bool

func (*Value) Name

func (v *Value) Name() string

Name returns the name of the value.

func (*Value) String

func (v *Value) String(prefix string, index int) string

String returns the string representation of value.

func (*Value) TypeName

func (v *Value) TypeName() string

TypeName returns the type name of value. If the value is a pointer, the type name will be prefixed with "*". If the value is a slice, the type name will be prefixed with "[]".

type ValueGroup

type ValueGroup []*Value

ValueGroup is a group of Value. It is used to represent the return values of a method.

func (ValueGroup) Imports

func (vs ValueGroup) Imports(pkgImports []*ast.ImportSpec) ImportGroup

func (ValueGroup) NameAt

func (vs ValueGroup) NameAt(prefix string, index int) string

func (ValueGroup) String

func (vs ValueGroup) String(prefix string) string

Jump to

Keyboard shortcuts

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