* Extract a class
(node: SyntaxNode, kind: NodeKind = 'class')
| 1677 | * Extract a class |
| 1678 | */ |
| 1679 | private extractClass(node: SyntaxNode, kind: NodeKind = 'class'): void { |
| 1680 | if (!this.extractor) return; |
| 1681 | |
| 1682 | // Skip forward declarations / elaborated type references (`class Foo;`) in |
| 1683 | // languages that opt in — bodiless there means "not a definition", so it |
| 1684 | // would otherwise mint a phantom node competing with the real definition |
| 1685 | // (#1093). Languages where a bodiless class is complete (Kotlin, Scala) |
| 1686 | // leave the flag unset. Resolved once here and reused for the body walk. |
| 1687 | const resolvedBody = this.extractor.resolveBody?.(node, this.extractor.bodyField) |
| 1688 | ?? getChildByField(node, this.extractor.bodyField); |
| 1689 | if (this.extractor.skipBodilessClass && !resolvedBody) return; |
| 1690 | |
| 1691 | const name = extractName(node, this.source, this.extractor); |
| 1692 | const docstring = getPrecedingDocstring(node, this.source); |
| 1693 | const visibility = this.extractor.getVisibility?.(node); |
| 1694 | const isExported = this.extractor.isExported?.(node, this.source); |
| 1695 | |
| 1696 | const classNode = this.createNode(kind, name, node, { |
| 1697 | docstring, |
| 1698 | visibility, |
| 1699 | isExported, |
| 1700 | }); |
| 1701 | if (!classNode) return; |
| 1702 | |
| 1703 | // Extract extends/implements |
| 1704 | this.extractInheritance(node, classNode.id); |
| 1705 | |
| 1706 | // C# primary-constructor parameter dependencies (`class Svc(IRepo r, …)`). |
| 1707 | this.extractCsharpPrimaryCtorParamRefs(node, classNode.id); |
| 1708 | |
| 1709 | // Extract decorators applied to the class (`@Foo class X {}`). |
| 1710 | this.extractDecoratorsFor(node, classNode.id); |
| 1711 | |
| 1712 | // Push to stack and visit body |
| 1713 | this.nodeStack.push(classNode.id); |
| 1714 | const body = resolvedBody ?? node; |
| 1715 | |
| 1716 | // Visit all children for methods and properties |
| 1717 | for (let i = 0; i < body.namedChildCount; i++) { |
| 1718 | const child = body.namedChild(i); |
| 1719 | if (child) { |
| 1720 | this.visitNode(child); |
| 1721 | } |
| 1722 | } |
| 1723 | |
| 1724 | // Synthesize compile-time-generated members (Lombok accessors, #912). Runs |
| 1725 | // after the body so the hook can dedup against hand-written members, and |
| 1726 | // while the class is still on the stack so containment/QNs attach. |
| 1727 | if (this.extractor.synthesizeMembers) { |
| 1728 | this.extractor.synthesizeMembers(node, this.makeExtractorContext()); |
| 1729 | } |
| 1730 | |
| 1731 | this.nodeStack.pop(); |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * Extract a method |
no test coverage detected