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