codegen

package
v0.0.0-...-6a0b755 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

codegen defines general utilities for codegen.

Index

Constants

View Source
const (
	DirectiveCommentIgnore    = "ignore"
	DirectiveCommentGenerated = "generated"
)
View Source
const (
	DirectivePrefix = "codegen:"
)

Variables

This section is empty.

Functions

func BufPrintf

func BufPrintf(w io.Writer) (func(format string, args ...any), func() error)

func EnumerateCommentGroup

func EnumerateCommentGroup(comments *ast.CommentGroup) iter.Seq[string]

func ExcludeIgnoredGenDecl

func ExcludeIgnoredGenDecl(genDecl *ast.GenDecl) (bool, error)

func ExcludeIgnoredTypeSpec

func ExcludeIgnoredTypeSpec(ts *ast.TypeSpec, _ types.Object) (bool, error)

func FieldAst

func FieldAst(st *ast.StructType) iter.Seq[FieldDescAst]

func FieldDst

func FieldDst(st *dst.StructType) iter.Seq[FieldDescDst]

func ParseFieldDirectiveCommentDst

func ParseFieldDirectiveCommentDst[T any](
	prefix string,
	comments dst.FieldDecorations,
	parser func(s []string) (T, error),
) (T, bool, error)

func PrintAstExprPanicking

func PrintAstExprPanicking(expr ast.Expr) string

func PrintFileHeader

func PrintFileHeader(w io.Writer, af *ast.File, fset *token.FileSet) error

func PrintTypeParamsAst

func PrintTypeParamsAst(ts *ast.TypeSpec) string

func PrintTypeParamsDst

func PrintTypeParamsDst(ts *dst.TypeSpec) string

func TrimPackageComment

func TrimPackageComment(f *dst.File)

func TypeToAst

func TypeToAst(ty types.Type, pkgPath string, importMap imports.ImportMap) ast.Expr

func TypeToDst

func TypeToDst(ty types.Type, pkgPath string, importMap imports.ImportMap) dst.Expr

Types

type Direction

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

func ParseDirectiveComment

func ParseDirectiveComment(comments *ast.CommentGroup) (Direction, bool, error)

func ParseDirectiveCommentDst

func ParseDirectiveCommentDst(comments dst.NodeDecs) (Direction, bool, error)

func (Direction) MustIgnore

func (d Direction) MustIgnore() bool

type FieldDescAst

type FieldDescAst struct {
	Pos   int
	Name  string
	Field *ast.Field
}

type FieldDescDst

type FieldDescDst struct {
	Pos   int
	Name  string
	Field *dst.Field
}

type Parser

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

func NewParser

func NewParser(dir string) *Parser

func (*Parser) ParseFile

func (p *Parser) ParseFile(fset *token.FileSet, filename string, src []byte) (*ast.File, error)

Jump to

Keyboard shortcuts

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