generator

package
v0.0.0-...-d2ce1ba Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandwrittenMapperName

func HandwrittenMapperName(destinationFieldName string) string

Types

type Field

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

func (Field) DesiredName

func (f Field) DesiredName() string

func (Field) OriginalName

func (f Field) OriginalName() string

OriginalName Returns name of a field as it was parsed from source.

func (Field) OverrideTypeTo

func (f Field) OverrideTypeTo() string

func (Field) Type

func (f Field) Type() ast.Expr

type FieldInput

type FieldInput struct {
	Name           string
	RenameTo       string
	OverrideTypeTo string
}

type Fields

type Fields []Field

func (Fields) RequiredImports

func (fs Fields) RequiredImports() Imports

type FieldsInput

type FieldsInput []FieldInput

type Generated

type Generated interface {
	String() string
}

type Generator

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

func New

func New(parser Parser, writer Writer) *Generator

func (*Generator) Generate

func (g *Generator) Generate(input Input) (Generated, error)

type Import

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

func NewImport

func NewImport(i *ast.ImportSpec) Import

func (Import) Alias

func (i Import) Alias() string

func (Import) Name

func (i Import) Name() string

func (Import) Path

func (i Import) Path() string

func (Import) UsedName

func (i Import) UsedName() string

UsedName Prefix used to access import declaration in file.

type Imports

type Imports []Import

func (Imports) Has

func (is Imports) Has(_import Import) bool

type Input

type Input struct {
	// PackagePath Import path to package in which source object is present.
	PackagePath string
	// TypeName Name of DTO in the source.
	TypeName string
	// RenameTypeTo Desired name of a DTO. If empty, original name will be used.
	RenameTypeTo string

	// If IncludeAllParsedFields is set to true, all fields, no matter if they are present in Fields, will be included.
	IncludeAllParsedFields bool
	// Fields Specifies which fields should be included in new DTO. Each field can be renamed, or have override type.
	Fields FieldsInput

	// If SkipMapper is set to true, mapper will not be generated.
	SkipMapper bool

	// OutputPackagePath Import path to where DTO will be generated.
	OutputPackagePath string
	// OutputPackage Overrides output package name.
	OutputPackage string
}

Input

Required: - PackagePath - TypeName - IncludeAllParsedFields or Fields. Both can be present, if you want to include all fields, and rename some of them. - OutputPackagePath

type Mapper

type Mapper struct {
	// SourceTypeName Name of a struct we are mapping from.
	SourceTypeName string
	// SourceImportName Name of an import of struct we are mapping from.
	SourceImportName string

	// DestinationTypeName Name of a struct we are mapping to.
	DestinationTypeName string

	Mappings Mappings

	Helpers ParsedFunctions
}

type Mapping

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

func (Mapping) Destination

func (m Mapping) Destination() string

func (Mapping) Field

func (m Mapping) Field() string

func (Mapping) IsField

func (m Mapping) IsField() bool

func (Mapping) IsFunction

func (m Mapping) IsFunction() bool

func (Mapping) IsMethod

func (m Mapping) IsMethod() bool

func (Mapping) Source

func (m Mapping) Source() string

type Mappings

type Mappings []Mapping

type Method

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

func NewMethod

func NewMethod(name string) Method

func (Method) IsExported

func (m Method) IsExported() bool

type Methods

type Methods []Method

type Package

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

func NewPackage

func NewPackage(path, name string) Package

func (Package) ToImport

func (p Package) ToImport() Import

type ParsedField

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

func NewParsedField

func NewParsedField(name string, _type ast.Expr) ParsedField

func (ParsedField) Name

func (f ParsedField) Name() string

func (ParsedField) Type

func (f ParsedField) Type() ast.Expr

type ParsedFields

type ParsedFields []ParsedField

type ParsedFunction

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

func NewParsedFunction

func NewParsedFunction(name, body string) ParsedFunction

func (ParsedFunction) Code

func (pf ParsedFunction) Code() string

type ParsedFunctions

type ParsedFunctions []ParsedFunction

type ParsedStruct

type ParsedStruct struct {
	Name    string
	Fields  ParsedFields
	Methods Methods
	Imports Imports
	Package Package
}

type Parser

type Parser interface {
	LoadPackage(importPath string) (Parser, error)
	GetStruct(typeName string) (*ParsedStruct, error)
	GetFunctions() (ParsedFunctions, Imports, error)
}

type RegisteredTypeInput

type RegisteredTypeInput struct {
	ImportPath string
	TypeName   string
}

type RegisteredTypesInput

type RegisteredTypesInput []RegisteredTypeInput

type Writer

type Writer interface {
	String() string
	In()
	Out()
	Write(code string)
	WriteLine(code string)
	WriteEmptyLine()
	WritePackage(pkg string)
	WriteImports(imports Imports)
	WriteStruct(structName string, fields Fields)
	WriteMapper(mapper Mapper)
}

Jump to

Keyboard shortcuts

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