builder

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToAssignable added in v1.4.1

func ToAssignable(assignTo *AssignTo) func(stmt []jen.Code, nextID *xtype.JenID, err *Error) ([]jen.Code, *Error)

func ToString

func ToString(err *Error) string

ToString converts the error into a string.

Types

type AssignTo added in v1.4.1

type AssignTo struct {
	Stmt   *jen.Statement
	Must   bool
	Update bool
}

func AssignOf added in v1.6.0

func AssignOf(s *jen.Statement) *AssignTo

func (*AssignTo) IsUpdate added in v1.7.0

func (a *AssignTo) IsUpdate() *AssignTo

func (*AssignTo) MustAssign added in v1.7.0

func (a *AssignTo) MustAssign() *AssignTo

func (*AssignTo) WithIndex added in v1.4.1

func (a *AssignTo) WithIndex(s *jen.Statement) *AssignTo

type Basic

type Basic struct{}

Basic handles basic data types.

func (*Basic) Assign added in v1.4.1

func (b *Basic) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*Basic) Build

func (*Basic) Build(_ Generator, _ *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Basic) Matches

func (*Basic) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type BasicTargetPointerRule

type BasicTargetPointerRule struct{}

BasicTargetPointerRule handles edge conditions if the target type is a pointer.

func (*BasicTargetPointerRule) Assign added in v1.4.1

func (b *BasicTargetPointerRule) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*BasicTargetPointerRule) Build

func (*BasicTargetPointerRule) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*BasicTargetPointerRule) Matches

func (*BasicTargetPointerRule) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type Builder

type Builder interface {
	// Matches returns true, if the builder can create handle the given types.
	Matches(ctx *MethodContext, source, target *xtype.Type) bool

	// Build creates conversion source code for the given source and target type.
	Build(gen Generator,
		ctx *MethodContext,
		sourceID *xtype.JenID,
		source, target *xtype.Type,
		path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

	// Assign creates conversion source code for the given source and target type and assigns it.
	Assign(gen Generator,
		ctx *MethodContext,
		assignTo *AssignTo,
		sourceID *xtype.JenID,
		source, target *xtype.Type,
		path ErrorPath) ([]jen.Code, *Error)
}

Builder builds converter implementations, and can decide if it can handle the given type.

type Enum added in v1.4.0

type Enum struct{}

Basic handles basic data types.

func (*Enum) Assign added in v1.4.1

func (s *Enum) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *Error)

func (*Enum) Build added in v1.4.0

func (*Enum) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Enum) Matches added in v1.4.0

func (*Enum) Matches(ctx *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type Error

type Error struct {
	Path  []*Path
	Cause string
}

Error defines a conversion error.

func AssignByBuild added in v1.4.1

func AssignByBuild(b Builder, gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func BuildByAssign added in v1.4.1

func BuildByAssign(b Builder, gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

func NewError

func NewError(cause string) *Error

NewError creates an error.

func (*Error) Lift

func (e *Error) Lift(paths ...*Path) *Error

Lift appends the path to the error.

type ErrorElement added in v1.4.0

type ErrorElement interface {
	// contains filtered or unexported methods
}

type ErrorPath added in v1.4.0

type ErrorPath []ErrorElement

func (ErrorPath) Field added in v1.4.0

func (e ErrorPath) Field(name string) ErrorPath

func (ErrorPath) Index added in v1.4.0

func (e ErrorPath) Index(code *jen.Statement) ErrorPath

func (ErrorPath) Key added in v1.4.0

func (e ErrorPath) Key(code *jen.Statement) ErrorPath

func (ErrorPath) WrapErrors added in v1.4.0

func (e ErrorPath) WrapErrors(errStmt *jen.Statement) *jen.Statement

func (ErrorPath) WrapErrorsUsing added in v1.4.0

func (e ErrorPath) WrapErrorsUsing(pkg string, errStmt *jen.Statement) *jen.Statement

type Generator

type Generator interface {
	Build(
		ctx *MethodContext,
		sourceID *xtype.JenID,
		source, target *xtype.Type,
		path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

	Assign(ctx *MethodContext,
		assignTo *AssignTo,
		sourceID *xtype.JenID,
		source, target *xtype.Type,
		path ErrorPath) ([]jen.Code, *Error)

	CallMethod(
		ctx *MethodContext,
		method *method.Definition,
		sourceID *xtype.JenID,
		source, target *xtype.Type,
		path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

	ReturnError(ctx *MethodContext,
		path ErrorPath,
		id *jen.Statement) (jen.Code, bool)
}

Generator checks all existing builders if they can create a conversion implementations for the given source and target type If no one Builder#Matches then, an error is returned.

type List

type List struct{}

List handles array / slice types.

func (*List) Assign added in v1.4.1

func (*List) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *Error)

func (*List) Build

func (l *List) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*List) Matches

func (*List) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type Map

type Map struct{}

Map handles map types.

func (*Map) Assign added in v1.4.1

func (*Map) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*Map) Build

func (m *Map) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Map) Matches

func (*Map) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type MethodContext

type MethodContext struct {
	*namer.Namer
	Conf              *config.Method
	FieldsTarget      string
	OutputPackagePath string
	UseConstructor    bool
	Signature         xtype.Signature
	TargetType        *xtype.Type
	HasMethod         func(*MethodContext, types.Type, types.Type) bool
	SeenNamed         map[string]struct{}

	IndexID method.IndexID
	Context map[string]*xtype.JenID

	AvailableContext map[string]*xtype.Type

	TargetVar *jen.Statement
}

MethodContext exposes information for the current method.

func (*MethodContext) DefinedEnumFields added in v1.4.0

func (ctx *MethodContext) DefinedEnumFields(target *xtype.Type) map[string]struct{}

func (*MethodContext) DefinedFields added in v1.3.0

func (ctx *MethodContext) DefinedFields(target *xtype.Type) map[string]struct{}

func (*MethodContext) Field added in v0.12.0

func (ctx *MethodContext) Field(target *xtype.Type, name string) *config.FieldMapping

func (*MethodContext) HasSeen added in v0.17.4

func (ctx *MethodContext) HasSeen(source *xtype.Type) bool

func (*MethodContext) MarkSeen added in v0.17.4

func (ctx *MethodContext) MarkSeen(source *xtype.Type)

func (*MethodContext) SetErrorTargetVar added in v0.15.0

func (ctx *MethodContext) SetErrorTargetVar(m *jen.Statement)

type Path

type Path struct {
	Prefix     string
	SourceID   string
	TargetID   string
	SourceType string
	TargetType string
}

Path defines the path inside an error message.

type Pointer

type Pointer struct{}

Pointer handles pointer types.

func (*Pointer) Assign added in v1.4.1

func (*Pointer) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*Pointer) Build

