formatTypeParams converts an AST FieldList to a string representation
(params *ast.FieldList)
| 231 | |
| 232 | // formatTypeParams converts an AST FieldList to a string representation |
| 233 | func 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. |
| 258 | func isrtfor(t ast.Expr) bool { return strings.HasPrefix(stringify(t), "msgp.RTFor[") } |