@@ -500,6 +500,88 @@ def get_file_summary(file_path: str, ctx: Context) -> Dict[str, Any]:
500
500
"function_count" : len (functions ),
501
501
})
502
502
503
+ elif ext == '.java' :
504
+ # Java analysis
505
+ package = ""
506
+ imports = []
507
+ classes = []
508
+ interfaces = []
509
+ methods = []
510
+ enums = []
511
+
512
+ for i , line in enumerate (lines ):
513
+ line = line .strip ()
514
+
515
+ # Check for package declaration
516
+ if line .startswith ('package ' ):
517
+ package = line .replace ('package ' , '' ).rstrip (';' )
518
+
519
+ # Check for imports
520
+ if line .startswith ('import ' ):
521
+ imports .append (line )
522
+
523
+ # Check for class definitions
524
+ if line .startswith ('public class ' ) or line .startswith ('private class ' ) or line .startswith ('protected class ' ) or line .startswith ('class ' ):
525
+ class_name = ""
526
+ if 'class ' in line :
527
+ parts = line .split ('class ' )[1 ]
528
+ class_name = parts .split (' ' )[0 ].split ('{' )[0 ].split ('<' )[0 ].strip ()
529
+ classes .append ({
530
+ "line" : i + 1 ,
531
+ "name" : class_name
532
+ })
533
+
534
+ # Check for interface definitions
535
+ if line .startswith ('public interface ' ) or line .startswith ('private interface ' ) or line .startswith ('protected interface ' ) or line .startswith ('interface ' ):
536
+ interface_name = ""
537
+ if 'interface ' in line :
538
+ parts = line .split ('interface ' )[1 ]
539
+ interface_name = parts .split (' ' )[0 ].split ('{' )[0 ].split ('<' )[0 ].strip ()
540
+ interfaces .append ({
541
+ "line" : i + 1 ,
542
+ "name" : interface_name
543
+ })
544
+
545
+ # Check for enum definitions
546
+ if line .startswith ('public enum ' ) or line .startswith ('private enum ' ) or line .startswith ('protected enum ' ) or line .startswith ('enum ' ):
547
+ enum_name = ""
548
+ if 'enum ' in line :
549
+ parts = line .split ('enum ' )[1 ]
550
+ enum_name = parts .split (' ' )[0 ].split ('{' )[0 ].strip ()
551
+ enums .append ({
552
+ "line" : i + 1 ,
553
+ "name" : enum_name
554
+ })
555
+
556
+ # Check for method definitions
557
+ if ('public ' in line or 'private ' in line or 'protected ' in line ) and '(' in line and ')' in line :
558
+ # Skip constructor calls and other non-method patterns
559
+ if not line .startswith ('//' ) and not line .startswith ('*' ) and not line .startswith ('/*' ):
560
+ # Extract method name
561
+ method_parts = line .split ('(' )[0 ].strip ().split ()
562
+ if len (method_parts ) >= 2 :
563
+ method_name = method_parts [- 1 ]
564
+ # Filter out common non-method patterns
565
+ if not method_name .startswith ('new ' ) and not method_name .endswith ('=' ):
566
+ methods .append ({
567
+ "line" : i + 1 ,
568
+ "name" : method_name
569
+ })
570
+
571
+ summary .update ({
572
+ "package" : package ,
573
+ "imports" : imports ,
574
+ "classes" : classes ,
575
+ "interfaces" : interfaces ,
576
+ "methods" : methods ,
577
+ "enums" : enums ,
578
+ "import_count" : len (imports ),
579
+ "class_count" : len (classes ),
580
+ "interface_count" : len (interfaces ),
581
+ "method_count" : len (methods ),
582
+ "enum_count" : len (enums ),
583
+ })
584
+
503
585
return summary
504
586
except Exception as e :
505
587
return {"error" : f"Error analyzing file: { e } " }
0 commit comments