Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

fix(core): extract abstract class, enum, record, and struct declarations

jiang4wqy2646a6abbf42
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/csharp-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/csharp-extractor.test.ts
index e1534b8d..1406848c 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/csharp-extractor.test.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/csharp-extractor.test.ts
@@ -663,3 +663,42 @@ namespace App.Services
});
});
});
+
+describe("CSharpExtractor - modern type declarations", () => {
+ const extractor = new CSharpExtractor();
+
+ it("extracts a public struct as a class node with its methods", () => {
+ const { tree, parser, root } = parse(`namespace App {
+ public struct Vec {
+ public int X;
+ public void Add() {
+ X = X + 1;
+ }
+ }
+}
+`);
+ const result = extractor.extractStructure(root);
+
+ const vec = result.classes.find((c) => c.name === "Vec");
+ expect(vec).toBeDefined();
+ expect(vec!.methods).toContain("Add");
+ expect(result.exports.some((e) => e.name === "Vec")).toBe(true);
+
+ tree.delete();
+ parser.delete();
+ });
+
+ it("extracts a public record as a class node", () => {
+ const { tree, parser, root } = parse(`namespace App {
+ public record Point(int X, int Y);
+}
+`);
+ const result = extractor.extractStructure(root);
+
+ expect(result.classes.some((c) => c.name === "Point")).toBe(true);
+ expect(result.exports.some((e) => e.name === "Point")).toBe(true);
+
+ tree.delete();
+ parser.delete();
+ });
+});
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/java-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/java-extractor.test.ts
index 17d14add..700e9985 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/java-extractor.test.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/java-extractor.test.ts
@@ -566,3 +566,38 @@ interface Repository {
});
});
});
+
+describe("JavaExtractor - modern type declarations", () => {
+ const extractor = new JavaExtractor();
+
+ it("extracts a public enum as a class node with its methods", () => {
+ const { tree, parser, root } = parse(`public enum Status {
+ ACTIVE, INACTIVE;
+ public boolean isActive() {
+ return this == ACTIVE;
+ }
+}
+`);
+ const result = extractor.extractStructure(root);
+
+ const status = result.classes.find((c) => c.name === "Status");
+ expect(status).toBeDefined();
+ expect(status!.methods).toContain("isActive");
+ expect(result.exports.some((e) => e.name === "Status")).toBe(true);
+
+ tree.delete();
+ parser.delete();
+ });
+
+ it("extracts a public record as a class node", () => {
+ const { tree, parser, root } = parse(`public record Point(int x, int y) {}
+`);
+ const result = extractor.extractStructure(root);
+
+ expect(result.classes.some((c) => c.name === "Point")).toBe(true);
+ expect(result.exports.some((e) => e.name === "Point")).toBe(true);
+
+ tree.delete();
+ parser.delete();
+ });
+});
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/typescript-extractor.test.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/typescript-extractor.test.ts
new file mode 100644
index 00000000..344bc34a
--- /dev/null
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/__tests__/typescript-extractor.test.ts
@@ -0,0 +1,86 @@
+import { describe, it, expect, beforeAll } from "vitest";
+import { createRequire } from "node:module";
+import { TypeScriptExtractor } from "../typescript-extractor.js";
+
+const require = createRequire(import.meta.url);
+
+// Load tree-sitter + TypeScript grammar once
+let Parser: any;
+let Language: any;
+let tsLang: any;
+
+beforeAll(async () => {
+ const mod = await import("web-tree-sitter");
+ Parser = mod.Parser;
+ Language = mod.Language;
+ await Parser.init();
+ const wasmPath = require.resolve(
+ "tree-sitter-typescript/tree-sitter-typescript.wasm",
+ );
+ tsLang = await Language.load(wasmPath);
+});
+
+function parse(code: string) {
+ const parser = new Parser();
+ parser.setLanguage(tsLang);
+ const tree = parser.parse(code);
+ const root = tree.rootNode;
+ return { tree, parser, root };
+}
+
+describe("TypeScriptExtractor", () => {
+ const extractor = new TypeScriptExtractor();
+
+ // Regression guard: a plain class is still extracted.
+ it("extracts a plain class declaration", () => {
+ const { tree, parser, root } = parse(`class Widget {
+ run(): void {
+ console.log("x");
+ }
+}
+`);
+ const result = extractor.extractStructure(root);
+ expect(result.classes.some((c) => c.name === "Widget")).toBe(true);
+ tree.delete();
+ parser.delete();
+ });
+
+ // ---- Abstract classes ----
+
+ describe("extractStructure - abstract classes", () => {
+ it("extracts an abstract class as a class node with its concrete methods", () => {
+ const { tree, parser, root } = parse(`abstract class Repository {
+ abstract find(id: string): Promise<string>;
+ save(value: string): void {
+ this.items.push(value);
+ }
+ private items: string[] = [];
+}
+`);
+ const result = extractor.extractStructure(root);
+
+ const repo = result.classes.find((c) => c.name === "Repository");
+ expect(repo).toBeDefined();
+ expect(repo!.methods).toContain("save");
+
+ tree.delete();
+ parser.delete();
+ });
+
+ it("records an exported abstract class in exports", () => {
+ const { tree, parser, root } = parse(`export abstract class Base {
+ abstract run(): void;
+}
+`);
+ const result = extractor.extractStructure(root);
+
+ expect(result.classes.some((c) => c.name === "Base")).toBe(true);
+ const baseExport = result.exports.find((e) => e.name === "Base");
+ expect(baseExport).toBeDefined();
+ expect(baseExport!.isDefault).toBe(false);
+
+ tree.delete();
+ parser.delete();
+ });
+ });
+});
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/csharp-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/csharp-extractor.ts
index 19b77b5b..abdf40b9 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/csharp-extractor.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/csharp-extractor.ts
@@ -233,6 +233,8 @@ export class CSharpExtractor implements LanguageExtractor {
break;
case "class_declaration":
+ case "record_declaration":
+ case "struct_declaration":
this.extractClass(child, functions, classes, exports);
break;
@@ -263,6 +265,8 @@ export class CSharpExtractor implements LanguageExtractor {
switch (child.type) {
case "class_declaration":
+ case "record_declaration":
+ case "struct_declaration":
this.extractClass(child, functions, classes, exports);
break;
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/java-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/java-extractor.ts
index 4ac3a4f3..ab56e60d 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/java-extractor.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/java-extractor.ts
@@ -112,6 +112,8 @@ export class JavaExtractor implements LanguageExtractor {
break;
case "class_declaration":
+ case "enum_declaration":
+ case "record_declaration":
this.extractClass(node, functions, classes, exports);
break;
@@ -346,6 +348,18 @@ export class JavaExtractor implements LanguageExtractor {
if (!child) continue;
switch (child.type) {
+ case "enum_body_declarations":
+ // Enum methods and members live in a nested enum_body_declarations
+ // node (after the constants); recurse so they are captured.
+ this.extractClassBodyMembers(
+ child,
+ methods,
+ properties,
+ functions,
+ exports,
+ );
+ break;
+
case "method_declaration":
this.extractMethod(child, methods, functions, exports);
break;
diff --git a/understand-anything-plugin/packages/core/src/plugins/extractors/typescript-extractor.ts b/understand-anything-plugin/packages/core/src/plugins/extractors/typescript-extractor.ts
index f8dd4810..8f8aebb9 100644
--- a/understand-anything-plugin/packages/core/src/plugins/extractors/typescript-extractor.ts
+++ b/understand-anything-plugin/packages/core/src/plugins/extractors/typescript-extractor.ts
@@ -208,6 +208,7 @@ export class TypeScriptExtractor implements LanguageExtractor {
this.extractFunction(node, functions);
break;
+ case "abstract_class_declaration":
case "class_declaration":
this.extractClass(node, classes);
break;
@@ -416,6 +417,7 @@ export class TypeScriptExtractor implements LanguageExtractor {
break;
}
+ case "abstract_class_declaration":
case "class_declaration": {
this.extractClass(child, classes);
const nameNode = child.children.find(