Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 1ee121e

Browse files
committed
feat(kotlin): update class name identifier and add structure tests
1 parent c2268b0 commit 1ee121e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/code-context/kotlin/KotlinProfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class KotlinProfile implements LanguageProfile {
6969
)?
7070
7171
(class_declaration
72-
(type_identifier) @interface-name
72+
(type_identifier) @class-name
7373
(class_body
7474
(property_declaration
7575
(binding_pattern_kind)?

src/code-context/kotlin/KotlinStructurerProvider.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class KotlinStructurerProvider extends BaseStructurerProvider {
9191
interfaceObj.methods = methods.slice();
9292
codeFile.classes.push({ ...interfaceObj });
9393

94-
// 重置字段和方法
9594
methods.length = 0;
9695
fields.length = 0;
9796
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { TestLanguageServiceProvider } from "src/test/TestLanguageService";
2+
import { KotlinStructurerProvider } from "../../../code-context/kotlin/KotlinStructurerProvider";
3+
4+
const Parser = require('web-tree-sitter');
5+
6+
describe('KotlinStructure', () => {
7+
it('should convert a simple file to CodeFile', async () => {
8+
const kotlinHelloWorld = `package com.example
9+
interface Shape {
10+
val vertexCount: Int
11+
}
12+
13+
class Rectangle(override val vertexCount: Int = 4) : Shape // Always has 4 vertices
14+
15+
class Polygon : Shape {
16+
override var vertexCount: Int = 0 // Can be set to any number later
17+
}`;
18+
19+
await Parser.init();
20+
const parser = new Parser();
21+
const languageService = new TestLanguageServiceProvider(parser);
22+
23+
const structurer = new KotlinStructurerProvider();
24+
await structurer.init(languageService);
25+
26+
const codeFile = await structurer.parseFile(kotlinHelloWorld, '');
27+
console.log(codeFile);
28+
});
29+
});

0 commit comments

Comments
 (0)