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

Function normalizeSpecial

src/extraction/function-ref.ts:638–842  ·  view source on GitHub ↗
(
  node: SyntaxNode,
  type: string,
  source: string
)

Source from the content-addressed store, hash-verified

636}
637
638function normalizeSpecial(
639 node: SyntaxNode,
640 type: string,
641 source: string
642): NormalizedRef[] {
643 switch (type) {
644 // Java method references. Receiver decides the resolution route (#808):
645 // `this::run0` / `super::close` → `this.<m>` (class-scoped resolver;
646 // super rides the inherited-member supertype pass)
647 // `Type::method` (capitalized) → qualified `Type::method` (suffix-
648 // matched against that type's members, cross-file capable)
649 // `variable::method` → nothing (receiver type unknown statically —
650 // the deferred obj.method class)
651 case 'method_reference': {
652 let last: SyntaxNode | null = null;
653 for (let i = 0; i < node.namedChildCount; i++) {
654 const child = node.namedChild(i);
655 if (child && child.type === 'identifier') last = child;
656 }
657 if (!last) return [];
658 const m = getNodeText(last, source);
659 const text = getNodeText(node, source);
660 if (text.startsWith('this::') || text.startsWith('super::')) {
661 return [{ name: `this.${m}`, node: last }];
662 }
663 const recv = text.match(/^([A-Z][A-Za-z0-9_]*)\s*::/);
664 if (recv) {
665 // `Type::method` — but `Type::new` (constructor ref) has no method
666 // node to land on; let the stoplist drop it via the bare name.
667 return m === 'new' ? [] : [{ name: `${recv[1]}::${m}`, node: last }];
668 }
669 return [];
670 }
671
672 // Kotlin `::targetCb` (one part) / `OtherClass::handle` (two parts —
673 // receiver is a type_identifier; lowercase receivers are variables, the
674 // deferred obj.method class).
675 case 'callable_reference': {
676 let receiver: SyntaxNode | null = null;
677 let member: SyntaxNode | null = null;
678 for (let i = 0; i < node.namedChildCount; i++) {
679 const child = node.namedChild(i);
680 if (!child) continue;
681 if (child.type === 'type_identifier') receiver = child;
682 if (child.type === 'simple_identifier') member = child;
683 }
684 if (!member) return [];
685 const m = getNodeText(member, source);
686 if (!receiver) return [{ name: m, node: member }]; // ::topLevelFn
687 const recvText = getNodeText(receiver, source);
688 return /^[A-Z]/.test(recvText)
689 ? [{ name: `${recvText}::${m}`, node: member }]
690 : []; // variable::method — unknown receiver type
691 }
692
693 // Kotlin `this::fire` parses as navigation_expression with a `::fire`
694 // navigation_suffix — route through the class-scoped `this.` resolver.
695 // Ordinary `a.b` navigation (and any non-`this` receiver) MUST yield

Callers 1

normalizeValueFunction · 0.85

Calls 8

getNodeTextFunction · 0.90
getChildByFieldFunction · 0.90
lastNamedOfTypeFunction · 0.85
phpEnclosingCallNameFunction · 0.85
phpStringContentFunction · 0.85
rubyEnclosingCallFunction · 0.85
isRubyHookCallFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected