* Interface/registry-dispatch announcement — #687 extended to GRAPH-visible * polymorphism (the body-scan can't see it: `nodeType.execute()` is textually * an ordinary call; the polymorphism lives in the `implements`/`extends` edges). * * A method the agent named that resolves to a large
(cg: CodeGraph, candidates: Array<{ token: string; family: Node[] }>, named: Map<string, Node>)
| 4037 | * TRUE graph-wide implementer count, NOT their frequency in the sample. |
| 4038 | */ |
| 4039 | private buildPolymorphicBoundaries(cg: CodeGraph, candidates: Array<{ token: string; family: Node[] }>, named: Map<string, Node>): string { |
| 4040 | const CLASSY = new Set(['class', 'struct', 'interface', 'trait', 'protocol', 'abstract']); |
| 4041 | const MIN_IMPL = 8; // a supertype needs >= this many implementers to count as "polymorphic" |
| 4042 | const MIN_SUPPORT = 2; // >= this many sampled definers must share the supertype (ties it to the token) |
| 4043 | const SAMPLE = 40; // family members inspected per token |
| 4044 | const MAX_NOTES = 3; |
| 4045 | const rel = (p: string) => p.replace(/\\/g, '/'); |
| 4046 | const containerOf = (m: Node): Node | null => { |
| 4047 | try { const ce = cg.getIncomingEdges(m.id).find((e) => e.kind === 'contains'); return ce ? cg.getNode(ce.source) : null; } |
| 4048 | catch { return null; } |
| 4049 | }; |
| 4050 | // A supertype dispatches only a member it (or an ancestor) declares. Without |
| 4051 | // this, any name shared by enough subclasses read as dispatch through their |
| 4052 | // common base: on vscode the query word `extension`, a getter on unrelated |
| 4053 | // classes that all extend `Disposable`, was announced as "runtime dispatch to |
| 4054 | // 2706 types implementing Disposable" at the top of 9 of 31 answers. |
| 4055 | // |
| 4056 | // A Swift protocol and each of its extensions are separate nodes of one name, |
| 4057 | // and a conformer's edge may land on any of them (Alamofire's |
| 4058 | // `RequestInterceptor` conformers point at an extension in OfflineRetrier.swift |
| 4059 | // that has no `adapt`), so every same-named type is asked. The answer is |
| 4060 | // `unknown`, and the announcement stays, whenever absence can't be judged: |
| 4061 | // nothing on the chain has indexed members of the family's sort, or an |
| 4062 | // interface/protocol on it has none (Swift requirements aren't nodes, so |
| 4063 | // `URLRequestConvertible` can't be said to lack `asURLRequest`). |
| 4064 | const memberOfSupertype = (typeId: string, name: string, callable: boolean): 'declared' | 'absent' | 'unknown' => { |
| 4065 | const counts = (kind: string) => !callable || kind === 'method' || kind === 'function'; |
| 4066 | let sawMembers = false; |
| 4067 | let opaque = false; |
| 4068 | const seen = new Set<string>(); |
| 4069 | const visit = (id: string, depth: number): boolean => { |
| 4070 | if (seen.has(id)) return false; |
| 4071 | seen.add(id); |
| 4072 | let node: Node | null = null; |
| 4073 | let edges: ReturnType<typeof cg.getOutgoingEdges> = []; |
| 4074 | try { node = cg.getNode(id); edges = cg.getOutgoingEdges(id); } catch { return false; } |
| 4075 | let own = 0; |
| 4076 | for (const e of edges) { |
| 4077 | if (e.kind !== 'contains') continue; |
| 4078 | let child: Node | null = null; |
| 4079 | try { child = cg.getNode(e.target); } catch { child = null; } |
| 4080 | if (!child) continue; |
| 4081 | if (child.name === name) return true; |
| 4082 | if (counts(child.kind)) own++; |
| 4083 | } |
| 4084 | if (own > 0) sawMembers = true; |
| 4085 | else if (node && (node.kind === 'interface' || node.kind === 'protocol' || node.kind === 'trait')) opaque = true; |
| 4086 | if (depth >= 3) return false; |
| 4087 | return edges.some((e) => (e.kind === 'extends' || e.kind === 'implements') && visit(e.target, depth + 1)); |
| 4088 | }; |
| 4089 | let root: Node | null = null; |
| 4090 | try { root = cg.getNode(typeId); } catch { root = null; } |
| 4091 | let namesakes: Node[] = []; |
| 4092 | try { |
| 4093 | namesakes = root |
| 4094 | ? cg.getNodesByName(root.name).filter((n) => n.language === root!.language && CLASSY.has(n.kind)) |
| 4095 | : []; |
| 4096 | } catch { namesakes = []; } |
no test coverage detected