interfaceMethods returns all embedded methods of an interface.
(i *dst.InterfaceType)
| 499 | |
| 500 | // interfaceMethods returns all embedded methods of an interface. |
| 501 | func interfaceMethods(i *dst.InterfaceType) []*dst.Field { |
| 502 | var allMethods []*dst.Field |
| 503 | for _, field := range i.Methods.List { |
| 504 | switch fieldType := field.Type.(type) { |
| 505 | case *dst.FuncType: |
| 506 | allMethods = append(allMethods, field) |
| 507 | case *dst.InterfaceType: |
| 508 | allMethods = append(allMethods, interfaceMethods(fieldType)...) |
| 509 | case *dst.Ident: |
| 510 | // Embedded interfaces are Idents -> TypeSpec -> InterfaceType |
| 511 | // If the embedded interface is not in the parsed file, then |
| 512 | // the Obj will be nil. |
| 513 | if fieldType.Obj != nil { |
| 514 | objDecl, ok := fieldType.Obj.Decl.(*dst.TypeSpec) |
| 515 | if ok { |
| 516 | isInterface, ok := objDecl.Type.(*dst.InterfaceType) |
| 517 | if ok { |
| 518 | allMethods = append(allMethods, interfaceMethods(isInterface)...) |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | return allMethods |
| 525 | } |
no outgoing calls
no test coverage detected