ast

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGenericFunc

func IsGenericFunc(funcDecl *ast.FuncDecl) bool

func JoinQuoteNames

func JoinQuoteNames(names []string, sep string) string

func ParseReceiverInfo

func ParseReceiverInfo(fnName string, receiverType ast.Expr) (identityName string, recvPtr bool, recvGeneric bool, recvType *ast.Ident)

func ParseReceiverType

func ParseReceiverType(typeExpr ast.Expr) (ptr bool, generic bool, recvType *ast.Ident)

ParseReceiverType parses a method receiver type expression, extracting whether it is a pointer receiver, a generic receiver, and the underlying type name as an *ast.Ident.

It handles these receiver forms (all unwrapped to the base type name):

T         → ptr=false, generic=false, recv="T"
*T        → ptr=true,  generic=false, recv="T"
T[K]      → ptr=false, generic=true,  recv="T"
*T[K]     → ptr=true,  generic=true,  recv="T"
pkg.T     → ptr=false, generic=false, recv="T"  (ast.SelectorExpr)
*pkg.T    → ptr=true,  generic=false, recv="T"  (StarExpr→SelectorExpr)
*pkg.T[K] → ptr=true,  generic=true,  recv="T"  (StarExpr→IndexExpr→SelectorExpr)

The SelectorExpr case occurs when a method receiver references a type from another package (e.g., *otherpkg.Type). The Go AST represents this as *ast.StarExpr{X: *ast.SelectorExpr{X: pkg, Sel: Type}}. Previously this caused a panic because the function only checked for *ast.Ident after unwrapping pointer and generic wrappers. The fix extracts selExpr.Sel, which is the *ast.Ident for the type name portion (e.g., "Type").

func QuoteNames

func QuoteNames(names []string) []string

Types

This section is empty.

Jump to

Keyboard shortcuts

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