AstUtils

package module
v0.0.0-...-1f077c5 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: MIT Imports: 8 Imported by: 1

README

AstUtils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddMissingImports

func AddMissingImports(file *ast.File, imports []string)

func AddModifiedComment

func AddModifiedComment(file *ast.File, comment string)

func CombineTags

func CombineTags(tag1, tag2 *ast.BasicLit, combiners map[string]TagCombiner) (*ast.BasicLit, error)

CombineTags Combines two tags. Uses the first seen tag, as combined tag, unless a TagCombiner for the tag key is present.

func DeleteTagByKey

func DeleteTagByKey(lit *ast.BasicLit, tagKey string) *ast.BasicLit

func ExtractTagsByKey

func ExtractTagsByKey(tag *ast.BasicLit, valueMap ...map[string][]string) map[string][]string

func GetEmptyFile

func GetEmptyFile(packageName string) (*ast.File, error)

func GetJsonTagName

func GetJsonTagName(tag *ast.BasicLit) (string, error)

func GetJsonTagValue

func GetJsonTagValue(tag string) string

func GetTagValue

func GetTagValue(tag string, tagKey string) string

func IsBasicField

func IsBasicField(field *ast.Field) bool

func PreviouslyModified

func PreviouslyModified(file *ast.File, searchString string) bool

func RemoveTag

func RemoveTag(key string, lit *ast.BasicLit) *ast.BasicLit

func ReplaceExprChild

func ReplaceExprChild(decl *ast.Node, n ast.Expr)

func ReplaceImports

func ReplaceImports(file *ast.File, imports []string)

func SearchNodes

func SearchNodes(decl ast.Node, foundNodes *[]*FoundNodes, parents []*ast.Node, searchFunction func(node *ast.Node, parents []*ast.Node, completed *bool) bool, completed *bool)

SearchNodes Searches the Ast-tree. The search function decides what's a match. foundNodes holds all matches including their parents. This allows to modify a method call inside a function, then traverses upwards to modify the containing function parameters as well. Set completed to true inside the search function, if the search should be terminated.

func SetExported

func SetExported(name string) string

func SetUnexported

func SetUnexported(name string) string

func TagsEqual

func TagsEqual(lit0, lit1 *ast.BasicLit) bool

func ToSnakeCase

func ToSnakeCase(s string) string

func UnnestStruct

func UnnestStruct(structName *string, file *ast.File)

UnnestStruct Unnest structs that are contained inside other structs. If a name is given, only structs that are embedded in the named one are considered otherwise all structs inside the file.

Types

type FoundNodes

type FoundNodes struct {
	Node    *ast.Node
	Parents []*ast.Node
}

FoundNodes holds the information for each found node

type TagCombiner

type TagCombiner interface {
	Combine(values []string) (string, error)
}

Jump to

Keyboard shortcuts

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