Skip to content

Commit 24ab961

Browse files
committed
fix: resolve Java method duplication in listCodeDefinitionNames
- Fixed duplication of methods appearing in both interface and class - Removed @OverRide annotations appearing as standalone lines - Interface methods no longer shown individually (shown as part of interface declaration) - Fixed display of actual method/class signatures instead of annotation lines - All methods now appear exactly once in the output
1 parent 0b1b51c commit 24ab961

File tree

10 files changed

+587
-77
lines changed

10 files changed

+587
-77
lines changed

src/debug-full-java-output.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# file.java
2+
2--193 | module test.module.definition {
3+
3--7 | module test.module.definition {
4+
8--8 | package test.package.definition;
5+
10--10 | import java.util.List;
6+
11--11 | import java.util.Map;
7+
12--12 | import java.util.function.Function;
8+
13--13 | import java.time.LocalDateTime;
9+
30--44 | public interface TestInterfaceDefinition<T extends Comparable<T>> {
10+
30--30 | public interface TestInterfaceDefinition<T extends Comparable<T>> {
11+
47--63 | public enum TestEnumDefinition {
12+
53--53 | private final int level;
13+
53--53 | private final int level;
14+
54--54 | private final String description;
15+
54--54 | private final String description;
16+
56--62 | TestEnumDefinition(
17+
66--119 | value = "test",
18+
71--71 | public class TestClassDefinition<T extends Comparable<T>>
19+
75--79 | value = "field",
20+
79--79 | private final String prefix;
21+
80--80 | private static int instanceCount = 0;
22+
80--80 | private static int instanceCount = 0;
23+
83--90 | public TestClassDefinition(
24+
93--99 | public void testInterfaceMethod(
25+
102--108 | public <R extends Comparable<R>> R testGenericMethodDefinition(
26+
102--102 | public <R extends Comparable<R>> R testGenericMethodDefinition(
27+
111--118 | private final Function<String, Integer> testLambdaDefinition = (
28+
111--118 | private final Function<String, Integer> testLambdaDefinition = (
29+
111--118 | private final Function<String, Integer> testLambdaDefinition = (
30+
122--143 | public record TestRecordDefinition(
31+
135--142 | public String formatMessage() {
32+
146--160 | public abstract class TestAbstractClassDefinition<T> {
33+
146--146 | public abstract class TestAbstractClassDefinition<T> {
34+
147--147 | protected final T data;
35+
147--147 | protected final T data;
36+
149--153 | protected TestAbstractClassDefinition(
37+
156--159 | public abstract String testAbstractMethod(
38+
163--192 | public class TestOuterClassDefinition {
39+
164--164 | private int value;
40+
164--164 | private int value;
41+
166--180 | public class TestInnerClassDefinition {
42+
167--167 | private String innerField;
43+
167--167 | private String innerField;
44+
169--173 | public TestInnerClassDefinition(
45+
175--179 | public void testInnerMethod() {
46+
183--191 | public static class TestStaticNestedClassDefinition {
47+
184--184 | private final String nestedField;
48+
184--184 | private final String nestedField;
49+
186--190 | public TestStaticNestedClassDefinition(

src/debug-interface-output.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
=== FULL PARSE RESULT ===
3+
# TestFile.java
4+
2--6 | interface TestInterface {
5+
9--29 | class TestClass implements TestInterface {
6+
11--14 | public void testMethod() {
7+
16--19 | public String getName() {
8+
21--24 | public int calculate(int a, int b) {
9+
26--28 | private void helperMethod() {
10+
11+
========================
12+
13+
=== INDIVIDUAL LINES ===
14+
Line 0: # TestFile.java
15+
Line 1: 2--6 | interface TestInterface {
16+
Line 2: 9--29 | class TestClass implements TestInterface {
17+
Line 3: 11--14 | public void testMethod() {
18+
Line 4: 16--19 | public String getName() {
19+
Line 5: 21--24 | public int calculate(int a, int b) {
20+
Line 6: 26--28 | private void helperMethod() {
21+
========================
22+
23+
=== INTERFACE LINES ===
24+
2--6 | interface TestInterface {
25+
========================
26+
27+
=== testMethod LINES ===
28+
11--14 | public void testMethod() {
29+
========================

src/debug-output.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
=== FULL PARSE RESULT ===
3+
# TestClass.java
4+
1--16 | class TestClass implements TestInterface {
5+
3--6 | public void testMethod() {
6+
8--11 | public String getName() {
7+
13--15 | private void helperMethod() {
8+
9+
========================
10+
11+
=== INDIVIDUAL LINES ===
12+
Line 0: # TestClass.java
13+
Line 1: 1--16 | class TestClass implements TestInterface {
14+
Line 2: 3--6 | public void testMethod() {
15+
Line 3: 8--11 | public String getName() {
16+
Line 4: 13--15 | private void helperMethod() {
17+
========================
18+
19+
=== testMethod LINES ===
20+
3--6 | public void testMethod() {
21+
========================
22+
23+
=== @Override ONLY LINES ===
24+
============================
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, it, expect } from "vitest"
2+
import { testParseSourceCodeDefinitions } from "./helpers"
3+
import { javaQuery } from "../queries"
4+
import sampleJavaContent from "./fixtures/sample-java"
5+
import * as fs from "fs"
6+
7+
describe("Debug full Java parsing", () => {
8+
it("should show what's being captured for full sample", async () => {
9+
const testOptions = {
10+
language: "java",
11+
wasmFile: "tree-sitter-java.wasm",
12+
queryString: javaQuery,
13+
extKey: "java",
14+
}
15+
16+
const parseResult = await testParseSourceCodeDefinitions("/test/file.java", sampleJavaContent, testOptions)
17+
18+
if (parseResult) {
19+
// Write to file
20+
fs.writeFileSync("debug-full-java-output.txt", parseResult)
21+
console.log("Debug output written to debug-full-java-output.txt")
22+
23+
// Check for specific patterns
24+
const lines = parseResult.split("\n").filter((line) => line.trim())
25+
26+
// Check for class with annotations
27+
const classLines = lines.filter((line) => line.includes("TestClassDefinition"))
28+
console.log("\n=== CLASS LINES ===")
29+
classLines.forEach((line) => console.log(line))
30+
31+
// Check for annotation declarations
32+
const annotationLines = lines.filter((line) => line.includes("@Target") || line.includes("@TestAnnotation"))
33+
console.log("\n=== ANNOTATION LINES ===")
34+
annotationLines.forEach((line) => console.log(line))
35+
36+
// Check for interface methods
37+
const interfaceMethodLines = lines.filter(
38+
(line) =>
39+
line.includes("void testInterfaceMethod") ||
40+
line.includes("default String testInterfaceDefaultMethod"),
41+
)
42+
console.log("\n=== INTERFACE METHOD LINES ===")
43+
interfaceMethodLines.forEach((line) => console.log(line))
44+
}
45+
46+
// This test is just for debugging, always pass
47+
expect(true).toBe(true)
48+
})
49+
})
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { describe, it, expect } from "vitest"
2+
import { testParseSourceCodeDefinitions } from "./helpers"
3+
import { javaQuery } from "../queries"
4+
import * as fs from "fs"
5+
6+
describe("Debug Java interface parsing", () => {
7+
it("should show what's being captured for interface", async () => {
8+
const javaContent = `// Test interface with methods
9+
interface TestInterface {
10+
void testMethod();
11+
String getName();
12+
int calculate(int a, int b);
13+
}
14+
15+
// Test class implementing interface with annotations
16+
class TestClass implements TestInterface {
17+
18+
@Override
19+
public void testMethod() {
20+
// Implementation goes here
21+
}
22+
23+
@Override
24+
public String getName() {
25+
return "TestClass";
26+
}
27+
28+
@Override
29+
public int calculate(int a, int b) {
30+
return a + b;
31+
}
32+
33+
private void helperMethod() {
34+
// Helper implementation
35+
}
36+
}`
37+
38+
const testOptions = {
39+
language: "java",
40+
wasmFile: "tree-sitter-java.wasm",
41+
queryString: javaQuery,
42+
extKey: "java",
43+
}
44+
45+
const parseResult = await testParseSourceCodeDefinitions("/test/TestFile.java", javaContent, testOptions)
46+
47+
let debugOutput = ""
48+
49+
if (parseResult) {
50+
debugOutput += "\n=== FULL PARSE RESULT ===\n"
51+
debugOutput += parseResult + "\n"
52+
debugOutput += "========================\n"
53+
54+
const lines = parseResult.split("\n").filter((line) => line.trim())
55+
debugOutput += "\n=== INDIVIDUAL LINES ===\n"
56+
lines.forEach((line, i) => {
57+
debugOutput += `Line ${i}: ${line}\n`
58+
})
59+
debugOutput += "========================\n"
60+
61+
// Check for interface
62+
const interfaceLines = lines.filter((line) => line.includes("interface TestInterface"))
63+
debugOutput += "\n=== INTERFACE LINES ===\n"
64+
interfaceLines.forEach((line) => (debugOutput += line + "\n"))
65+
debugOutput += "========================\n"
66+
67+
// Check for testMethod
68+
const methodLines = lines.filter((line) => line.includes("testMethod"))
69+
debugOutput += "\n=== testMethod LINES ===\n"
70+
methodLines.forEach((line) => (debugOutput += line + "\n"))
71+
debugOutput += "========================\n"
72+
73+
// Write to file
74+
fs.writeFileSync("debug-interface-output.txt", debugOutput)
75+
console.log("Debug output written to debug-interface-output.txt")
76+
}
77+
78+
// This test is just for debugging, always pass
79+
expect(true).toBe(true)
80+
})
81+
})
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { describe, it, expect } from "vitest"
2+
import { testParseSourceCodeDefinitions } from "./helpers"
3+
import { javaQuery } from "../queries"
4+
import * as fs from "fs"
5+
6+
describe("Debug Java parsing", () => {
7+
it("should show what's being captured", async () => {
8+
const javaContent = `class TestClass implements TestInterface {
9+
10+
@Override
11+
public void testMethod() {
12+
// Implementation goes here
13+
}
14+
15+
@Override
16+
public String getName() {
17+
return "TestClass";
18+
}
19+
20+
private void helperMethod() {
21+
// Helper implementation
22+
}
23+
}`
24+
25+
const testOptions = {
26+
language: "java",
27+
wasmFile: "tree-sitter-java.wasm",
28+
queryString: javaQuery,
29+
extKey: "java",
30+
}
31+
32+
const parseResult = await testParseSourceCodeDefinitions("/test/TestClass.java", javaContent, testOptions)
33+
34+
let debugOutput = ""
35+
36+
if (parseResult) {
37+
debugOutput += "\n=== FULL PARSE RESULT ===\n"
38+
debugOutput += parseResult + "\n"
39+
debugOutput += "========================\n"
40+
41+
const lines = parseResult.split("\n").filter((line) => line.trim())
42+
debugOutput += "\n=== INDIVIDUAL LINES ===\n"
43+
lines.forEach((line, i) => {
44+
debugOutput += `Line ${i}: ${line}\n`
45+
})
46+
debugOutput += "========================\n"
47+
48+
// Check for duplicates
49+
const methodLines = lines.filter((line) => line.includes("testMethod"))
50+
debugOutput += "\n=== testMethod LINES ===\n"
51+
methodLines.forEach((line) => (debugOutput += line + "\n"))
52+
debugOutput += "========================\n"
53+
54+
// Check for @Override lines
55+
const overrideLines = lines.filter((line) => {
56+
const content = line.split("|")[1]?.trim() || ""
57+
return content === "@Override"
58+
})
59+
debugOutput += "\n=== @Override ONLY LINES ===\n"
60+
overrideLines.forEach((line) => (debugOutput += line + "\n"))
61+
debugOutput += "============================\n"
62+
63+
// Write to file
64+
fs.writeFileSync("debug-output.txt", debugOutput)
65+
console.log("Debug output written to debug-output.txt")
66+
}
67+
68+
// This test is just for debugging, always pass
69+
expect(true).toBe(true)
70+
})
71+
})
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default String.raw`
2+
// Test interface with methods
3+
interface TestInterface {
4+
void testMethod();
5+
String getName();
6+
int calculate(int a, int b);
7+
}
8+
9+
// Test class implementing interface with annotations
10+
class TestClass implements TestInterface {
11+
12+
@Override
13+
public void testMethod() {
14+
// Implementation goes here
15+
}
16+
17+
@Override
18+
public String getName() {
19+
return "TestClass";
20+
}
21+
22+
@Override
23+
public int calculate(int a, int b) {
24+
return a + b;
25+
}
26+
27+
private void helperMethod() {
28+
// Helper implementation
29+
}
30+
}
31+
`

0 commit comments

Comments
 (0)