generator

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultHeaderTemplate = `` /* 193-byte string literal not displayed */

DefaultHeaderTemplate is the built-in template for the generated file header. It includes the standard "Code generated by ... DO NOT EDIT." line recognized by Go tools.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is responsible for building the output file from collected declarations.

func NewBuilder

func NewBuilder(packageName string, outputFilePath string, copyrightHolder string) *Builder

NewBuilder creates a new Builder.

func (*Builder) Build

func (b *Builder) Build(c *Collector)

Build builds the output file structure from the collected data.

func (*Builder) RenderHeader

func (b *Builder) RenderHeader(sourceFile string) error

RenderHeader executes the header template with the given source file name.

func (*Builder) WithFormatCode

func (b *Builder) WithFormatCode(format bool) *Builder

WithFormatCode sets whether to automatically format after generating code

func (*Builder) WithHeaderTemplate

func (b *Builder) WithHeaderTemplate(headerTemplate string) *Builder

WithHeaderTemplate sets a custom header template.

func (*Builder) Write

func (b *Builder) Write() error

Write writes the generated code to the output file or to the configured writer.

type Collector

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

Collector is responsible for collecting declarations from source packages.

func NewCollector

func NewCollector(replacer interfaces.Replacer) *Collector

NewCollector creates a new Collector.

func (*Collector) Collect

func (c *Collector) Collect(packages []*PackageInfo) error

Collect method to use the new alias manager

type Generator

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

Generator holds the state and configuration for code generation.

func NewGenerator

func NewGenerator(packageName string, outputFilePath string, replacer interfaces.Replacer, copyrightHolder string) *Generator

NewGenerator creates a new Generator instance.

func (*Generator) Generate

func (g *Generator) Generate(packages []*PackageInfo) error

Generate generates the output code.

func (*Generator) RenderHeader

func (g *Generator) RenderHeader(sourceFile string) error

RenderHeader renders the header for the generated file.

func (*Generator) WithFormatCode

func (g *Generator) WithFormatCode(format bool) *Generator

WithFormatCode sets whether to automatically format after generating code

type PackageInfo

type PackageInfo struct {
	ImportPath  string // The import path of the package
	ImportAlias string // The alias for the package import
}

PackageInfo holds the minimal package information needed by the generator.

Jump to

Keyboard shortcuts

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