tree-sitter-analyzer 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tree-sitter-analyzer might be problematic. Click here for more details.

Files changed (78) hide show
  1. tree_sitter_analyzer/__init__.py +134 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +533 -539
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -13
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -27
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -155
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -19
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -82
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
  14. tree_sitter_analyzer/cli/commands/table_command.py +235 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +278 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +555 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +559 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +502 -502
  23. tree_sitter_analyzer/encoding_utils.py +456 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +210 -222
  26. tree_sitter_analyzer/formatters/__init__.py +1 -1
  27. tree_sitter_analyzer/formatters/base_formatter.py +167 -168
  28. tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
  29. tree_sitter_analyzer/formatters/java_formatter.py +291 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +259 -235
  31. tree_sitter_analyzer/interfaces/__init__.py +9 -10
  32. tree_sitter_analyzer/interfaces/cli.py +528 -557
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +343 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +187 -219
  37. tree_sitter_analyzer/language_detector.py +398 -400
  38. tree_sitter_analyzer/language_loader.py +224 -228
  39. tree_sitter_analyzer/languages/__init__.py +10 -11
  40. tree_sitter_analyzer/languages/java_plugin.py +1174 -1113
  41. tree_sitter_analyzer/{plugins → languages}/javascript_plugin.py +446 -439
  42. tree_sitter_analyzer/languages/python_plugin.py +747 -712
  43. tree_sitter_analyzer/mcp/__init__.py +31 -32
  44. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  45. tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -213
  46. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +555 -550
  47. tree_sitter_analyzer/mcp/server.py +333 -345
  48. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +654 -557
  50. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -245
  51. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  52. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  53. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  54. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  55. tree_sitter_analyzer/mcp/utils/__init__.py +107 -106
  56. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  57. tree_sitter_analyzer/models.py +470 -481
  58. tree_sitter_analyzer/output_manager.py +255 -264
  59. tree_sitter_analyzer/plugins/__init__.py +280 -334
  60. tree_sitter_analyzer/plugins/base.py +496 -446
  61. tree_sitter_analyzer/plugins/manager.py +379 -355
  62. tree_sitter_analyzer/queries/__init__.py +26 -27
  63. tree_sitter_analyzer/queries/java.py +391 -394
  64. tree_sitter_analyzer/queries/javascript.py +148 -149
  65. tree_sitter_analyzer/queries/python.py +285 -286
  66. tree_sitter_analyzer/queries/typescript.py +229 -230
  67. tree_sitter_analyzer/query_loader.py +257 -260
  68. tree_sitter_analyzer/table_formatter.py +471 -448
  69. tree_sitter_analyzer/utils.py +277 -277
  70. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/METADATA +23 -8
  71. tree_sitter_analyzer-0.4.0.dist-info/RECORD +73 -0
  72. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/entry_points.txt +2 -1
  73. tree_sitter_analyzer/plugins/java_plugin.py +0 -625
  74. tree_sitter_analyzer/plugins/plugin_loader.py +0 -83
  75. tree_sitter_analyzer/plugins/python_plugin.py +0 -598
  76. tree_sitter_analyzer/plugins/registry.py +0 -366
  77. tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
  78. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.4.0.dist-info}/WHEEL +0 -0
