code

package
v1.7.10 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayType

type ArrayType struct {
	ContainedType Type
}

ArrayType is a model of array

func (ArrayType) Code

func (t ArrayType) Code() string

Code returns token string in code format

type Coder

type Coder interface {
	Code() string
}

type ConstantField

type ConstantField struct {
	Name     string
	Type     Type
	Value    any
	Comments []string
}

type ConstantFields

type ConstantFields []*ConstantField

type ExternalType

type ExternalType struct {
	PackageAlias string
	Name         string
}

ExternalType is a type that is called to another package

func (ExternalType) Code

func (t ExternalType) Code() string

Code returns token string in code format

type File

type File struct {
	PackageName string
	Imports     []*Import
	Structs     Structs
	Interfaces  InterfaceSpecs
	Methods     []*Method
	Constants   ConstantFields
}

File is a container of all required components for code generation in the file

func ExportFile

func ExportFile(file *File) (*File, error)

func ExtractComponents

func ExtractComponents(f *ast.File, opts ...Option) File

ExtractComponents converts ast file into code components model

func ExtractComponentsByPath

func ExtractComponentsByPath(componentPath string, opts ...Option) (*File, error)

type Function

type Function struct {
	Name     string
	Params   []Param
	Returns  []Type
	Comments []string
}

func ExtractFunction

func ExtractFunction(name string, commonts []string, funcType *ast.FuncType) *Function

type Import

type Import struct {
	Name string
	Path string
}

Import is a model for package imports

func ExtraImports

func ExtraImports(spec *ast.ImportSpec) *Import

type InterfaceSpec

type InterfaceSpec struct {
	Name    string
	Methods []*Function
}

InterfaceSpec is a definition of the interface

func ExtractInterfaceSpec

func ExtractInterfaceSpec(spec *ast.TypeSpec, iType *ast.InterfaceType) *InterfaceSpec

type InterfaceSpecs

type InterfaceSpecs []*InterfaceSpec

InterfaceSpecs is a group of InterfaceSpec model

func (InterfaceSpecs) ByName

func (intfs InterfaceSpecs) ByName(name string) (*InterfaceSpec, bool)

ByName return interface by name Another return value shows whether there is an interface with that name exists.

type MapType

type MapType struct {
	KeyType   Type
	ValueType Type
}

MapType is a model of map

func (MapType) Code

func (t MapType) Code() string

Code returns token string in code format

type Method

type Method struct {
	Function
	Receiver Receiver
}

func ExtractMethod

func ExtractMethod(funcDecl *ast.FuncDecl) *Method

type Option

type Option interface {
	Apply(*Options)
}

func WithConstants

func WithConstants() Option

func WithFunctions

func WithFunctions() Option

func WithImports

func WithImports() Option

func WithInterfaces

func WithInterfaces() Option

func WithStructs

func WithStructs() Option

type Options

type Options struct {
	ExtraImports    bool
	ExtraConstants  bool
	ExtraStructs    bool
	ExtraInterfaces bool
	ExtraFunctions  bool
}

func NewOptions

func NewOptions(opts ...Option) *Options

type Param

type Param struct {
	Name string
	Type Type
}

Param is a model of method parameter

type PointerType

type PointerType struct {
	ContainedType Type
}

PointerType is a model of pointer

func (PointerType) Code

func (t PointerType) Code() string

Code returns token string in code format

type Receiver

type Receiver struct {
	Type Type
	Name string
}

type SimpleType

type SimpleType string

SimpleType is a type that can be called directly

func (SimpleType) Code

func (t SimpleType) Code() string

Code returns token string in code format

func (SimpleType) IsBuildIn

func (t SimpleType) IsBuildIn() bool

type Struct

type Struct struct {
	PackageAlias string
	Name         string
	Fields       StructFields
}

Struct is a definition of the struct

func (Struct) ReferencedType

func (str Struct) ReferencedType() Type

ReferencedType returns a type variable of this struct

type StructField

type StructField struct {
	Name string
	Type Type
	Tags reflect.StructTag
}

StructField is a definition of the struct field

type StructFields

type StructFields []StructField

StructFields is a group of the StructField model

func (StructFields) ByName

func (fields StructFields) ByName(name string) (StructField, bool)

ByName return struct field with matching name

type Structs

type Structs []*Struct

Structs is a group of Struct model

func (Structs) ByName

func (strs Structs) ByName(name string) (*Struct, bool)

ByName return struct with matching name. Another return value shows whether there is a struct with that name exists.

type Type

type Type interface {
	Coder
}

Type is an interface for value types

Jump to

Keyboard shortcuts

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