@@ -520,6 +520,88 @@ def get_file_summary(file_path: str, ctx: Context) -> Dict[str, Any]:
520
520
"function_count" : len (functions ),
521
521
})
522
522
523
+ elif ext == '.java' :
524
+ # Java analysis
525
+ package = ""
526
+ imports = []
527
+ classes = []
528
+ interfaces = []
529
+ methods = []
530
+ enums = []
531
+
532
+ for i , line in enumerate (lines ):
533
+ line = line .strip ()
534
+
535
+ # Check for package declaration
536
+ if line .startswith ('package ' ):
537
+ package = line .replace ('package ' , '' ).rstrip (';' )
538
+
539
+ # Check for imports
540
+ if line .startswith ('import ' ):
541
+ imports .append (line )
542
+
543
+ # Check for class definitions
544
+ if line .startswith ('public class ' ) or line .startswith ('private class ' ) or line .startswith ('protected class ' ) or line .startswith ('class ' ):
545
+ class_name = ""
546
+ if 'class ' in line :
547
+ parts = line .split ('class ' )[1 ]
548
+ class_name = parts .split (' ' )[0 ].split ('{' )[0 ].split ('<' )[0 ].strip ()
549
+ classes .append ({
550
+ "line" : i + 1 ,
551
+ "name" : class_name
552
+ })
553
+
554
+ # Check for interface definitions
555
+ if line .startswith ('public interface ' ) or line .startswith ('private interface ' ) or line .startswith ('protected interface ' ) or line .startswith ('interface ' ):
556
+ interface_name = ""
557
+ if 'interface ' in line :
558
+ parts = line .split ('interface ' )[1 ]
559
+ interface_name = parts .split (' ' )[0 ].split ('{' )[0 ].split ('<' )[0 ].strip ()
560
+ interfaces .append ({
561
+ "line" : i + 1 ,
562
+ "name" : interface_name
563
+ })
564
+
565
+ # Check for enum definitions
566
+ if line .startswith ('public enum ' ) or line .startswith ('private enum ' ) or line .startswith ('protected enum ' ) or line .startswith ('enum ' ):
567
+ enum_name = ""
568
+ if 'enum ' in line :
569
+ parts = line .split ('enum ' )[1 ]
570
+ enum_name = parts .split (' ' )[0 ].split ('{' )[0 ].strip ()
571
+ enums .append ({
572
+ "line" : i + 1 ,
573
+ "name" : enum_name
574
+ })
575
+
576
+ # Check for method definitions
577
+ if ('public ' in line or 'private ' in line or 'protected ' in line ) and '(' in line and ')' in line :
578
+ # Skip constructor calls and other non-method patterns
579
+ if not line .startswith ('//' ) and not line .startswith ('*' ) and not line .startswith ('/*' ):
580
+ # Extract method name
581
+ method_parts = line .split ('(' )[0 ].strip ().split ()
582
+ if len (method_parts ) >= 2 :
583
+ method_name = method_parts [- 1 ]
584
+ # Filter out common non-method patterns
585
+ if not method_name .startswith ('new ' ) and not method_name .endswith ('=' ):
586
+ methods .append ({
587
+ "line" : i + 1 ,
588
+ "name" : method_name
589
+ })
590
+
591
+ summary .update ({
592
+ "package" : package ,
593
+ "imports" : imports ,
594
+ "classes" : classes ,
595
+ "interfaces" : interfaces ,
596
+ "methods" : methods ,
597
+ "enums" : enums ,
598
+ "import_count" : len (imports ),
599
+ "class_count" : len (classes ),
600
+ "interface_count" : len (interfaces ),
601
+ "method_count" : len (methods ),
602
+ "enum_count" : len (enums ),
603
+ })
604
+
523
605
return summary
524
606
except Exception as e :
525
607
return {"error" : f"Error analyzing file: { e } " }
@@ -796,4 +878,4 @@ def main():
796
878
if __name__ == '__main__' :
797
879
# Set path to project root
798
880
sys .path .append (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
799
- main ()
881
+ main ()
0 commit comments