(caller: Node, callee: string)
| 496 | const fileTypes = new Map<string, Map<string, string>>(); |
| 497 | const classTypes = new Map<string, Map<string, string>>(); |
| 498 | const receiverTypeFor = async (caller: Node, callee: string): Promise<string | null> => { |
| 499 | const first = callee.replace(/^(?:this|self)\./, '').split(/[.:(]/)[0] ?? ''; |
| 500 | if (!first || /^[A-Z]/.test(first)) return null; |
| 501 | const declared = await memberTypesOf(caller); |
| 502 | const own = declared.get(first) ?? declared.get(first.replace(/^_/, '')) ?? null; |
| 503 | if (own) return own; |
| 504 | let types = fileTypes.get(caller.filePath); |
| 505 | if (!types) { |
| 506 | types = new Map(); |
| 507 | for (const n of cg.getNodesInFile(caller.filePath)) { |
| 508 | if ((n.kind !== 'field' && n.kind !== 'property' && n.kind !== 'variable' && n.kind !== 'parameter') || !n.signature) continue; |
| 509 | const sig = n.signature.replace(/\s+/g, ' ').trim(); |
| 510 | // `OwnerRepository owners`, `private final OwnerRepository owners`, `owners: OwnerRepository`, `val owners: OwnerRepository`. |
| 511 | const typed = new RegExp(`(?:^|\\s)([A-Z][\\w<>,?. ]*?)\\s+${escapeRegExp(n.name)}\\b`).exec(sig) ?? new RegExp(`\\b${escapeRegExp(n.name)}\\s*:\\s*([A-Z][\\w<>,?. ]*)`).exec(sig); |
| 512 | if (typed && !types.has(n.name)) types.set(n.name, typed[1]!.trim()); |
| 513 | } |
| 514 | fileTypes.set(caller.filePath, types); |
| 515 | } |
| 516 | return types.get(first) ?? null; |
| 517 | }; |
| 518 | const memberTypesOf = async (node: Node): Promise<Map<string, string>> => { |
| 519 | const key = `${node.filePath}:${node.startLine}`; |
| 520 | let types = classTypes.get(key); |
no test coverage detected