(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield)
| 1675 | } |
| 1676 | |
| 1677 | async function interfaceOverrideEdges(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield): Promise<Edge[]> { |
| 1678 | let scanned255 = 0; |
| 1679 | const edges: Edge[] = []; |
| 1680 | const seen = new Set<string>(); |
| 1681 | // Memoized: a popular base interface's method list is otherwise re-fetched |
| 1682 | // once per implementer (dubbo-style hub interfaces have hundreds), and the |
| 1683 | // memo only ever serves reads. Same rows, same order — byte-identical. |
| 1684 | const methodsMemo = new Map<string, Node[]>(); |
| 1685 | const methodsOf = (classId: string): Node[] => { |
| 1686 | const hit = methodsMemo.get(classId); |
| 1687 | if (hit) return hit; |
| 1688 | const methods = queries |
| 1689 | .getOutgoingEdges(classId, ['contains']) |
| 1690 | .map((e) => queries.getNodeById(e.target)) |
| 1691 | .filter((n): n is Node => !!n && n.kind === 'method'); |
| 1692 | methodsMemo.set(classId, methods); |
| 1693 | return methods; |
| 1694 | }; |
| 1695 | // A Swift protocol's methods live in its extensions: requirements are not |
| 1696 | // extracted as methods, and `extension EventMonitor { func request(…) }` is |
| 1697 | // where the default implementations a conformer overrides are. A class-kind |
| 1698 | // node sharing a protocol's name is one of its extensions. |
| 1699 | const protocolMemo = new Map<string, Node[]>(); |
| 1700 | const baseMethodsOf = (base: Node): Node[] => { |
| 1701 | if (base.language !== 'swift' || base.kind !== 'interface') return methodsOf(base.id); |
| 1702 | const hit = protocolMemo.get(base.id); |
| 1703 | if (hit) return hit; |
| 1704 | const methods = [ |
| 1705 | ...methodsOf(base.id), |
| 1706 | ...queries |
| 1707 | .getNodesByName(base.name) |
| 1708 | .filter((n) => n.language === 'swift' && n.kind === 'class') |
| 1709 | .flatMap((n) => methodsOf(n.id)), |
| 1710 | ]; |
| 1711 | protocolMemo.set(base.id, methods); |
| 1712 | return methods; |
| 1713 | }; |
| 1714 | // Of a class's same-named methods, the ones that can override one of a |
| 1715 | // base's overloads (#2663): Java, Kotlin, C# and Scala make an override |
| 1716 | // repeat the parameters of what it overrides. Asked only for a name that |
| 1717 | // is overloaded on either side. |
| 1718 | const overridesOf = overrideFilter(ctx); |
| 1719 | const nameCounts = new Map<string, Map<string, number>>(); |
| 1720 | const declaredNamed = (base: Node, name: string): number => { |
| 1721 | let counts = nameCounts.get(base.id); |
| 1722 | if (!counts) { |
| 1723 | counts = new Map(); |
| 1724 | for (const m of baseMethodsOf(base)) counts.set(m.name, (counts.get(m.name) ?? 0) + 1); |
| 1725 | nameCounts.set(base.id, counts); |
| 1726 | } |
| 1727 | return counts.get(name) ?? 0; |
| 1728 | }; |
| 1729 | // A Go struct also satisfies an interface with the methods its embedded |
| 1730 | // types promote into it (goImplementsEdges counts them), and a call through |
| 1731 | // the interface then runs the embedded type's method. Those links are made |
| 1732 | // after the loop, from what the struct's cap has left, so every override |
| 1733 | // keeps its edge, and a provider that implements the interface itself keeps |
| 1734 | // its own. |
no test coverage detected