Skip to content

Commit 75670f3

Browse files
committed
fix: simplify Java method signature detection to avoid backtracking issues
1 parent a0be919 commit 75670f3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/services/tree-sitter/index.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,11 @@ async function parseFile(
444444
* @returns The line index of the method signature
445445
*/
446446
function findJavaMethodSignatureLine(lines: string[], startLine: number, endLine: number): number {
447-
// Java method signature pattern:
448-
// - May start with access modifiers (public, private, protected, static, final, etc.)
449-
// - Followed by return type
450-
// - Followed by method name
451-
// - Followed by parentheses
452-
// Using atomic groups and possessive quantifiers to prevent backtracking
453-
const methodSignaturePattern =
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*\(/
447+
// Java method signature pattern - avoiding backtracking issues
448+
// Split into separate checks to avoid complex alternations
449+
const accessModifiers = /^\s*(?:public|private|protected)\s+/
450+
const otherModifiers = /^\s*(?:static|final|abstract|synchronized|native|strictfp)\s+/
451+
const methodPattern = /^\s*(?:\w+(?:\[\])*(?:\s*<[^>]+>)?\s+)+\w+\s*\(/
455452

456453
for (let i = startLine; i <= endLine; i++) {
457454
const line = lines[i].trim()
@@ -461,8 +458,9 @@ function findJavaMethodSignatureLine(lines: string[], startLine: number, endLine
461458
continue
462459
}
463460

464-
// Check if this line looks like a method signature
465-
if (methodSignaturePattern.test(line)) {
461+
// Check if this looks like a method signature using multiple simple patterns
462+
// This avoids complex alternation that can cause backtracking
463+
if (accessModifiers.test(line) || otherModifiers.test(line) || methodPattern.test(line)) {
466464
return i
467465
}
468466
}

0 commit comments

Comments
 (0)