MCPcopy
hub / github.com/tinylib/msgp / formatTypeParams

Function formatTypeParams

parse/getast.go:233–255  ·  view source on GitHub ↗

formatTypeParams converts an AST FieldList to a string representation

(params *ast.FieldList)

Source from the content-addressed store, hash-verified

231
232// formatTypeParams converts an AST FieldList to a string representation
233func formatTypeParams(params *ast.FieldList) string {
234 if params == nil || params.NumFields() == 0 {
235 return ""
236 }
237
238 var paramStrs []string
239 for _, field := range params.List {
240 // Convert underscores to _RTn where n is the number of the parameter
241 convert := isrtfor(field.Type)
242
243 // Each field can have multiple names (e.g., T, U constraint)
244 for _, name := range field.Names {
245 if convert && name.Name == "_" {
246 name.Name = fmt.Sprintf("_RT%d", len(paramStrs)+1)
247 }
248 // For method receivers, we only include the type parameter name
249 // The constraints are defined in the type declaration, not the method receiver
250 paramStrs = append(paramStrs, name.Name)
251 }
252 }
253
254 return "[" + strings.Join(paramStrs, ", ") + "]"
255}
256
257// isrtfor returns whether the provided expression is a msgp.RTFor[T] pattern.
258func isrtfor(t ast.Expr) bool { return strings.HasPrefix(stringify(t), "msgp.RTFor[") }

Callers 1

processMethod · 0.85

Calls 1

isrtforFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…