(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield)
| 1739 | } |
| 1740 | |
| 1741 | async function interfaceOverrideEdges(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield): Promise<Edge[]> { |
| 1742 | let scanned255 = 0; |
| 1743 | const edges: Edge[] = []; |
| 1744 | const seen = new Set<string>(); |
| 1745 | // Memoized: a popular base interface's method list is otherwise re-fetched |
| 1746 | // once per implementer (dubbo-style hub interfaces have hundreds), and the |
| 1747 | // memo only ever serves reads. Same rows, same order — byte-identical. |
| 1748 | const methodsMemo = new Map<string, Node[]>(); |
| 1749 | const methodsOf = (classId: string): Node[] => { |
| 1750 | const hit = methodsMemo.get(classId); |
| 1751 | if (hit) return hit; |
| 1752 | const methods = queries |
| 1753 | .getOutgoingEdges(classId, ['contains']) |
| 1754 | .map((e) => queries.getNodeById(e.target)) |
| 1755 | .filter((n): n is Node => !!n && n.kind === 'method'); |
| 1756 | methodsMemo.set(classId, methods); |
| 1757 | return methods; |
| 1758 | }; |
| 1759 | // A Swift protocol's methods live in its extensions: requirements are not |
| 1760 | // extracted as methods, and `extension EventMonitor { func request(…) }` is |
| 1761 | // where the default implementations a conformer overrides are. A class-kind |
| 1762 | // node sharing a protocol's name is one of its extensions. |
| 1763 | const protocolMemo = new Map<string, Node[]>(); |
| 1764 | const baseMethodsOf = (base: Node): Node[] => { |
| 1765 | if (base.language !== 'swift' || base.kind !== 'interface') return methodsOf(base.id); |
| 1766 | const hit = protocolMemo.get(base.id); |
| 1767 | if (hit) return hit; |
| 1768 | const methods = [ |
| 1769 | ...methodsOf(base.id), |
| 1770 | ...queries |
| 1771 | .getNodesByName(base.name) |
| 1772 | .filter((n) => n.language === 'swift' && n.kind === 'class') |
| 1773 | .flatMap((n) => methodsOf(n.id)), |
| 1774 | ]; |
| 1775 | protocolMemo.set(base.id, methods); |
| 1776 | return methods; |
| 1777 | }; |
| 1778 | // Of a class's same-named methods, the ones that can override one of a |
| 1779 | // base's overloads (#2663): Java, Kotlin, C# and Scala make an override |
| 1780 | // repeat the parameters of what it overrides. Asked only for a name that |
| 1781 | // is overloaded on either side. |
| 1782 | const overridesOf = overrideFilter(ctx); |
| 1783 | const nameCounts = new Map<string, Map<string, number>>(); |
| 1784 | const declaredNamed = (base: Node, name: string): number => { |
| 1785 | let counts = nameCounts.get(base.id); |
| 1786 | if (!counts) { |
| 1787 | counts = new Map(); |
| 1788 | for (const m of baseMethodsOf(base)) counts.set(m.name, (counts.get(m.name) ?? 0) + 1); |
| 1789 | nameCounts.set(base.id, counts); |
| 1790 | } |
| 1791 | return counts.get(name) ?? 0; |
| 1792 | }; |
| 1793 | // A Go struct also satisfies an interface with the methods its embedded |
| 1794 | // types promote into it (goImplementsEdges counts them), and a call through |
| 1795 | // the interface then runs the embedded type's method. Those links are made |
| 1796 | // after the loop, from what the struct's cap has left, so every override |
| 1797 | // keeps its edge, and a provider that implements the interface itself keeps |
| 1798 | // its own. |
no test coverage detected