From fd1d1c6450abcef6876b46b6976ff6134dee24bf Mon Sep 17 00:00:00 2001 From: thejesh Date: Sat, 13 Jun 2026 05:26:12 -0700 Subject: [PATCH] =?UTF-8?q?feat(core):=20DartExtractor=20=E2=80=94=20enum?= =?UTF-8?q?=20declarations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds enum_declaration handling to DartExtractor: enum constants are surfaced as properties[] so the structural graph captures Color.red / Color.green etc. Implements Task 9 of the Dart language support plan (TDD, 16/16 dart tests pass, full suite 708/708). Co-Authored-By: Claude Sonnet 4.6 --- .../__tests__/dart-extractor.test.ts | 13 ++++++++ .../src/plugins/extractors/dart-extractor.ts | 33 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts index 3bab6ea..4cf09f2 100644 --- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts +++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/dart-extractor.test.ts @@ -220,6 +220,19 @@ describe("DartExtractor", () => { }); }); + describe("extractStructure - enums", () => { + it("extracts a simple enum and surfaces its constants as properties", () => { + const { tree, parser, root } = parse(`enum Color { red, green, blue }\n`); + const result = extractor.extractStructure(root); + + expect(result.classes).toHaveLength(1); + expect(result.classes[0].name).toBe("Color"); + expect(result.classes[0].properties).toEqual(["red", "green", "blue"]); + tree.delete(); + parser.delete(); + }); + }); + describe("extractStructure - extensions", () => { it("extracts a named extension on String", () => { const { tree, parser, root } = parse(`extension StringX on String { diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts index dacdfee..5e37f46 100644 --- a/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts +++ b/understand-anything-plugin/packages/core/src/plugins/extractors/dart-extractor.ts @@ -241,6 +241,9 @@ export class DartExtractor implements LanguageExtractor { case "extension_declaration": this.extractExtensionDeclaration(node, classes, functions, exports); break; + case "enum_declaration": + this.extractEnumDeclaration(node, classes, exports); + break; } } @@ -348,6 +351,36 @@ export class DartExtractor implements LanguageExtractor { ); } + private extractEnumDeclaration( + declNode: TreeSitterNode, + classes: StructuralAnalysis["classes"], + exports: StructuralAnalysis["exports"], + ): void { + const nameNode = findChild(declNode, "identifier"); + if (!nameNode) return; + const name = nameNode.text; + + const properties: string[] = []; + const body = findChild(declNode, "enum_body"); + if (body) { + for (const k of findChildren(body, "enum_constant")) { + const id = findChild(k, "identifier"); + if (id) properties.push(id.text); + } + } + + classes.push({ + name, + lineRange: [declNode.startPosition.row + 1, declNode.endPosition.row + 1], + methods: [], + properties, + }); + + if (isExported(name)) { + exports.push({ name, lineNumber: declNode.startPosition.row + 1 }); + } + } + extractCallGraph(rootNode: TreeSitterNode): CallGraphEntry[] { // Implementation lands in a later task. void rootNode;