astutils

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package astutils provides utility functions for working with AST nodes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncSignatureIs

func FuncSignatureIs(funcDecl *ast.FuncDecl, wantName string, wantParametersTypes, wantResultsTypes []string) bool

FuncSignatureIs returns true if the given func decl satisfies a signature characterized by the given name, parameters types and return types; false otherwise.

Example: to check if a function declaration has the signature Foo(int, string) (bool,error) call to FuncSignatureIs(funcDecl,"Foo",[]string{"int","string"},[]string{"bool","error"}).

func GetTypeNames added in v1.10.0

func GetTypeNames(fields *ast.FieldList) []string

GetTypeNames yields an slice with the string representation of the types of given fields. It yields nil if the field list is nil.

func GoFmt added in v1.10.0

func GoFmt(x any) string

GoFmt returns a string representation of an AST subtree.

func IsCgoExported added in v1.10.0

func IsCgoExported(f *ast.FuncDecl) bool

IsCgoExported returns true if the given function declaration is exported as Cgo function, false otherwise.

func IsIdent added in v1.10.0

func IsIdent(expr ast.Expr, ident string) bool

IsIdent returns true if the given expression is the identifier with name ident, false otherwise.

func IsPkgDotName added in v1.10.0

func IsPkgDotName(expr ast.Expr, pkg, name string) bool

IsPkgDotName returns true if the given expression is a selector expression of the form <pkg>.<name>, false otherwise.

func IsStringLiteral added in v1.10.0

func IsStringLiteral(e ast.Expr) bool

IsStringLiteral returns true if the given expression is a string literal, false otherwise.

func NodeHash added in v1.12.0

func NodeHash(node ast.Node) string

NodeHash yields the MD5 hash of the given AST node.

func PickNodes added in v1.10.0

func PickNodes(n ast.Node, selector func(n ast.Node) bool) []ast.Node

PickNodes yields a list of nodes by picking them from a sub-ast with root node n. Nodes are selected by applying the selector function.

func SeekNode added in v1.12.0

func SeekNode[T ast.Node](n ast.Node, selector func(n ast.Node) bool) T

SeekNode yields the first node selected by the given selector function in the AST subtree with root n. The function returns nil if no matching node is found in the subtree.

Types

This section is empty.

Jump to

Keyboard shortcuts

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