* Extract an enum
(node: SyntaxNode)
| 1918 | * Extract an enum |
| 1919 | */ |
| 1920 | private extractEnum(node: SyntaxNode): void { |
| 1921 | if (!this.extractor) return; |
| 1922 | |
| 1923 | // Skip forward declarations and type references (no body = not a definition) |
| 1924 | const body = this.extractor.resolveBody?.(node, this.extractor.bodyField) |
| 1925 | ?? getChildByField(node, this.extractor.bodyField); |
| 1926 | if (!body) return; |
| 1927 | |
| 1928 | const name = extractName(node, this.source, this.extractor); |
| 1929 | const docstring = getPrecedingDocstring(node, this.source); |
| 1930 | const visibility = this.extractor.getVisibility?.(node); |
| 1931 | const isExported = this.extractor.isExported?.(node, this.source); |
| 1932 | |
| 1933 | const enumNode = this.createNode('enum', name, node, { |
| 1934 | docstring, |
| 1935 | visibility, |
| 1936 | isExported, |
| 1937 | }); |
| 1938 | if (!enumNode) return; |
| 1939 | |
| 1940 | // Extract inheritance (e.g. Swift: enum AFError: Error) |
| 1941 | this.extractInheritance(node, enumNode.id); |
| 1942 | |
| 1943 | // Push to stack and visit body children (enum members, nested types, methods) |
| 1944 | this.nodeStack.push(enumNode.id); |
| 1945 | |
| 1946 | const memberTypes = this.extractor.enumMemberTypes; |
| 1947 | for (let i = 0; i < body.namedChildCount; i++) { |
| 1948 | const child = body.namedChild(i); |
| 1949 | if (!child) continue; |
| 1950 | |
| 1951 | if (memberTypes?.includes(child.type)) { |
| 1952 | this.extractEnumMembers(child); |
| 1953 | } else { |
| 1954 | this.visitNode(child); |
| 1955 | } |
| 1956 | } |
| 1957 | this.nodeStack.pop(); |
| 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Extract enum member names from an enum member node. |
no test coverage detected