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

Function receiverTypeFor

src/ui-server/api/steps.ts:498–517  ·  view source on GitHub ↗
(caller: Node, callee: string)

Source from the content-addressed store, hash-verified

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);

Callers 3

resolveByReceiverFunction · 0.85
effectLinkFunction · 0.85
buildStepsFunction · 0.85

Calls 7

escapeRegExpFunction · 0.90
memberTypesOfFunction · 0.85
hasMethod · 0.80
getMethod · 0.65
getNodesInFileMethod · 0.65
execMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected