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

Function resolveStaticMember

src/resolution/import-resolver.ts:4504–4535  ·  view source on GitHub ↗
(
  container: Node,
  ref: UnresolvedRef,
  localName: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

4502}
4503
4504function resolveStaticMember(
4505 container: Node,
4506 ref: UnresolvedRef,
4507 localName: string,
4508 context: ResolutionContext
4509): Node | undefined {
4510 if (!STATIC_MEMBER_CONTAINERS.has(container.kind)) return undefined;
4511 // First segment after the receiver: `Foo.bar.baz` → `bar`.
4512 const [member, ...rest] = ref.referenceName.slice(localName.length + 1).split('.');
4513 if (!member) return undefined;
4514
4515 const candidates = context
4516 .getNodesByQualifiedName(`${container.qualifiedName}::${member}`)
4517 .filter((n) => n.filePath === container.filePath);
4518 if (candidates.length === 0) return undefined;
4519
4520 // A Python reference keeps its whole chain, and it reads the chain's last
4521 // link: `Foo.bar.fset()` is no call of `bar`, nor `Foo.Inner.objects.create()`
4522 // a new `Inner`, but `Foo.Inner.run()` is `Inner`'s `run`.
4523 if (ref.language === 'python' && rest.length > 0) {
4524 const next = candidates.find((n) => STATIC_MEMBER_CONTAINERS.has(n.kind));
4525 return next && resolveStaticMember(next, { ...ref, referenceName: `${member}.${rest.join('.')}` }, member, context);
4526 }
4527
4528 // When the reference is a call, prefer a callable member if several nodes
4529 // share the qualifiedName (e.g. a static property and a method).
4530 if (ref.referenceKind === 'calls') {
4531 const callable = candidates.find((n) => n.kind === 'method' || n.kind === 'function');
4532 if (callable) return callable;
4533 }
4534 return candidates[0];
4535}
4536
4537/**
4538 * Is `name`, as used in `ref`'s file, bound by an import whose module lives

Callers 1

resolveViaImportFunction · 0.85

Calls 3

hasMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected