parse

package
v0.0.0-...-4921599 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface struct {
	Name    string
	Methods []Method
}

Interface represents an interface defined in a Package.

func (*Interface) Len

func (intf *Interface) Len() int

Len returns the number of methods.

func (*Interface) String

func (intf *Interface) String() string

type Method

type Method struct {
	Name    string
	Params  Params
	Results Results
}

Method represents a method of some interface.

func (*Method) Arity

func (meth *Method) Arity() int

Arity returns the number of required (non-variadic) method parameters.

func (*Method) Len

func (meth *Method) Len() int

Len returns the number of return values, including 0 if none.

func (*Method) String

func (meth *Method) String() string

String returns the method's name.

type Package

type Package struct {
	// Absolute path to this package
	Dir string
	// All package names declared by any source file (usually just 1 or 2!)
	Names []string
	// All interfaces defined in any source file
	Interfaces []Interface
}

Package is a package that contains interfaces.

func NewPackage

func NewPackage(path string) (*Package, error)

NewPackage loads *.go from a given directory and returns type information about the package defined in it.

func (*Package) Len

func (lp *Package) Len() int

Len is the number of interfaces defined in the sources.

func (*Package) Name

func (lp *Package) Name() string

Name is the package name that generated source files should use.

func (*Package) String

func (lp *Package) String() string

String returns a pseudocode package definition.

type Param

type Param struct {
	Name string
	Type Type
}

Param is a method parameter.

type Params

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

Params is the set of parameters to a method.

func (*Params) At

func (p *Params) At(i int) *Param

At returns the parameter in a specified position i.

func (*Params) Len

func (p *Params) Len() int

Len is the number of method parameters, excluding variadic .

func (*Params) NameList

func (p *Params) NameList() string

NameList is a comma-separated list of parameter names, including variadic (without trailing dots)

func (*Params) Tuple

func (p *Params) Tuple(local string, resolver Resolver) string

Tuple is the formal parameters declaration surrounded by parentheses e.g. "(alice string, bob int)"

func (*Params) TypeList

func (p *Params) TypeList(local string, resolver Resolver) string

TypeList is a comma-separated list of parameter types, including variadic (without trailing dots)

func (*Params) Variadic

func (p *Params) Variadic() *Param

Variadic returns the variadic parameter, or nil if the method is not variadic.

type Resolver

type Resolver interface {
	// Resolve transforms an absolute path-and-typename into an imported type with
	// a package-unique nickname. The "local" package name must be given, and if
	// it is the same as the type's package's assigned nickname, the prefix is
	// omitted.
	Resolve(local, typePath string) string

	// Import idempotently adds a package to the resolver's dictionary with a
	// chosen nickname. Returns true if addition was succesful, or if the package
	// is already registered with that name.
	Import(nick, impPath string) bool

	// Imports provides a map of nickname-to-package.
	Imports() map[string]string
}

Resolver assigns unique file-local import names ("nicknames") to packages that will be imported and used in a Go source file. It works with several string representations of packages; to avoid confusion, please keep in mind the following terminology:

nick, local: one-word, file-local nicknames e.g. "os", "mypkg"
typePath: absolute type paths e.g. "/usr/local/src/foo.Widget", "sort.Interface"
impPath: relative import paths e.g. "net/url", "github.com/xeger/bar"

func NewResolver

func NewResolver() Resolver

NewResolver creates a simple resolver that keeps state with a pair of maps.

type Results

type Results []Type

Results are the type(s) returned by an interface method.

func (Results) At

func (r Results) At(i int) *Type

At returns the type of the return value at index i.

func (Results) Len

func (r Results) Len() int

Len returns the number of values returned by the method.

func (Results) NameList

func (r Results) NameList() string

NameList returns a comma-separated list of parameter names.

func (Results) Tuple

func (r Results) Tuple(local string, resolver Resolver) string

Tuple returns a comma-separated list of types enclosed in parentheses. It is suitable for printing as the return values of a method declaration.

func (Results) ZeroList

func (r Results) ZeroList(local string, resolver Resolver) string

ZeroList returns a comma-separated list of zero values that are suitable as a return value or for other purposes.

type Type

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

Type represents a Go data type.

func (Type) BareName

func (lt Type) BareName() string

BareName returns the name of ultimate, underlying basic or named type, free from any pointer/slice/map decorators or package names. For maps, it returns the underlying key type instead of the value type.

func (Type) ShortName

func (lt Type) ShortName(local string, r Resolver) string

ShortName returns the type's name as usable from within a Go source file. You must pass a Resolver to handle package import names, as well as the package name declared in the source file in which this type name will appear.

func (Type) String

func (lt Type) String() string

String returns the unmodified name of the type. It's only useful for basic types and compositions thereof; for named types, use BareName or ShortName instead.

func (Type) ZeroValue

func (lt Type) ZeroValue(local string, r Resolver) string

ZeroValue returns the zero-value literal for this type.

Jump to

Keyboard shortcuts

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