union

package
v1.2.125 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagUnion          = "union"
	TagUnionFlagShort = "short" // `union:",short"`
)

Variables

This section is empty.

Functions

func FilterTypeName

func FilterTypeName(exp ast.Expr) (fieldType string, fieldCanBeCompareWithNil bool, fieldCanBeCompareWithZero bool)

func FormatTypeDeclaration

func FormatTypeDeclaration(tparams *ast.FieldList) (string, error)

FormatTypeDeclaration turns TypeParamList into its Go representation, such as: [T, Y comparable]. Note that it does not print constraints as this is mainly used for formatting type params in method receivers.

func FormatTypeParams

func FormatTypeParams(tparams *ast.FieldList) string

FormatTypeParams turns TypeParamList into its Go representation, such as: [T, Y]. Note that it does not print constraints as this is mainly used for formatting type params in method receivers.

func IsExported

func IsExported(arg reflect.Value) bool

func Main

func Main()

func Usage

func Usage()

Usage is a replacement usage function for the flags package.

Types

type File

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

File holds a single parsed file and associated data.

type Generator

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

Generator holds the state of the analysis. Primarily used to buffer the output for format.Source.

func (*Generator) Printf

func (g *Generator) Printf(format string, args ...any)

Printf format & write to the buf in this generator

func (*Generator) Render

func (g *Generator) Render(text string, arg any)

func (*Generator) Reset

func (g *Generator) Reset()

Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes.

type Package

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

Package holds a single parsed package and associated files and ast files.

type Struct

type Struct struct {
	FileImports                  []string // The import path of the file contains the struct
	StructTypeImport             string   // The import path of StructTypeName.
	StructTypeName               string   // The StructTypeName of the struct.
	StructTypeGenericDeclaration string   // the Generic type of the struct type
	StructTypeGenericTypeParams  string   // the Generic params of the struct type
	IsStruct                     bool
	Fields                       []StructField
}

Struct represents a declared constant.

type StructField

type StructField struct {
	FieldName                 string                // The FieldName of the struct field.
	FieldType                 string                // The FieldType of the struct field.
	FieldDocComment           *ast.CommentGroup     // The doc comment of the struct field.
	FieldLineComment          *ast.CommentGroup     // The line comment of the struct field.
	UnionTag                  reflect_.SubStructTag // The UnionTag of the struct field.
	FieldCanBeCompareWithNil  bool                  // The FieldType of the struct field can be compared with nil.
	FieldCanBeCompareWithZero bool                  // The FieldType of the struct field can be compared with zero.
}

type TmplUnionRender

type TmplUnionRender struct {
	// Print the header and package clause.
	GoUnionToolName       string
	GoUnionToolArgs       []string
	GoUnionToolArgsJoined string

	PackageName string
	ImportPaths []string
	ValDecls    []string

	TargetTypeName               string // type name of target type
	TargetTypeImport             string // import path of target type
	TargetTypeGenericDeclaration string // the Generic type of the struct type
	TargetTypeGenericParams      string // the Generic params of the struct type

	FormatTypeName string        // The format FieldName of the struct type.
	Fields         []StructField // fields if target type is struct

	UnionInterfaceName string // union interface name of target type
	UnionStructName    string // union struct name of target type

	ApplyUnionsAsMemberFunction bool // ApplyUnions can be registered as UnionType's member function
	WithTargetTypeNameAsPrefix  bool // WithXXX() can be generated as {{UnionType}}WithXXX()
}

func (*TmplUnionRender) Complete

func (t *TmplUnionRender) Complete()

type Value

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

Value represents a declared constant.

func (*Value) String

func (v *Value) String() string

Jump to

Keyboard shortcuts

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