generator

package
v0.0.0-...-d7285d5 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 14 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

type Fake struct {
	Packages           []*packages.Package
	Package            *packages.Package
	Target             *types.TypeName
	Mode               FakeMode
	DestinationPackage string
	Name               string
	TargetAlias        string
	TargetName         string
	TargetPackage      string
	Imports            Imports
	Methods            []Method
	Function           Method
}

Fake is used to generate a Fake implementation of an interface.

func NewFake

func NewFake(fakeMode FakeMode, targetName string, packagePath string, fakeName string, destinationPackage string, workingDir string) (*Fake, error)

NewFake returns a Fake that loads the package and finds the interface or the function.

func (*Fake) Generate

func (f *Fake) Generate(runImports bool) ([]byte, error)

Generate uses the Fake to generate an implementation, optionally running goimports on the output.

func (*Fake) IsFunction

func (f *Fake) IsFunction() bool

IsFunction indicates whether the fake is for a function..

func (*Fake) IsInterface

func (f *Fake) IsInterface() bool

IsInterface indicates whether the fake is for an interface.

type FakeMode

type FakeMode int

FakeMode indicates the type of Fake to generate.

const (
	InterfaceOrFunction FakeMode = iota
	Package
)

FakeMode can be Interface, Function, or Package.

type Import

type Import struct {
	Alias   string
	PkgPath string
}

Import is a package import with the associated alias for that package.

func (Import) String

func (i Import) String() string

String returns a string that may be used as an import line in a go source file. Imports with aliases that match the package basename are printed without an alias.

type Imports

type Imports struct {
	ByAlias   map[string]Import
	ByPkgPath map[string]Import
}

Imports indexes imports by package path and alias so that all imports have a unique alias, and no package is included twice.

func (*Imports) Add

func (i *Imports) Add(alias string, path string) Import

Add creates an import with the given alias and path, and adds it to Fake.Imports.

func (*Imports) AliasForPackage

func (i *Imports) AliasForPackage(p *types.Package) string

AliasForPackage returns a package alias for the package.

type Method

type Method struct {
	Name    string
	Params  Params
	Returns Returns
}

Method is a method of the interface.

type Param

type Param struct {
	Name       string
	Type       string
	IsVariadic bool
	IsSlice    bool
}

Param is an argument to a function.

type Params

type Params []Param

Params is a slice of Param.

func (Params) AsArgs

func (p Params) AsArgs() string

AsArgs builds a string that represents the parameters to a function as arguments to a function invocation.

func (Params) AsNamedArgs

func (p Params) AsNamedArgs() string

AsNamedArgs builds a string that represents parameters as named arguments.

func (Params) AsNamedArgsForInvocation

func (p Params) AsNamedArgsForInvocation() string

AsNamedArgsForInvocation builds a string that represents a function's arguments as required for invocation of the function.

func (Params) AsNamedArgsWithTypes

func (p Params) AsNamedArgsWithTypes() string

AsNamedArgsWithTypes builds a string that represents parameters as named arugments to a function, with associated types.

func (Params) AsReturnSignature

func (p Params) AsReturnSignature() string

AsReturnSignature builds a string representing signature for the params of a function.

func (Params) HasLength

func (p Params) HasLength() bool

HasLength returns true if there are params. It returns false if there are no params.

func (Params) Slices

func (p Params) Slices() Params

Slices returns those params that are a slice.

func (Params) WithPrefix

func (p Params) WithPrefix(prefix string) string

WithPrefix builds a string representing a functions parameters, and adds a prefix to each.

type Return

type Return struct {
	Name string
	Type string
}

Return is the result of a method's invocation.

type Returns

type Returns []Return

Returns is a slice of Return.

func (Returns) AsArgs

func (r Returns) AsArgs() string

AsArgs builds a string representing the arguments passed to a function.

func (Returns) AsNamedArgs

func (r Returns) AsNamedArgs() string

AsNamedArgs builds a string representing a function's named arguments.

func (Returns) AsNamedArgsWithTypes

func (r Returns) AsNamedArgsWithTypes() string

AsNamedArgsWithTypes builds a string representing a function's named arguments, with associated types.

func (Returns) AsReturnSignature

func (r Returns) AsReturnSignature() string

AsReturnSignature builds a string representing signature for the returns of a function.

func (Returns) HasLength

func (r Returns) HasLength() bool

HasLength is true if there are returns, else false.

func (Returns) WithPrefix

func (r Returns) WithPrefix(p string) string

WithPrefix builds a string representing the parameters returned from a function, and adds a prefix to each.

Jump to

Keyboard shortcuts

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