(f *dst.File, interfaceName string)
| 380 | } |
| 381 | |
| 382 | func loadInterfaceFuncs(f *dst.File, interfaceName string) ([]querierFunction, error) { |
| 383 | var querier *dst.InterfaceType |
| 384 | for _, decl := range f.Decls { |
| 385 | genDecl, ok := decl.(*dst.GenDecl) |
| 386 | if !ok { |
| 387 | continue |
| 388 | } |
| 389 | |
| 390 | for _, spec := range genDecl.Specs { |
| 391 | typeSpec, ok := spec.(*dst.TypeSpec) |
| 392 | if !ok { |
| 393 | continue |
| 394 | } |
| 395 | // This is the name of the interface. If that ever changes, |
| 396 | // this will need to be updated. |
| 397 | if typeSpec.Name.Name != interfaceName { |
| 398 | continue |
| 399 | } |
| 400 | querier, ok = typeSpec.Type.(*dst.InterfaceType) |
| 401 | if !ok { |
| 402 | return nil, xerrors.Errorf("unexpected sqlcQuerier type: %T", typeSpec.Type) |
| 403 | } |
| 404 | break |
| 405 | } |
| 406 | } |
| 407 | if querier == nil { |
| 408 | return nil, xerrors.Errorf("querier not found") |
| 409 | } |
| 410 | funcs := []querierFunction{} |
| 411 | allMethods := interfaceMethods(querier) |
| 412 | for _, method := range allMethods { |
| 413 | funcType, ok := method.Type.(*dst.FuncType) |
| 414 | if !ok { |
| 415 | continue |
| 416 | } |
| 417 | |
| 418 | for _, t := range []*dst.FieldList{funcType.Params, funcType.Results, funcType.TypeParams} { |
| 419 | if t == nil { |
| 420 | continue |
| 421 | } |
| 422 | for _, f := range t.List { |
| 423 | var ident *dst.Ident |
| 424 | switch t := f.Type.(type) { |
| 425 | case *dst.Ident: |
| 426 | ident = t |
| 427 | case *dst.StarExpr: |
| 428 | ident, ok = t.X.(*dst.Ident) |
| 429 | if !ok { |
| 430 | continue |
| 431 | } |
| 432 | case *dst.SelectorExpr: |
| 433 | ident, ok = t.X.(*dst.Ident) |
| 434 | if !ok { |
| 435 | continue |
| 436 | } |
| 437 | case *dst.ArrayType: |
| 438 | ident, ok = t.Elt.(*dst.Ident) |
| 439 | if !ok { |
no test coverage detected