Skip to content

Commit 7847d25

Browse files
author
Test User
committed
Merge Java file support from PR #9
Add comprehensive Java file analysis support to get_file_summary function: - Package declarations - Import statements - Class definitions - Interface declarations - Enum definitions - Method signatures Resolves merge conflicts while preserving all master branch features including regex search support and improved glob pattern handling.
2 parents 3970a07 + e8ae4e8 commit 7847d25

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

src/code_index_mcp/server.py

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,88 @@ def get_file_summary(file_path: str, ctx: Context) -> Dict[str, Any]:
520520
"function_count": len(functions),
521521
})
522522

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+
523605
return summary
524606
except Exception as e:
525607
return {"error": f"Error analyzing file: {e}"}
@@ -796,4 +878,4 @@ def main():
796878
if __name__ == '__main__':
797879
# Set path to project root
798880
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
799-
main()
881+
main()

0 commit comments

Comments
 (0)