lib

package
v0.0.0-...-90ca10d Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDirective

func BuildDirective(predicate bool) string

func FindFileBuildTags

func FindFileBuildTags(pkg *packages.Package, file *ast.File) map[string]*Extent

func FindPackageBuildTags

func FindPackageBuildTags(pkg *packages.Package) map[string]*Extent

func FormatCode

func FormatCode(ctx context.Context, filePath string, buildTag string) error

func GenBuildTags

func GenBuildTags(predicate bool) string

func GenFuncLit

func GenFuncLit(funcType string, body string) string

func GenImport

func GenImport(pkgName, pkgPath string) string

func GenNewLine

func GenNewLine() string

func GenPkgName

func GenPkgName(prefix string, nameHint string) string

func GenReturn

func GenReturn(expr string) string

func GenTmpBuildTags

func GenTmpBuildTags(predicate bool) string

func GenVarName

func GenVarName(prefix string, nameHint string) string

func GenerateSyntax

func GenerateSyntax[Syntax interface {
	fmt.Stringer
	comparable
}](info *FileInfo[Syntax], writer io.Writer,
	proc func(file *os.File, addImports map[string]string) ([]*ReplaceBlock, error)) error

func GetNameFromType

func GetNameFromType(ty types.Type) string

func GetNameFromTypeStr

func GetNameFromTypeStr(str string) string

func GetPkgPathFromType

func GetPkgPathFromType(ty types.Type) string

func GetPkgPathFromTypeStr

func GetPkgPathFromTypeStr(str string) string

func GetTypesFromType

func GetTypesFromType(ty types.Type) []string

func GetTypesFromTypeStr

func GetTypesFromTypeStr(str string) []string

func JoinStringers

func JoinStringers[S []T, T fmt.Stringer](ss S, sep string) string

func LoadPackages

func LoadPackages(ctx context.Context, path string, buildFlags ...string) ([]*packages.Package, error)

func ReadExtent

func ReadExtent(reader io.ReaderAt, extent *Extent) (string, error)

func ReadExtentList

func ReadExtentList(reader io.ReaderAt, extents []*Extent) ([]string, error)

func ResetTypePkgName

func ResetTypePkgName(ty types.Type, imports map[string]string, currentPkg string) (ret string, adds map[string]string)

func ResetTypeStrPkgName

func ResetTypeStrPkgName(str string, imports map[string]string, currentPkg string) (ret string, adds map[string]string)

func SetProdBuildTags

func SetProdBuildTags(ctx context.Context, rootDir string) error

func SetTmpBuildTags

func SetTmpBuildTags(ctx context.Context, rootDir string) error

func TmpBuildDirective

func TmpBuildDirective(predicate bool) string

func TranslateSyntax

func TranslateSyntax[Type, Syntax interface {
	fmt.Stringer
	comparable
}](
	ctx context.Context, rootDir string, firstRun bool,
	translator SyntaxTranslator[Type, Syntax],
) error

Types

type Extent

type Extent struct {
	Start token.Position
	End   token.Position
}

func (*Extent) IsEmpty

func (m *Extent) IsEmpty() bool

func (*Extent) String

func (m *Extent) String() string

type FileInfo

type FileInfo[Syntax interface {
	fmt.Stringer
	comparable
}] struct {
	Path         string
	BuildTag     *Extent
	PkgPath      string
	Imports      map[string]string
	ImportExtent *Extent
	Syntax       []Syntax
}

type PackageInspector

type PackageInspector[Syntax interface {
	fmt.Stringer
	comparable
}] struct {
	// contains filtered or unexported fields
}

func NewPackageInspector

func NewPackageInspector[Syntax interface {
	fmt.Stringer
	comparable
}](pkg *packages.Package, inpector SyntaxInspector[Syntax]) *PackageInspector[Syntax]

func (*PackageInspector[Syntax]) Inspect

func (i *PackageInspector[Syntax]) Inspect() []*FileInfo[Syntax]

type Program

type Program interface {
	Run(ctx context.Context, rootDir string, firstRun bool) error
}

type ReplaceBlock

type ReplaceBlock struct {
	Old Extent
	New string
}

type SyntaxInspector

type SyntaxInspector[Syntax interface {
	fmt.Stringer
	comparable
}] interface {
	Nodes() []ast.Node
	Inspect(node ast.Node, stack []ast.Node) Syntax
}

type SyntaxTranslator

type SyntaxTranslator[Type, Syntax interface {
	fmt.Stringer
	comparable
}] interface {
	InpectTypes(p *packages.Package) []Type
	InspectSyntax(p *packages.Package, instTypes []Type) SyntaxInspector[Syntax]
	Generate(info *FileInfo[Syntax], writer io.Writer) error
}

Jump to

Keyboard shortcuts

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