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

Function normalizeSpecial

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

Source from the content-addressed store, hash-verified

641}
642
643function normalizeSpecial(
644 node: SyntaxNode,
645 type: string,
646 source: string
647): NormalizedRef[] {
648 switch (type) {
649 // Java method references. Receiver decides the resolution route (#808):
650 // `this::run0` / `super::close` → `this.<m>` (class-scoped resolver;
651 // super rides the inherited-member supertype pass)
652 // `Type::method` (capitalized) → qualified `Type::method` (suffix-
653 // matched against that type's members, cross-file capable)
654 // `variable::method` → nothing (receiver type unknown statically —
655 // the deferred obj.method class)
656 case 'method_reference': {
657 let last: SyntaxNode | null = null;
658 for (const child of node.namedChildren) {
659 if (child && child.type === 'identifier') last = child;
660 }
661 if (!last) return [];
662 const m = getNodeText(last, source);
663 const text = getNodeText(node, source);
664 if (text.startsWith('this::') || text.startsWith('super::')) {
665 return [{ name: `this.${m}`, node: last }];
666 }
667 const recv = text.match(/^([A-Z][A-Za-z0-9_]*)\s*::/);
668 if (recv) {
669 // `Type::method` — but `Type::new` (constructor ref) has no method
670 // node to land on; let the stoplist drop it via the bare name.
671 return m === 'new' ? [] : [{ name: `${recv[1]}::${m}`, node: last }];
672 }
673 return [];
674 }
675
676 // Rust `Graph::counts`, `crate::graph::Graph::counts`, `Self::helper`
677 // (#3254): a function named through its path. The whole path is kept;
678 // resolution reads it as the same path written as a call would be, so the
679 // module, `use` and `Self` rules of a call decide what it names. Only a
680 // function-like last segment qualifies (a capitalized one is a variant or
681 // a constant); a generic path (`Vec::<u8>::new`) is left alone.
682 case 'scoped_identifier': {
683 const name = getChildByField(node, 'name');
684 if (!name || name.type !== 'identifier' || !/^(?:r#)?[a-z_]/.test(getNodeText(name, source))) return [];
685 const text = getNodeText(node, source).replace(/\s+/g, '');
686 return /^[A-Za-z_][\w:#]*$/.test(text) ? [{ name: text, node: name }] : [];
687 }
688
689 // Kotlin `::targetCb` (one part) / `OtherClass::handle` (two parts —
690 // receiver is a type_identifier; lowercase receivers are variables, the
691 // deferred obj.method class).
692 case 'callable_reference': {
693 let receiver: SyntaxNode | null = null;
694 let member: SyntaxNode | null = null;
695 for (const child of node.namedChildren) {
696 if (!child) continue;
697 if (child.type === 'type_identifier') receiver = child;
698 if (child.type === 'simple_identifier') member = child;
699 }
700 if (!member) return [];

Callers 1

normalizeValueFunction · 0.85

Calls 9

getNodeTextFunction · 0.90
getChildByFieldFunction · 0.90
namedChildrenOfFunction · 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