mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
feat(core): DartExtractor — enum declarations
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 <noreply@anthropic.com>
This commit is contained in:
+13
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user