@@ -1,270 +1,291 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Java-specific table formatter.
5
- """
6
-
7
- from typing import Any, Dict, List
8
- from .base_formatter import BaseTableFormatter
9
-
10
-
11
- class JavaTableFormatter(BaseTableFormatter):
12
- """Java言語専用のテーブルフォーマッター"""
13
-
14
- def _format_full_table(self, data: Dict[str, Any]) -> str:
15
- """Java用完全版テーブル形式"""
16
- lines = []
17
-
18
- # ヘッダー - Java用(複数クラス対応)
19
- classes = data.get("classes", [])
20
- package_name = (data.get("package") or {}).get("name", "unknown")
21
-
22
- if len(classes) > 1:
23
- # 複数クラスがある場合はファイル名を使用
24
- file_name = data.get("file_path", "Unknown").split("/")[-1].split("\\")[-1]
25
- lines.append(f"# {package_name}.{file_name}")
26
- else:
27
- # 単一クラスの場合は従来通り
28
- class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
29
- lines.append(f"# {package_name}.{class_name}")
30
- lines.append("")
31
-
32
- # Imports
33
- imports = data.get("imports", [])
34
- if imports:
35
- lines.append("## Imports")
36
- lines.append("```java")
37
- for imp in imports:
38
- lines.append(str(imp.get("statement", "")))
39
- lines.append("```")
40
- lines.append("")
41
-
42
- # Class Info - Java用(複数クラス対応)
43
- if len(classes) > 1:
44
- lines.append("## Classes")
45
- lines.append("| Class | Type | Visibility | Lines | Methods | Fields |")
46
- lines.append("|-------|------|------------|-------|---------|--------|")
47
-
48
- for class_info in classes:
49
- name = str(class_info.get("name", "Unknown"))
50
- class_type = str(class_info.get("type", "class"))
51
- visibility = str(class_info.get("visibility", "public"))
52
- line_range = class_info.get("line_range", {})
53
- lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
54
-
55
- # このクラスのメソッド数とフィールド数を計算
56
- class_methods = [m for m in data.get("methods", [])
57
- if line_range.get('start', 0) <= m.get('line_range', {}).get('start', 0) <= line_range.get('end', 0)]
58
- class_fields = [f for f in data.get("fields", [])
59
- if line_range.get('start', 0) <= f.get('line_range', {}).get('start', 0) <= line_range.get('end', 0)]
60
-
61
- lines.append(f"| {name} | {class_type} | {visibility} | {lines_str} | {len(class_methods)} | {len(class_fields)} |")
62
- else:
63
- # 単一クラスの場合は従来通り
64
- lines.append("## Class Info")
65
- lines.append("| Property | Value |")
66
- lines.append("|----------|-------|")
67
-
68
- class_info = data.get("classes", [{}])[0] if data.get("classes") else {}
69
- stats = data.get("statistics") or {}
70
-
71
- lines.append(f"| Package | {package_name} |")
72
- lines.append(f"| Type | {str(class_info.get('type', 'class'))} |")
73
- lines.append(f"| Visibility | {str(class_info.get('visibility', 'public'))} |")
74
- lines.append(
75
- f"| Lines | {class_info.get('line_range', {}).get('start', 0)}-{class_info.get('line_range', {}).get('end', 0)} |"
76
- )
77
- lines.append(f"| Total Methods | {stats.get('method_count', 0)} |")
78
- lines.append(f"| Total Fields | {stats.get('field_count', 0)} |")
79
-
80
- lines.append("")
81
-
82
- # Fields
83
- fields = data.get("fields", [])
84
- if fields:
85
- lines.append("## Fields")
86
- lines.append("| Name | Type | Vis | Modifiers | Line | Doc |")
87
- lines.append("|------|------|-----|-----------|------|-----|")
88
-
89
- for field in fields:
90
- name = str(field.get("name", ""))
91
- field_type = str(field.get("type", ""))
92
- visibility = self._convert_visibility(str(field.get("visibility", "")))
93
- modifiers = ",".join([str(m) for m in field.get("modifiers", [])])
94
- line = field.get("line_range", {}).get("start", 0)
95
- doc = str(field.get("javadoc", "")) or "-"
96
- doc = doc.replace("\n", " ").replace("|", "\\|")[:50]
97
-
98
- lines.append(
99
- f"| {name} | {field_type} | {visibility} | {modifiers} | {line} | {doc} |"
100
- )
101
- lines.append("")
102
-
103
- # Constructor
104
- constructors = [
105
- m for m in (data.get("methods") or []) if m.get("is_constructor", False)
106
- ]
107
- if constructors:
108
- lines.append("## Constructor")
109
- lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
110
- lines.append("|--------|-----------|-----|-------|------|----|----|")
111
-
112
- for method in constructors:
113
- lines.append(self._format_method_row(method))
114
- lines.append("")
115
-
116
- # Public Methods
117
- public_methods = [
118
- m
119
- for m in (data.get("methods") or [])
120
- if not m.get("is_constructor", False)
121
- and str(m.get("visibility")) == "public"
122
- ]
123
- if public_methods:
124
- lines.append("## Public Methods")
125
- lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
126
- lines.append("|--------|-----------|-----|-------|------|----|----|")
127
-
128
- for method in public_methods:
129
- lines.append(self._format_method_row(method))
130
- lines.append("")
131
-
132
- # Private Methods
133
- private_methods = [
134
- m
135
- for m in (data.get("methods") or [])
136
- if not m.get("is_constructor", False)
137
- and str(m.get("visibility")) == "private"
138
- ]
139
- if private_methods:
140
- lines.append("## Private Methods")
141
- lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
142
- lines.append("|--------|-----------|-----|-------|------|----|----|")
143
-
144
- for method in private_methods:
145
- lines.append(self._format_method_row(method))
146
- lines.append("")
147
-
148
- # 末尾の空行を削除
149
- while lines and lines[-1] == "":
150
- lines.pop()
151
-
152
- return "\n".join(lines)
153
-
154
- def _format_compact_table(self, data: Dict[str, Any]) -> str:
155
- """Java用コンパクト版テーブル形式"""
156
- lines = []
157
-
158
- # ヘッダー
159
- package_name = (data.get("package") or {}).get("name", "unknown")
160
- classes = data.get("classes", [])
161
- class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
162
- lines.append(f"# {package_name}.{class_name}")
163
- lines.append("")
164
-
165
- # 基本情報
166
- stats = data.get("statistics") or {}
167
- lines.append("## Info")
168
- lines.append("| Property | Value |")
169
- lines.append("|----------|-------|")
170
- lines.append(f"| Package | {package_name} |")
171
- lines.append(f"| Methods | {stats.get('method_count', 0)} |")
172
- lines.append(f"| Fields | {stats.get('field_count', 0)} |")
173
- lines.append("")
174
-
175
- # メソッド(簡略版)
176
- methods = data.get("methods", [])
177
- if methods:
178
- lines.append("## Methods")
179
- lines.append("| Method | Sig | V | L | Cx | Doc |")
180
- lines.append("|--------|-----|---|---|----|----|")
181
-
182
- for method in methods:
183
- name = str(method.get("name", ""))
184
- signature = self._create_compact_signature(method)
185
- visibility = self._convert_visibility(str(method.get("visibility", "")))
186
- line_range = method.get("line_range", {})
187
- lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
188
- complexity = method.get("complexity_score", 0)
189
- doc = self._clean_csv_text(
190
- self._extract_doc_summary(str(method.get("javadoc", "")))
191
- )
192
-
193
- lines.append(
194
- f"| {name} | {signature} | {visibility} | {lines_str} | {complexity} | {doc} |"
195
- )
196
- lines.append("")
197
-
198
- # 末尾の空行を削除
199
- while lines and lines[-1] == "":
200
- lines.pop()
201
-
202
- return "\n".join(lines)
203
-
204
- def _format_method_row(self, method: Dict[str, Any]) -> str:
205
- """Java用メソッド行のフォーマット"""
206
- name = str(method.get("name", ""))
207
- signature = self._create_full_signature(method)
208
- visibility = self._convert_visibility(str(method.get("visibility", "")))
209
- line_range = method.get("line_range", {})
210
- lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
211
- cols_str = "5-6" # デフォルト値
212
- complexity = method.get("complexity_score", 0)
213
- doc = self._clean_csv_text(
214
- self._extract_doc_summary(str(method.get("javadoc", "")))
215
- )
216
-
217
- return f"| {name} | {signature} | {visibility} | {lines_str} | {cols_str} | {complexity} | {doc} |"
218
-
219
- def _create_compact_signature(self, method: Dict[str, Any]) -> str:
220
- """Java用コンパクトなメソッドシグネチャを作成"""
221
- params = method.get("parameters", [])
222
- param_types = [self._shorten_type(p.get("type", "O") if isinstance(p, dict) else str(p)) for p in params]
223
- params_str = ",".join(param_types)
224
- return_type = self._shorten_type(method.get("return_type", "void"))
225
-
226
- return f"({params_str}):{return_type}"
227
-
228
- def _shorten_type(self, type_name: Any) -> str:
229
- """Java用型名を短縮"""
230
- if type_name is None:
231
- return "O"
232
-
233
- if not isinstance(type_name, str):
234
- type_name = str(type_name)
235
-
236
- type_mapping = {
237
- "String": "S",
238
- "int": "i",
239
- "long": "l",
240
- "double": "d",
241
- "boolean": "b",
242
- "void": "void",
243
- "Object": "O",
244
- "Exception": "E",
245
- "SQLException": "SE",
246
- "IllegalArgumentException": "IAE",
247
- "RuntimeException": "RE",
248
- }
249
-
250
- # Map<String,Object> -> M<S,O>
251
- if "Map<" in type_name:
252
- return (
253
- type_name.replace("Map<", "M<")
254
- .replace("String", "S")
255
- .replace("Object", "O")
256
- )
257
-
258
- # List<String> -> L<S>
259
- if "List<" in type_name:
260
- return type_name.replace("List<", "L<").replace("String", "S")
261
-
262
- # String[] -> S[]
263
- if "[]" in type_name:
264
- base_type = type_name.replace("[]", "")
265
- if base_type:
266
- return type_mapping.get(base_type, base_type[0].upper()) + "[]"
267
- else:
268
- return "O[]"
269
-
270
- return type_mapping.get(type_name, type_name)
1
+ #!/usr/bin/env python3
2
+ """
3
+ Java-specific table formatter.
4
+ """
5
+
6
+ from typing import Any
7
+
8
+ from .base_formatter import BaseTableFormatter
9
+
10
+
11
+ class JavaTableFormatter(BaseTableFormatter):
12
+ """Java言語専用のテーブルフォーマッター"""
13
+
14
+ def _format_full_table(self, data: dict[str, Any]) -> str:
15
+ """Java用完全版テーブル形式"""
16
+ lines = []
17
+
18
+ # ヘッダー - Java用(複数クラス対応)
19
+ classes = data.get("classes", [])
20
+ package_name = (data.get("package") or {}).get("name", "unknown")
21
+
22
+ if len(classes) > 1:
23
+ # 複数クラスがある場合はファイル名を使用
24
+ file_name = data.get("file_path", "Unknown").split("/")[-1].split("\\")[-1]
25
+ lines.append(f"# {package_name}.{file_name}")
26
+ else:
27
+ # 単一クラスの場合は従来通り
28
+ class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
29
+ lines.append(f"# {package_name}.{class_name}")
30
+ lines.append("")
31
+
32
+ # Imports
33
+ imports = data.get("imports", [])
34
+ if imports:
35
+ lines.append("## Imports")
36
+ lines.append("```java")
37
+ for imp in imports:
38
+ lines.append(str(imp.get("statement", "")))
39
+ lines.append("```")
40
+ lines.append("")
41
+
42
+ # Class Info - Java用(複数クラス対応)
43
+ if len(classes) > 1:
44
+ lines.append("## Classes")
45
+ lines.append("| Class | Type | Visibility | Lines | Methods | Fields |")
46
+ lines.append("|-------|------|------------|-------|---------|--------|")
47
+
48
+ for class_info in classes:
49
+ name = str(class_info.get("name", "Unknown"))
50
+ class_type = str(class_info.get("type", "class"))
51
+ visibility = str(class_info.get("visibility", "public"))
52
+ line_range = class_info.get("line_range", {})
53
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
54
+
55
+ # このクラスのメソッド数とフィールド数を計算
56
+ class_methods = [
57
+ m
58
+ for m in data.get("methods", [])
59
+ if line_range.get("start", 0)
60
+ <= m.get("line_range", {}).get("start", 0)
61
+ <= line_range.get("end", 0)
62
+ ]
63
+ class_fields = [
64
+ f
65
+ for f in data.get("fields", [])
66
+ if line_range.get("start", 0)
67
+ <= f.get("line_range", {}).get("start", 0)
68
+ <= line_range.get("end", 0)
69
+ ]
70
+
71
+ lines.append(
72
+ f"| {name} | {class_type} | {visibility} | {lines_str} | {len(class_methods)} | {len(class_fields)} |"
73
+ )
74
+ else:
75
+ # 単一クラスの場合は従来通り
76
+ lines.append("## Class Info")
77
+ lines.append("| Property | Value |")
78
+ lines.append("|----------|-------|")
79
+
80
+ class_info = data.get("classes", [{}])[0] if data.get("classes") else {}
81
+ stats = data.get("statistics") or {}
82
+
83
+ lines.append(f"| Package | {package_name} |")
84
+ lines.append(f"| Type | {str(class_info.get('type', 'class'))} |")
85
+ lines.append(
86
+ f"| Visibility | {str(class_info.get('visibility', 'public'))} |"
87
+ )
88
+ lines.append(
89
+ f"| Lines | {class_info.get('line_range', {}).get('start', 0)}-{class_info.get('line_range', {}).get('end', 0)} |"
90
+ )
91
+ lines.append(f"| Total Methods | {stats.get('method_count', 0)} |")
92
+ lines.append(f"| Total Fields | {stats.get('field_count', 0)} |")
93
+
94
+ lines.append("")
95
+
96
+ # Fields
97
+ fields = data.get("fields", [])
98
+ if fields:
99
+ lines.append("## Fields")
100
+ lines.append("| Name | Type | Vis | Modifiers | Line | Doc |")
101
+ lines.append("|------|------|-----|-----------|------|-----|")
102
+
103
+ for field in fields:
104
+ name = str(field.get("name", ""))
105
+ field_type = str(field.get("type", ""))
106
+ visibility = self._convert_visibility(str(field.get("visibility", "")))
107
+ modifiers = ",".join([str(m) for m in field.get("modifiers", [])])
108
+ line = field.get("line_range", {}).get("start", 0)
109
+ doc = str(field.get("javadoc", "")) or "-"
110
+ doc = doc.replace("\n", " ").replace("|", "\\|")[:50]
111
+
112
+ lines.append(
113
+ f"| {name} | {field_type} | {visibility} | {modifiers} | {line} | {doc} |"
114
+ )
115
+ lines.append("")
116
+
117
+ # Constructor
118
+ constructors = [
119
+ m for m in (data.get("methods") or []) if m.get("is_constructor", False)
120
+ ]
121
+ if constructors:
122
+ lines.append("## Constructor")
123
+ lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
124
+ lines.append("|--------|-----------|-----|-------|------|----|----|")
125
+
126
+ for method in constructors:
127
+ lines.append(self._format_method_row(method))
128
+ lines.append("")
129
+
130
+ # Public Methods
131
+ public_methods = [
132
+ m
133
+ for m in (data.get("methods") or [])
134
+ if not m.get("is_constructor", False)
135
+ and str(m.get("visibility")) == "public"
136
+ ]
137
+ if public_methods:
138
+ lines.append("## Public Methods")
139
+ lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
140
+ lines.append("|--------|-----------|-----|-------|------|----|----|")
141
+
142
+ for method in public_methods:
143
+ lines.append(self._format_method_row(method))
144
+ lines.append("")
145
+
146
+ # Private Methods
147
+ private_methods = [
148
+ m
149
+ for m in (data.get("methods") or [])
150
+ if not m.get("is_constructor", False)
151
+ and str(m.get("visibility")) == "private"
152
+ ]
153
+ if private_methods:
154
+ lines.append("## Private Methods")
155
+ lines.append("| Method | Signature | Vis | Lines | Cols | Cx | Doc |")
156
+ lines.append("|--------|-----------|-----|-------|------|----|----|")
157
+
158
+ for method in private_methods:
159
+ lines.append(self._format_method_row(method))
160
+ lines.append("")
161
+
162
+ # 末尾の空行を削除
163
+ while lines and lines[-1] == "":
164
+ lines.pop()
165
+
166
+ return "\n".join(lines)
167
+
168
+ def _format_compact_table(self, data: dict[str, Any]) -> str:
169
+ """Java用コンパクト版テーブル形式"""
170
+ lines = []
171
+
172
+ # ヘッダー
173
+ package_name = (data.get("package") or {}).get("name", "unknown")
174
+ classes = data.get("classes", [])
175
+ class_name = classes[0].get("name", "Unknown") if classes else "Unknown"
176
+ lines.append(f"# {package_name}.{class_name}")
177
+ lines.append("")
178
+
179
+ # 基本情報
180
+ stats = data.get("statistics") or {}
181
+ lines.append("## Info")
182
+ lines.append("| Property | Value |")
183
+ lines.append("|----------|-------|")
184
+ lines.append(f"| Package | {package_name} |")
185
+ lines.append(f"| Methods | {stats.get('method_count', 0)} |")
186
+ lines.append(f"| Fields | {stats.get('field_count', 0)} |")
187
+ lines.append("")
188
+
189
+ # メソッド(簡略版)
190
+ methods = data.get("methods", [])
191
+ if methods:
192
+ lines.append("## Methods")
193
+ lines.append("| Method | Sig | V | L | Cx | Doc |")
194
+ lines.append("|--------|-----|---|---|----|----|")
195
+
196
+ for method in methods:
197
+ name = str(method.get("name", ""))
198
+ signature = self._create_compact_signature(method)
199
+ visibility = self._convert_visibility(str(method.get("visibility", "")))
200
+ line_range = method.get("line_range", {})
201
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
202
+ complexity = method.get("complexity_score", 0)
203
+ doc = self._clean_csv_text(
204
+ self._extract_doc_summary(str(method.get("javadoc", "")))
205
+ )
206
+
207
+ lines.append(
208
+ f"| {name} | {signature} | {visibility} | {lines_str} | {complexity} | {doc} |"
209
+ )
210
+ lines.append("")
211
+
212
+ # 末尾の空行を削除
213
+ while lines and lines[-1] == "":
214
+ lines.pop()
215
+
216
+ return "\n".join(lines)
217
+
218
+ def _format_method_row(self, method: dict[str, Any]) -> str:
219
+ """Java用メソッド行のフォーマット"""
220
+ name = str(method.get("name", ""))
221
+ signature = self._create_full_signature(method)
222
+ visibility = self._convert_visibility(str(method.get("visibility", "")))
223
+ line_range = method.get("line_range", {})
224
+ lines_str = f"{line_range.get('start', 0)}-{line_range.get('end', 0)}"
225
+ cols_str = "5-6" # デフォルト値
226
+ complexity = method.get("complexity_score", 0)
227
+ doc = self._clean_csv_text(
228
+ self._extract_doc_summary(str(method.get("javadoc", "")))
229
+ )
230
+
231
+ return f"| {name} | {signature} | {visibility} | {lines_str} | {cols_str} | {complexity} | {doc} |"
232
+
233
+ def _create_compact_signature(self, method: dict[str, Any]) -> str:
234
+ """Java用コンパクトなメソッドシグネチャを作成"""
235
+ params = method.get("parameters", [])
236
+ param_types = [
237
+ self._shorten_type(p.get("type", "O") if isinstance(p, dict) else str(p))
238
+ for p in params
239
+ ]
240
+ params_str = ",".join(param_types)
241
+ return_type = self._shorten_type(method.get("return_type", "void"))
242
+
243
+ return f"({params_str}):{return_type}"
244
+
245
+ def _shorten_type(self, type_name: Any) -> str:
246
+ """Java用型名を短縮"""
247
+ if type_name is None:
248
+ return "O"
249
+
250
+ if not isinstance(type_name, str):
251
+ type_name = str(type_name)
252
+
253
+ type_mapping = {
254
+ "String": "S",
255
+ "int": "i",
256
+ "long": "l",
257
+ "double": "d",
258
+ "boolean": "b",
259
+ "void": "void",
260
+ "Object": "O",
261
+ "Exception": "E",
262
+ "SQLException": "SE",
263
+ "IllegalArgumentException": "IAE",
264
+ "RuntimeException": "RE",
265
+ }
266
+
267
+ # Map<String,Object> -> M<S,O>
268
+ if "Map<" in type_name:
269
+ result = (
270
+ type_name.replace("Map<", "M<")
271
+ .replace("String", "S")
272
+ .replace("Object", "O")
273
+ )
274
+ return str(result)
275
+
276
+ # List<String> -> L<S>
277
+ if "List<" in type_name:
278
+ result = type_name.replace("List<", "L<").replace("String", "S")
279
+ return str(result)
280
+
281
+ # String[] -> S[]
282
+ if "[]" in type_name:
283
+ base_type = type_name.replace("[]", "")
284
+ if base_type:
285
+ result = type_mapping.get(base_type, base_type[0].upper()) + "[]"
286
+ return str(result)
287
+ else:
288
+ return "O[]"
289
+
290
+ result = type_mapping.get(type_name, type_name)
291
+ return str(result)