* Extract a struct
(node: SyntaxNode)
| 1740 | * Extract a struct |
| 1741 | */ |
| 1742 | private extractStruct(node: SyntaxNode): void { |
| 1743 | if (!this.extractor) return; |
| 1744 | |
| 1745 | // Skip forward declarations and type references (no body = not a definition) |
| 1746 | // — EXCEPT C# positional records (`record struct M(decimal Amount);`), |
| 1747 | // complete definitions with no body block. (#831) |
| 1748 | const body = getChildByField(node, this.extractor.bodyField); |
| 1749 | if (!body && node.type !== 'record_declaration') return; |
| 1750 | |
| 1751 | const name = extractName(node, this.source, this.extractor); |
| 1752 | const docstring = getPrecedingDocstring(node, this.source); |
| 1753 | const visibility = this.extractor.getVisibility?.(node); |
| 1754 | const isExported = this.extractor.isExported?.(node, this.source); |
| 1755 | |
| 1756 | const structNode = this.createNode('struct', name, node, { |
| 1757 | docstring, |
| 1758 | visibility, |
| 1759 | isExported, |
| 1760 | }); |
| 1761 | if (!structNode) return; |
| 1762 | |
| 1763 | // Extract inheritance (e.g. Swift: struct HTTPMethod: RawRepresentable) |
| 1764 | this.extractInheritance(node, structNode.id); |
| 1765 | |
| 1766 | // C# primary-constructor parameter dependencies (`struct P(int x)`, and |
| 1767 | // `record struct M(decimal Amount)` which the grammar nests here). |
| 1768 | this.extractCsharpPrimaryCtorParamRefs(node, structNode.id); |
| 1769 | |
| 1770 | // Push to stack for field extraction (bodiless positional records have |
| 1771 | // no members to visit) |
| 1772 | if (body) { |
| 1773 | this.nodeStack.push(structNode.id); |
| 1774 | for (let i = 0; i < body.namedChildCount; i++) { |
| 1775 | const child = body.namedChild(i); |
| 1776 | if (child) { |
| 1777 | this.visitNode(child); |
| 1778 | } |
| 1779 | } |
| 1780 | this.nodeStack.pop(); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /** |
| 1785 | * Extract an enum |
no test coverage detected