func (p *Pointer) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Pointer) Matches

func (*Pointer) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type SkipCopy added in v0.18.0

type SkipCopy struct{}

SkipCopy handles FlagSkipCopySameType.

func (*SkipCopy) Assign added in v1.4.1

func (*SkipCopy) Assign(_ Generator, _ *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, _, _ *xtype.Type, _ ErrorPath) ([]jen.Code, *Error)

func (*SkipCopy) Build added in v0.18.0

func (*SkipCopy) Build(_ Generator, _ *MethodContext, sourceID *xtype.JenID, _, _ *xtype.Type, _ ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*SkipCopy) Matches added in v0.18.0

func (*SkipCopy) Matches(ctx *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type SourcePointer added in v0.17.0

type SourcePointer struct{}

SourcePointer handles type were only the source is a pointer.

func (*SourcePointer) Assign added in v1.4.1

func (*SourcePointer) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *Error)

func (*SourcePointer) Build added in v0.17.0

func (s *SourcePointer) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*SourcePointer) Matches added in v0.17.0

func (*SourcePointer) Matches(ctx *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type Struct

type Struct struct{}

Struct handles struct types.

func (*Struct) Assign added in v1.4.1

func (s *Struct) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*Struct) Build

func (s *Struct) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*Struct) Matches

func (*Struct) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type TargetPointer

type TargetPointer struct{}

TargetPointer handles type were only the target is a pointer.

func (*TargetPointer) Assign added in v1.4.1

func (tp *TargetPointer) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *Error)

func (*TargetPointer) Build

func (*TargetPointer) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, path ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*TargetPointer) Matches

func (*TargetPointer) Matches(_ *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

type UseUnderlyingTypeMethods added in v1.1.0

type UseUnderlyingTypeMethods struct{}

UseUnderlyingTypeMethods handles UseUnderlyingTypeMethods.

func (*UseUnderlyingTypeMethods) Assign added in v1.4.1

func (u *UseUnderlyingTypeMethods) Assign(gen Generator, ctx *MethodContext, assignTo *AssignTo, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *Error)

func (*UseUnderlyingTypeMethods) Build added in v1.1.0

func (*UseUnderlyingTypeMethods) Build(gen Generator, ctx *MethodContext, sourceID *xtype.JenID, source, target *xtype.Type, errPath ErrorPath) ([]jen.Code, *xtype.JenID, *Error)

Build creates conversion source code for the given source and target type.

func (*UseUnderlyingTypeMethods) Matches added in v1.1.0

func (*UseUnderlyingTypeMethods) Matches(ctx *MethodContext, source, target *xtype.Type) bool

Matches returns true, if the builder can create handle the given types.

Jump to

Keyboard shortcuts

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