MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / interfaceOverrideEdges

Function interfaceOverrideEdges

src/resolution/callback-synthesizer.ts:1741–1922  ·  view source on GitHub ↗
(queries: QueryBuilder, ctx: ResolutionContext, onYield: MaybeYield)

Source from the content-addressed store, hash-verified

1739}
1740
1741async 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.

Callers 1

Calls 15

overrideFilterFunction · 0.90
goPromotionsFunction · 0.85
baseMethodsOfFunction · 0.85
declaredNamedFunction · 0.85
goMethodKeyFunction · 0.85
mapMethod · 0.80
iterateNodesByKindInMethod · 0.80
hasMethod · 0.80
pushMethod · 0.80
methodsOfFunction · 0.70
keyOfFunction · 0.70
iterateNodesByKindMethod · 0.65

Tested by

no test coverage detected