astgen

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeclarationBuilder

type DeclarationBuilder interface {
	Build() ast.Decl
}

type File

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

File describes a single Go source file.

func NewFile

func NewFile(packageName string) *File

NewFile returns new empty source file within the specified package.

func (*File) AddImport

func (f *File) AddImport(packageName, location string) (importAlias string)

AddImport assures that the specified package name in the specified location will be added as an import and returns the import package alias.

func (*File) AppendDeclaration

func (f *File) AppendDeclaration(d DeclarationBuilder)

AppendDeclarations appends the specified decleration to the file.

func (*File) Build

func (f *File) Build() *ast.File

Build returns AST representing the file.

type Generator

type Generator struct {
	Model    ModelBuilder
	Locator  *resolution.Locator
	Resolver *resolution.Resolver
}

func (*Generator) ProcessInterface

func (g *Generator) ProcessInterface(d resolution.TypeDiscovery) error

type Method

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

Method represents a struct method.

func NewMethod

func NewMethod(name, receiverName, receiverType string) *Method

func (*Method) AddStatement

func (m *Method) AddStatement(stmt ast.Stmt)

func (*Method) AddStatements

func (m *Method) AddStatements(stmts []ast.Stmt)

func (*Method) Build

func (m *Method) Build() ast.Decl

func (*Method) SetType

func (m *Method) SetType(funcType *ast.FuncType)

type MethodConfig

type MethodConfig struct {
	// MethodName specifies the name of the method as seen in the interface it
	// came from.
	MethodName string

	// MethodParams specifies all the parameters of the method.  They should
	// have been normalized (i.e. no type reuse and no anonymous parameters)
	// and resolved (i.e. all selector expressions resolved against the
	// generated stub's new namespace)
	MethodParams []*ast.Field

	// MethodResults specifies all the results of the method.  They should have
	// been normalized (i.e. no type reuse and no anonymous results) and
	// resolved (i.e. all selector expressions resolved against the generated
	// stub's new namespace)
	MethodResults []*ast.Field
}

MethodConfig describes a method.

func (*MethodConfig) HasParams

func (s *MethodConfig) HasParams() bool

func (*MethodConfig) HasResults

func (s *MethodConfig) HasResults() bool

type ModelBuilder

type ModelBuilder interface {
	// AddMethod should add implementation for the specified method.
	AddMethod(*MethodConfig) error
}

type Struct

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

Struct represents a Go struct.

func NewStruct

func NewStruct(name string) *Struct

NewStruct creates new empty struct.

func (*Struct) AddField

func (s *Struct) AddField(name, typePackage, typeName string)

AddField adds field of the specified type to the struct.

func (*Struct) AddFieldWithType

func (s *Struct) AddFieldWithType(name string, typ ast.Expr)

func (*Struct) Build

func (s *Struct) Build() ast.Decl

Jump to

Keyboard shortcuts

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