interfaces

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: 2 Imported by: 0

Documentation

Index

Constants

View Source
const PackagePathContextKey = ContextKey("packagePath")

PackagePathContextKey is the context key for the package path.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompiledConfig

type CompiledConfig struct {
	PackageName string // The name of the package to be generated
	Packages    []*CompiledPackage

	// RulesByPackageAndType stores compiled rules, organized for efficient lookup.
	// Outer map key: PackageName (empty string for global/wildcard rules).
	// Inner map key: RuleType (e.g., RuleTypeType, RuleTypeFunc).
	// Value: A slice of CompiledRenameRule, sorted by Priority.
	RulesByPackageAndType map[string]map[RuleType][]CompiledRenameRule
}

CompiledConfig holds all the compiled information needed for generation.

type CompiledPackage

type CompiledPackage struct {
	ImportPath  string
	ImportAlias string
	Types       interface{} // Types defined in this package
	Functions   interface{} // Functions defined in this package
	Variables   interface{} // Variables defined in this package
	Constants   interface{} // Constants defined in this package
}

CompiledPackage holds the compiled information for a single source package.

type CompiledRenameRule

type CompiledRenameRule struct {
	Type          string         // e.g., "prefix", "suffix", "explicit", "regex"
	RuleType      RuleType       // The category of the rule (const, var, func, type)
	OriginalName  string         // The original name from the config rule (e.g., "*", "Worker")
	Value         string         // For prefix/suffix
	From          string         // For explicit
	To            string         // For explicit
	Pattern       string         // Original regex pattern string
	Replace       string         // Replacement string for regex
	CompiledRegex *regexp.Regexp // Pre-compiled regex for "regex" type rules
	Priority      int            // Priority of the rule
	IsWildcard    bool           // Indicates if the rule applies to all packages (wildcard)
}

CompiledRenameRule represents a fully compiled and ready-to-apply renaming rule.

type Context

type Context interface {
	WithValue(key, value interface{}) Context
	Value(key interface{}) interface{}
	Push(nodeType RuleType) Context
	CurrentNodeType() RuleType
}

Context defines the interface for passing context across calls. It allows for carrying metadata in a key-value manner and managing a stack of node types.

func NewContext

func NewContext() Context

NewContext creates a new root context.

type ContextInfo

type ContextInfo struct {
	NodeType string // e.g., "const", "var", "type", "func"
}

ContextInfo holds information about the current processing context.

type ContextKey

type ContextKey string

ContextKey is the type for context keys.

type RenameRule

type RenameRule struct {
	Type     string   // e.g., "prefix", "suffix", "explicit", "regex"
	RuleType RuleType // The category of the rule (const, var, func, type)
	Value    string   // For prefix/suffix
	From     string   // For explicit
	To       string   // For explicit
	Pattern  string   // For regex
	Replace  string   // For regex
}

RenameRule defines a single renaming rule.

type Replacer

type Replacer interface {
	Apply(ctx Context, node ast.Node) ast.Node
}

Replacer defines the interface for applying code transformations based on compiled rules. It takes an AST node and returns a potentially modified node.

type RuleType

type RuleType int

RuleType is an enum for different container rule types.

const (
	RuleTypeUnknown RuleType = iota
	RuleTypeRoot
	RuleTypePackage
	RuleTypeType
	RuleTypeFunc
	RuleTypeVar
	RuleTypeConst
	RuleTypeMethod
	RuleTypeField
)

func ParseRuleType

func ParseRuleType(s string) RuleType

func (RuleType) String

func (t RuleType) String() string

Jump to

Keyboard shortcuts

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