@@ -444,14 +444,11 @@ async function parseFile(
444444 * @returns The line index of the method signature
445445 */
446446function 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 * (?: p u b l i c | p r i v a t e | p r o t e c t e d | s t a t i c | f i n a l | a b s t r a c t | s y n c h r o n i z e d | n a t i v e | s t r i c t f p | \w + ) (?: \s + (?: p u b l i c | p r i v a t e | p r o t e c t e d | s t a t i c | f i n a l | a b s t r a c t | s y n c h r o n i z e d | n a t i v e | s t r i c t f p | \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 * (?: p u b l i c | p r i v a t e | p r o t e c t e d ) \s + /
450+ const otherModifiers = / ^ \s * (?: s t a t i c | f i n a l | a b s t r a c t | s y n c h r o n i z e d | n a t i v e | s t r i c t f p ) \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