parseSourceCodeDefinitions.java.spec.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { javaQuery } from "../queries"
  2. import { testParseSourceCodeDefinitions } from "./helpers"
  3. import sampleJavaContent from "./fixtures/sample-java"
  4. /*
  5. TODO: The following structures can be parsed by tree-sitter but lack query support:
  6. 1. Import Declarations:
  7. (import_declaration (scoped_identifier))
  8. - Tree-sitter successfully parses import statements but no query pattern exists
  9. - Example from inspect output: 'import java.util.List;'
  10. - Would enable capturing package dependencies and API usage
  11. 2. Field Declarations:
  12. (field_declaration (modifiers) type: (type_identifier) declarator: (variable_declarator))
  13. - Current query pattern needs enhancement to fully capture modifier information
  14. - Example from inspect output: 'private static final int count = 0;'
  15. - Would improve field visibility and mutability analysis
  16. */
  17. // Java test options
  18. const testOptions = {
  19. language: "java",
  20. wasmFile: "tree-sitter-java.wasm",
  21. queryString: javaQuery,
  22. extKey: "java",
  23. }
  24. describe("parseSourceCodeDefinitionsForFile with Java", () => {
  25. let parseResult: string = ""
  26. beforeAll(async () => {
  27. const result = await testParseSourceCodeDefinitions("/test/file.java", sampleJavaContent, testOptions)
  28. if (!result) {
  29. throw new Error("Failed to parse Java source code")
  30. }
  31. parseResult = result
  32. })
  33. beforeEach(() => {
  34. vi.clearAllMocks()
  35. })
  36. it("should parse package declarations", () => {
  37. expect(parseResult).toMatch(/\d+--\d+ \|\s*package test\.package\.definition/)
  38. })
  39. it("should parse module declarations", () => {
  40. expect(parseResult).toMatch(/\d+--\d+ \|\s*module test\.module\.definition/)
  41. })
  42. it("should parse annotation declarations", () => {
  43. expect(parseResult).toMatch(/\d+--\d+ \|\s*@Target/)
  44. })
  45. it("should parse interface declarations", () => {
  46. expect(parseResult).toMatch(/\d+--\d+ \|\s*public interface TestInterfaceDefinition/)
  47. })
  48. it("should parse enum declarations", () => {
  49. expect(parseResult).toMatch(/\d+--\d+ \|\s*public enum TestEnumDefinition/)
  50. })
  51. it("should parse class declarations", () => {
  52. expect(parseResult).toMatch(/\d+--\d+ \|\s*@TestAnnotationDefinition\(/)
  53. expect(parseResult).toMatch(/\d+--\d+ \|\s*implements TestInterfaceDefinition<T>/)
  54. })
  55. it("should parse abstract class declarations", () => {
  56. expect(parseResult).toMatch(/\d+--\d+ \|\s*public abstract class TestAbstractClassDefinition/)
  57. })
  58. it("should parse inner class declarations", () => {
  59. expect(parseResult).toMatch(/\d+--\d+ \|\s*public class TestInnerClassDefinition/)
  60. })
  61. it("should parse static nested class declarations", () => {
  62. expect(parseResult).toMatch(/\d+--\d+ \|\s*public static class TestStaticNestedClassDefinition/)
  63. })
  64. it("should parse record declarations", () => {
  65. expect(parseResult).toMatch(/\d+--\d+ \|\s*public record TestRecordDefinition/)
  66. })
  67. it("should parse constructor declarations", () => {
  68. expect(parseResult).toMatch(/\d+--\d+ \|\s*public TestClassDefinition\(/)
  69. expect(parseResult).toMatch(/\d+--\d+ \|\s*public TestInnerClassDefinition\(/)
  70. expect(parseResult).toMatch(/\d+--\d+ \|\s*public TestStaticNestedClassDefinition\(/)
  71. })
  72. it("should parse method declarations", () => {
  73. expect(parseResult).toMatch(/\d+--\d+ \|\s*void testInterfaceMethod\(/)
  74. expect(parseResult).toMatch(/\d+--\d+ \|\s*public void testInterfaceMethod\(String message, T data\) {/) // kilocode_change
  75. expect(parseResult).toMatch(/\d+--\d+ \|\s*default String testInterfaceDefaultMethod\(/)
  76. expect(parseResult).toMatch(/\d+--\d+ \|\s*void testMultipleAnnotationMethod\(String message, T data\) {/) // kilocode_change
  77. expect(parseResult).toMatch(/\d+--\d+ \|\s*public <R extends Comparable<R>> R testGenericMethodDefinition\(/)
  78. expect(parseResult).toMatch(/\d+--\d+ \|\s*public String formatMessage\(/)
  79. expect(parseResult).toMatch(/\d+--\d+ \|\s*public abstract String testAbstractMethod\(/)
  80. expect(parseResult).toMatch(/\d+--\d+ \|\s*public void testInnerMethod\(/)
  81. })
  82. })