(enums []Enum, structs []Struct, queries []Query)
| 368 | } |
| 369 | |
| 370 | func filterUnusedStructs(enums []Enum, structs []Struct, queries []Query) ([]Enum, []Struct) { |
| 371 | keepTypes := make(map[string]struct{}) |
| 372 | |
| 373 | for _, query := range queries { |
| 374 | if !query.Arg.isEmpty() { |
| 375 | keepTypes[query.Arg.Type()] = struct{}{} |
| 376 | if query.Arg.IsStruct() { |
| 377 | for _, field := range query.Arg.Struct.Fields { |
| 378 | keepTypes[field.Type] = struct{}{} |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | if query.hasRetType() { |
| 383 | keepTypes[query.Ret.Type()] = struct{}{} |
| 384 | if query.Ret.IsStruct() { |
| 385 | for _, field := range query.Ret.Struct.Fields { |
| 386 | keepTypes[strings.TrimPrefix(field.Type, "[]")] = struct{}{} |
| 387 | for _, embedField := range field.EmbedFields { |
| 388 | keepTypes[embedField.Type] = struct{}{} |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | keepEnums := make([]Enum, 0, len(enums)) |
| 396 | for _, enum := range enums { |
| 397 | _, keep := keepTypes[enum.Name] |
| 398 | _, keepNull := keepTypes["Null"+enum.Name] |
| 399 | _, keepPointer := keepTypes["*"+enum.Name] |
| 400 | if keep || keepNull || keepPointer { |
| 401 | keepEnums = append(keepEnums, enum) |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | keepStructs := make([]Struct, 0, len(structs)) |
| 406 | for _, st := range structs { |
| 407 | if _, ok := keepTypes[st.Name]; ok { |
| 408 | keepStructs = append(keepStructs, st) |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | return keepEnums, keepStructs |
| 413 | } |
no test coverage detected