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