@@ -405,7 +405,36 @@ private boolean isTestCode(String filePath) {
405405 // Utility from old MethodAnalyzer to find source file for a class.
406406 // This might need to be made more robust or use ProjectCtx information.
407407 public String getSourceFilePathForClass (String className , String sourceRootPath ) {
408- String classPath = className .replace ('.' , File .separatorChar ) + ".java" ;
408+ // Handle inner classes: for inner classes like "com.example.Outer.Inner",
409+ // we need to find the file for "com.example.Outer.java"
410+ String outerClassName = className ;
411+ if (className .contains ("." ) && Character .isUpperCase (className .charAt (className .lastIndexOf ('.' ) + 1 ))) {
412+ // This might be an inner class. Find the outer class.
413+ // Look for pattern like "package.Class.InnerClass" where the last part starts with uppercase
414+ String [] parts = className .split ("\\ ." );
415+ StringBuilder outerClassBuilder = new StringBuilder ();
416+
417+ for (int i = 0 ; i < parts .length ; i ++) {
418+ if (i > 0 && Character .isUpperCase (parts [i ].charAt (0 ))) {
419+ // Found first part that starts with uppercase, this might be the start of class names
420+ // Check if we already have a class name (outer class)
421+ if (outerClassBuilder .length () > 0 && Character .isUpperCase (parts [i -1 ].charAt (0 ))) {
422+ // Previous part was also a class name, so current part is inner class
423+ break ;
424+ }
425+ }
426+
427+ if (outerClassBuilder .length () > 0 ) {
428+ outerClassBuilder .append ("." );
429+ }
430+ outerClassBuilder .append (parts [i ]);
431+ }
432+ outerClassName = outerClassBuilder .toString ();
433+ }
434+
435+ System .out .println ("DEBUG: Looking for source file - Original class: " + className + ", Outer class: " + outerClassName );
436+
437+ String classPath = outerClassName .replace ('.' , File .separatorChar ) + ".java" ;
409438 Path effectiveSourceRoot = Paths .get (sourceRootPath );
410439
411440 // Attempt to find in standard main/java or test/java if sourceRootPath is project root
@@ -434,13 +463,14 @@ public String getSourceFilePathForClass(String className, String sourceRootPath)
434463 .collect (Collectors .toList ());
435464 if (!foundPaths .isEmpty ()) {
436465 // Prefer paths that match more closely or handle multiple matches if necessary
466+ System .out .println ("DEBUG: Found source file: " + foundPaths .get (0 ).toString ());
437467 return foundPaths .get (0 ).toString ();
438468 }
439469 } catch (IOException e ) {
440470 System .err .println ("Error walking path: " + root + " : " + e .getMessage ());
441471 }
442472 }
443- System .err .println ("Warning: Source file not found for class " + className + " under roots: " + potentialSourceRoots );
473+ System .err .println ("Warning: Source file not found for class " + className + " (searched as " + outerClassName + ") under roots: " + potentialSourceRoots );
444474 return null ;
445475 }
446476
0 commit comments