constructor

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectInitFuncReturnTypes added in v0.4.0

func CollectInitFuncReturnTypes(typeName string, initFuncName string, astFiles []*ast.File) ([]string, error)

CollectInitFuncReturnTypes collects the return types of the init function.

Types

type AllArgsConstructorGenerator

type AllArgsConstructorGenerator struct {
	TypeName                 string
	Fields                   []*Field
	InitFunc                 string
	InitFuncReturnTypes      []string
	PropagateInitFuncReturns bool
}

AllArgsConstructorGenerator is a struct type that has the responsibility to generate a statement of a constructor with all of arguments.

func (*AllArgsConstructorGenerator) Generate

func (cg *AllArgsConstructorGenerator) Generate(indentLevel int) g.Statement

Generate generates a constructor statement with all of arguments.

type BuilderGenerator

type BuilderGenerator struct {
	TypeName                 string
	Fields                   []*Field
	InitFunc                 string
	InitFuncReturnTypes      []string
	PropagateInitFuncReturns bool
}

BuilderGenerator is a struct type that has the responsibility to generate a statement of a builder.

func (*BuilderGenerator) Generate

func (cg *BuilderGenerator) Generate(indentLevel int) g.Statement

Generate generates a builder statement.

type Field

type Field struct {
	// FieldName is a name of the field.
	FieldName string
	// FieldType is a type of the field.
	FieldType string
	// ShouldIgnore marks whether the field should be ignored or not in a constructor.
	ShouldIgnore bool
}

Field represents a field of the structure for a constructor to be generated.

func CollectConstructorFieldsFromAST

func CollectConstructorFieldsFromAST(typeName string, astFiles []*ast.File) ([]*Field, error)

CollectConstructorFieldsFromAST collects fields to include in a constructor from the AST.

type Generator

type Generator interface {
	// Generate generates a constructor statement.
	Generate(indentLevel int) g.Statement
}

Generator is an interface that has the responsibility to generate a constructor code.

Jump to

Keyboard shortcuts

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