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

Function normalizeSpecial

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

Source from the content-addressed store, hash-verified

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