codegen

package
v1.41.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decl

type Decl interface {
	Name() string
	Qual() *jen.Statement
	Code() *jen.Statement
}

type File

type File struct {
	Jen *jen.File // the jen file we're generating
	// contains filtered or unexported fields
}

File represents a generated file for a specific package.

func (*File) Add

func (f *File) Add(code jen.Code)

Add adds a declaration to the file.

func (*File) FuncDecl

func (f *File) FuncDecl(nameParts ...string) *FuncDecl

func (*File) HasDecl

func (f *File) HasDecl(nameParts ...string) bool

func (*File) ImportAnon

func (f *File) ImportAnon(pkgs ...paths.Pkg)

ImportAnon adds an anonymous ("_"-prefixed) import of the given packages.

func (*File) Render

func (f *File) Render(w io.Writer) error

Render renders the file to the given writer.

func (*File) VarDecl

func (f *File) VarDecl(nameParts ...string) *VarDecl

type FuncDecl

type FuncDecl struct {
	File *File // file the declaration belongs to.
	// contains filtered or unexported fields
}

FuncDecl represents a generated declaration.

func (*FuncDecl) Body

func (d *FuncDecl) Body(code ...jen.Code) *FuncDecl

Body sets the body of the generated function.

func (*FuncDecl) BodyFunc

func (d *FuncDecl) BodyFunc(fn func(g *jen.Group)) *FuncDecl

BodyFunc computes the body of the generated function.

func (*FuncDecl) Code

func (d *FuncDecl) Code() *jen.Statement

Code returns the generated code.

func (*FuncDecl) Name

func (d *FuncDecl) Name() string

Name returns the package-level name of the declaration.

func (*FuncDecl) Params

func (d *FuncDecl) Params(params ...jen.Code) *FuncDecl

Params appends to the parameters of the generated function.

func (*FuncDecl) Qual

func (d *FuncDecl) Qual() *jen.Statement

Qual returns the qualified name of the declaration.

func (*FuncDecl) Results

func (d *FuncDecl) Results(results ...jen.Code) *FuncDecl

Results appends to the results of the generated function.

func (*FuncDecl) TypeParams

func (d *FuncDecl) TypeParams(params ...jen.Code) *FuncDecl

TypeParams appends to the type parameters of the generated function.

type Generator

type Generator struct {
	*parsectx.Context

	Util       *genutil.Helper
	TraceNodes *legacymeta.TraceNodes
	// contains filtered or unexported fields
}

func New

func New(c *parsectx.Context, traceNodes *legacymeta.TraceNodes) *Generator

func (*Generator) File

func (g *Generator) File(pkg *pkginfo.Package, shortName string) *File

func (*Generator) InjectFile

func (g *Generator) InjectFile(pkgPath paths.Pkg, pkgName string, pkgDir paths.FS, baseName, shortName string) *File

func (*Generator) InsertTestSupport added in v1.16.0

func (g *Generator) InsertTestSupport(pkg *pkginfo.Package)

InsertTestSupport inserts an import of the testsupport package in the given package.

func (*Generator) Overlays

func (g *Generator) Overlays() []overlay.File

func (*Generator) Rewrite

func (g *Generator) Rewrite(file *pkginfo.File) *rewrite.Rewriter

type TestConfig

type TestConfig struct {
	// Packages are the packages to generate test code for.
	Packages []*pkginfo.Package

	// EnvsToEmbed are the environment variables to embed inside
	// the test binaries themselves. This is useful when
	// building tests with "go test -c", where the binary is
	// built first and executed later (such as by GoLand).
	EnvsToEmbed map[string]string
}

TestConfig describes common configuration for code generation when running tests.

type VarDecl

type VarDecl struct {
	File *File // file the declaration belongs to.
	// contains filtered or unexported fields
}

func (*VarDecl) Code

func (d *VarDecl) Code() *jen.Statement

func (*VarDecl) Name

func (d *VarDecl) Name() string

func (*VarDecl) Qual

func (d *VarDecl) Qual() *jen.Statement

func (*VarDecl) Value

func (d *VarDecl) Value(code ...jen.Code) *VarDecl

Jump to

Keyboard shortcuts

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