tree-sitter-analyzer 0.9.1__py3-none-any.whl → 0.9.2__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 (61) hide show
  1. tree_sitter_analyzer/__init__.py +132 -132
  2. tree_sitter_analyzer/__main__.py +11 -11
  3. tree_sitter_analyzer/api.py +533 -533
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -12
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -26
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +182 -178
  9. tree_sitter_analyzer/cli/commands/structure_command.py +138 -138
  10. tree_sitter_analyzer/cli/commands/summary_command.py +101 -101
  11. tree_sitter_analyzer/core/__init__.py +15 -15
  12. tree_sitter_analyzer/core/analysis_engine.py +74 -78
  13. tree_sitter_analyzer/core/cache_service.py +320 -320
  14. tree_sitter_analyzer/core/engine.py +566 -566
  15. tree_sitter_analyzer/core/parser.py +293 -293
  16. tree_sitter_analyzer/encoding_utils.py +459 -459
  17. tree_sitter_analyzer/file_handler.py +210 -210
  18. tree_sitter_analyzer/formatters/__init__.py +1 -1
  19. tree_sitter_analyzer/formatters/base_formatter.py +167 -167
  20. tree_sitter_analyzer/formatters/formatter_factory.py +78 -78
  21. tree_sitter_analyzer/formatters/java_formatter.py +18 -18
  22. tree_sitter_analyzer/formatters/python_formatter.py +19 -19
  23. tree_sitter_analyzer/interfaces/__init__.py +9 -9
  24. tree_sitter_analyzer/interfaces/cli.py +528 -528
  25. tree_sitter_analyzer/interfaces/cli_adapter.py +344 -343
  26. tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -206
  27. tree_sitter_analyzer/language_detector.py +53 -53
  28. tree_sitter_analyzer/languages/__init__.py +10 -10
  29. tree_sitter_analyzer/languages/java_plugin.py +1 -1
  30. tree_sitter_analyzer/languages/javascript_plugin.py +446 -446
  31. tree_sitter_analyzer/languages/python_plugin.py +755 -755
  32. tree_sitter_analyzer/mcp/__init__.py +34 -45
  33. tree_sitter_analyzer/mcp/resources/__init__.py +44 -44
  34. tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -209
  35. tree_sitter_analyzer/mcp/server.py +623 -568
  36. tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
  37. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +681 -673
  38. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -247
  39. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -54
  40. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +310 -308
  41. tree_sitter_analyzer/mcp/tools/table_format_tool.py +386 -379
  42. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +563 -559
  43. tree_sitter_analyzer/mcp/utils/__init__.py +107 -107
  44. tree_sitter_analyzer/models.py +10 -10
  45. tree_sitter_analyzer/output_manager.py +253 -253
  46. tree_sitter_analyzer/plugins/__init__.py +280 -280
  47. tree_sitter_analyzer/plugins/base.py +529 -529
  48. tree_sitter_analyzer/plugins/manager.py +379 -379
  49. tree_sitter_analyzer/queries/__init__.py +26 -26
  50. tree_sitter_analyzer/queries/java.py +391 -391
  51. tree_sitter_analyzer/queries/javascript.py +148 -148
  52. tree_sitter_analyzer/queries/python.py +285 -285
  53. tree_sitter_analyzer/queries/typescript.py +229 -229
  54. tree_sitter_analyzer/query_loader.py +257 -257
  55. tree_sitter_analyzer/security/validator.py +246 -241
  56. tree_sitter_analyzer/utils.py +294 -277
  57. {tree_sitter_analyzer-0.9.1.dist-info → tree_sitter_analyzer-0.9.2.dist-info}/METADATA +1 -1
  58. tree_sitter_analyzer-0.9.2.dist-info/RECORD +77 -0
  59. {tree_sitter_analyzer-0.9.1.dist-info → tree_sitter_analyzer-0.9.2.dist-info}/entry_points.txt +1 -0
  60. tree_sitter_analyzer-0.9.1.dist-info/RECORD +0 -77
  61. {tree_sitter_analyzer-0.9.1.dist-info → tree_sitter_analyzer-0.9.2.dist-info}/WHEEL +0 -0
@@ -1,343 +1,344 @@
1
- #!/usr/bin/env python3
2
- """
3
- CLI Adapter for tree-sitter-analyzer
4
-
5
- Adapter that uses the new unified analysis engine while maintaining compatibility with existing CLI API.
6
-
7
- Roo Code compliance:
8
- - Type hints: Required for all functions
9
- - MCP logging: Log output at each step
10
- - docstring: Google Style docstring
11
- - Error handling: Proper exception handling
12
- - Performance: Optimization through unified engine
13
- """
14
-
15
- import asyncio
16
- import logging
17
- import time
18
- from pathlib import Path
19
- from typing import Any
20
-
21
- from ..core.analysis_engine import AnalysisRequest, UnifiedAnalysisEngine
22
- from ..models import AnalysisResult
23
-
24
- logger = logging.getLogger(__name__)
25
-
26
-
27
- class CLIAdapter:
28
- """
29
- CLI Adapter
30
-
31
- Uses the new unified analysis engine while maintaining compatibility with existing CLI API.
32
- Provides synchronous API and internally calls asynchronous engine.
33
-
34
- Features:
35
- - Maintaining existing API compatibility
36
- - Utilizing unified analysis engine
37
- - Sync/async conversion
38
- - Performance monitoring
39
- - Error handling
40
-
41
- Example:
42
- >>> adapter = CLIAdapter()
43
- >>> result = adapter.analyze_file("example.java")
44
- >>> print(result.classes)
45
- """
46
-
47
- def __init__(self) -> None:
48
- """
49
- Initialize CLI adapter
50
-
51
- Raises:
52
- Exception: If unified analysis engine initialization fails
53
- """
54
- try:
55
- self._engine = UnifiedAnalysisEngine()
56
- logger.info("CLIAdapter initialized successfully")
57
- except Exception as e:
58
- logger.error(f"Failed to initialize CLIAdapter: {e}")
59
- raise
60
-
61
- def analyze_file(self, file_path: str, **kwargs: Any) -> AnalysisResult:
62
- """
63
- Analyze file (synchronous version)
64
-
65
- Provides synchronous interface to maintain compatibility with existing CLI API.
66
- Internally calls asynchronous methods of unified analysis engine.
67
-
68
- Args:
69
- file_path: Path to file to analyze
70
- **kwargs: Analysis options
71
- - language: Language specification (auto-detection possible)
72
- - include_complexity: Include complexity calculation
73
- - include_details: Include detailed information
74
- - format_type: Output format ("standard", "structure", "summary")
75
-
76
- Returns:
77
- AnalysisResult: Analysis result
78
-
79
- Raises:
80
- ValueError: For invalid file path
81
- FileNotFoundError: If file does not exist
82
- UnsupportedLanguageError: For unsupported language
83
-
84
- Example:
85
- >>> adapter = CLIAdapter()
86
- >>> result = adapter.analyze_file("example.java", include_complexity=True)
87
- >>> print(f"Classes: {len(result.classes)}")
88
- """
89
- start_time = time.time()
90
-
91
- # Input validation
92
- if not file_path or not file_path.strip():
93
- raise ValueError("File path cannot be empty")
94
-
95
- # File existence check
96
- if not Path(file_path).exists():
97
- raise FileNotFoundError(f"File not found: {file_path}")
98
-
99
- try:
100
- # Create AnalysisRequest
101
- request = AnalysisRequest(
102
- file_path=file_path,
103
- language=kwargs.get("language"),
104
- include_complexity=kwargs.get("include_complexity", False),
105
- include_details=kwargs.get("include_details", True),
106
- format_type=kwargs.get("format_type", "standard"),
107
- )
108
-
109
- # 非同期エンジンを同期的に実行
110
- result = asyncio.run(self._engine.analyze(request))
111
-
112
- # パフォーマンスログ
113
- elapsed_time = time.time() - start_time
114
- logger.info(f"CLI analysis completed: {file_path} in {elapsed_time:.3f}s")
115
-
116
- return result
117
-
118
- except Exception as e:
119
- logger.error(f"CLI analysis failed for {file_path}: {e}")
120
- raise
121
-
122
- def analyze_structure(self, file_path: str, **kwargs: Any) -> dict[str, Any]:
123
- """
124
- 構造解析(既存API互換)
125
-
126
- 既存のCLI APIとの互換性を保つため、構造情報を辞書形式で返します。
127
-
128
- Args:
129
- file_path: 解析対象ファイルのパス
130
- **kwargs: 解析オプション
131
-
132
- Returns:
133
- Dict[str, Any]: 構造情報の辞書
134
- - file_path: ファイルパス
135
- - classes: クラス情報のリスト
136
- - methods: メソッド情報のリスト
137
- - fields: フィールド情報のリスト
138
- - imports: インポート情報のリスト
139
-
140
- Example:
141
- >>> adapter = CLIAdapter()
142
- >>> structure = adapter.analyze_structure("example.java")
143
- >>> print(structure["classes"])
144
- """
145
- # 詳細情報を含めて解析
146
- kwargs["include_details"] = True
147
- kwargs["format_type"] = "structure"
148
-
149
- result = self.analyze_file(file_path, **kwargs)
150
-
151
- # 構造情報を辞書形式に変換
152
- return {
153
- "file_path": result.file_path,
154
- "language": result.language,
155
- "package": result.package,
156
- "imports": [
157
- {"name": imp.name, "type": str(type(imp).__name__)}
158
- for imp in result.imports
159
- ],
160
- "classes": [
161
- {"name": cls.name, "type": str(type(cls).__name__)}
162
- for cls in result.classes
163
- ],
164
- "methods": [
165
- {"name": method.name, "type": str(type(method).__name__)}
166
- for method in result.methods
167
- ],
168
- "fields": [
169
- {"name": field.name, "type": str(type(field).__name__)}
170
- for field in result.fields
171
- ],
172
- "annotations": [
173
- {
174
- "name": getattr(ann, "name", str(ann)),
175
- "type": str(type(ann).__name__),
176
- }
177
- for ann in getattr(result, "annotations", [])
178
- ],
179
- "analysis_time": result.analysis_time,
180
- "elements": [
181
- {"name": elem.name, "type": str(type(elem).__name__)}
182
- for elem in result.elements
183
- ],
184
- "success": result.success,
185
- }
186
-
187
- def analyze_batch(
188
- self, file_paths: list[str], **kwargs: Any
189
- ) -> list[AnalysisResult]:
190
- """
191
- 複数ファイルの一括解析
192
-
193
- Args:
194
- file_paths: 解析対象ファイルパスのリスト
195
- **kwargs: 解析オプション
196
-
197
- Returns:
198
- list[AnalysisResult]: 解析結果のリスト
199
-
200
- Example:
201
- >>> adapter = CLIAdapter()
202
- >>> results = adapter.analyze_batch(["file1.java", "file2.java"])
203
- >>> print(f"Analyzed {len(results)} files")
204
- """
205
- results = []
206
-
207
- for file_path in file_paths:
208
- try:
209
- result = self.analyze_file(file_path, **kwargs)
210
- results.append(result)
211
- except Exception as e:
212
- logger.warning(f"Failed to analyze {file_path}: {e}")
213
- # エラーの場合も結果に含める(失敗情報付き)
214
- error_result = AnalysisResult(
215
- file_path=file_path,
216
- package=None,
217
- imports=[],
218
- classes=[],
219
- methods=[],
220
- fields=[],
221
- annotations=[],
222
- analysis_time=0.0,
223
- success=False,
224
- error_message=str(e),
225
- )
226
- results.append(error_result)
227
-
228
- return results
229
-
230
- def get_supported_languages(self) -> list[str]:
231
- """
232
- サポートされている言語のリストを取得
233
-
234
- Returns:
235
- list[str]: サポート言語のリスト
236
-
237
- Example:
238
- >>> adapter = CLIAdapter()
239
- >>> languages = adapter.get_supported_languages()
240
- >>> print(languages)
241
- """
242
- return self._engine.get_supported_languages()
243
-
244
- def clear_cache(self) -> None:
245
- """
246
- キャッシュをクリア
247
-
248
- Example:
249
- >>> adapter = CLIAdapter()
250
- >>> adapter.clear_cache()
251
- """
252
- self._engine.clear_cache()
253
- logger.info("CLI adapter cache cleared")
254
-
255
- def get_cache_stats(self) -> dict[str, Any]:
256
- """
257
- キャッシュ統計情報を取得
258
-
259
- Returns:
260
- Dict[str, Any]: キャッシュ統計情報
261
-
262
- Example:
263
- >>> adapter = CLIAdapter()
264
- >>> stats = adapter.get_cache_stats()
265
- >>> print(f"Cache hit rate: {stats['hit_rate']:.2%}")
266
- """
267
- return self._engine.get_cache_stats()
268
-
269
- def validate_file(self, file_path: str) -> bool:
270
- """
271
- ファイルが解析可能かどうかを検証
272
-
273
- Args:
274
- file_path: 検証対象ファイルのパス
275
-
276
- Returns:
277
- bool: 解析可能な場合True
278
-
279
- Example:
280
- >>> adapter = CLIAdapter()
281
- >>> if adapter.validate_file("example.java"):
282
- ... result = adapter.analyze_file("example.java")
283
- """
284
- try:
285
- # ファイル存在チェック
286
- if not Path(file_path).exists():
287
- return False
288
-
289
- # 言語サポートチェック
290
- supported_languages = self.get_supported_languages()
291
- file_extension = Path(file_path).suffix.lower()
292
-
293
- # 拡張子から言語を推定
294
- extension_map = {
295
- ".java": "java",
296
- ".py": "python",
297
- ".js": "javascript",
298
- ".ts": "typescript",
299
- ".cpp": "cpp",
300
- ".c": "c",
301
- ".cs": "csharp",
302
- ".go": "go",
303
- ".rs": "rust",
304
- ".php": "php",
305
- ".rb": "ruby",
306
- }
307
-
308
- language = extension_map.get(file_extension)
309
- return language in supported_languages if language else False
310
-
311
- except Exception as e:
312
- logger.warning(f"File validation failed for {file_path}: {e}")
313
- return False
314
-
315
- def get_engine_info(self) -> dict[str, Any]:
316
- """
317
- エンジン情報を取得
318
-
319
- Returns:
320
- Dict[str, Any]: エンジン情報
321
-
322
- Example:
323
- >>> adapter = CLIAdapter()
324
- >>> info = adapter.get_engine_info()
325
- >>> print(f"Engine version: {info['version']}")
326
- """
327
- return {
328
- "adapter_type": "CLI",
329
- "engine_type": "UnifiedAnalysisEngine",
330
- "supported_languages": self.get_supported_languages(),
331
- "cache_enabled": True,
332
- "async_support": True,
333
- }
334
-
335
-
336
- # Legacy AdvancedAnalyzerAdapter removed - use UnifiedAnalysisEngine directly
337
-
338
-
339
- def get_analysis_engine() -> "UnifiedAnalysisEngine":
340
- """Get analysis engine instance for testing compatibility."""
341
- from ..core.analysis_engine import UnifiedAnalysisEngine
342
-
343
- return UnifiedAnalysisEngine()
1
+ #!/usr/bin/env python3
2
+ """
3
+ CLI Adapter for tree-sitter-analyzer
4
+
5
+ Adapter that uses the new unified analysis engine while maintaining compatibility with existing CLI API.
6
+
7
+ Roo Code compliance:
8
+ - Type hints: Required for all functions
9
+ - MCP logging: Log output at each step
10
+ - docstring: Google Style docstring
11
+ - Error handling: Proper exception handling
12
+ - Performance: Optimization through unified engine
13
+ """
14
+
15
+ import asyncio
16
+ import logging
17
+ import time
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ from ..core.analysis_engine import AnalysisRequest, UnifiedAnalysisEngine
22
+ from ..models import AnalysisResult
23
+
24
+ logger = logging.getLogger(__name__)
25
+
26
+
27
+ class CLIAdapter:
28
+ """
29
+ CLI Adapter
30
+
31
+ Uses the new unified analysis engine while maintaining compatibility with existing CLI API.
32
+ Provides synchronous API and internally calls asynchronous engine.
33
+
34
+ Features:
35
+ - Maintaining existing API compatibility
36
+ - Utilizing unified analysis engine
37
+ - Sync/async conversion
38
+ - Performance monitoring
39
+ - Error handling
40
+
41
+ Example:
42
+ >>> adapter = CLIAdapter()
43
+ >>> result = adapter.analyze_file("example.java")
44
+ >>> print(result.classes)
45
+ """
46
+
47
+ def __init__(self) -> None:
48
+ """
49
+ Initialize CLI adapter
50
+
51
+ Raises:
52
+ Exception: If unified analysis engine initialization fails
53
+ """
54
+ try:
55
+ self._engine = UnifiedAnalysisEngine()
56
+ logger.info("CLIAdapter initialized successfully")
57
+ except Exception as e:
58
+ logger.error(f"Failed to initialize CLIAdapter: {e}")
59
+ raise
60
+
61
+ def analyze_file(self, file_path: str, **kwargs: Any) -> AnalysisResult:
62
+ """
63
+ Analyze file (synchronous version)
64
+
65
+ Provides synchronous interface to maintain compatibility with existing CLI API.
66
+ Internally calls asynchronous methods of unified analysis engine.
67
+
68
+ Args:
69
+ file_path: Path to file to analyze
70
+ **kwargs: Analysis options
71
+ - language: Language specification (auto-detection possible)
72
+ - include_complexity: Include complexity calculation
73
+ - include_details: Include detailed information
74
+ - format_type: Output format ("standard", "structure", "summary")
75
+
76
+ Returns:
77
+ AnalysisResult: Analysis result
78
+
79
+ Raises:
80
+ ValueError: For invalid file path
81
+ FileNotFoundError: If file does not exist
82
+ UnsupportedLanguageError: For unsupported language
83
+
84
+ Example:
85
+ >>> adapter = CLIAdapter()
86
+ >>> result = adapter.analyze_file("example.java", include_complexity=True)
87
+ >>> print(f"Classes: {len(result.classes)}")
88
+ """
89
+ start_time = time.time()
90
+
91
+ # Input validation
92
+ if not file_path or not file_path.strip():
93
+ raise ValueError("File path cannot be empty")
94
+
95
+ # File existence check
96
+ if not Path(file_path).exists():
97
+ raise FileNotFoundError(f"File not found: {file_path}")
98
+
99
+ try:
100
+ # Create AnalysisRequest
101
+ request = AnalysisRequest(
102
+ file_path=file_path,
103
+ language=kwargs.get("language"),
104
+ include_complexity=kwargs.get("include_complexity", False),
105
+ include_details=kwargs.get("include_details", True),
106
+ format_type=kwargs.get("format_type", "standard"),
107
+ )
108
+
109
+ # Run async engine synchronously
110
+ result = asyncio.run(self._engine.analyze(request))
111
+
112
+ # パフォーマンスログ
113
+ elapsed_time = time.time() - start_time
114
+ logger.info(f"CLI analysis completed: {file_path} in {elapsed_time:.3f}s")
115
+
116
+ return result
117
+
118
+ except Exception as e:
119
+ logger.error(f"CLI analysis failed for {file_path}: {e}")
120
+ raise
121
+
122
+ def analyze_structure(self, file_path: str, **kwargs: Any) -> dict[str, Any]:
123
+ """
124
+ Structure analysis (legacy API compatible)
125
+
126
+ Returns structure info as a dictionary to keep compatibility with
127
+ existing CLI API.
128
+
129
+ Args:
130
+ file_path: Path to the file to analyze
131
+ **kwargs: Analysis options
132
+
133
+ Returns:
134
+ Dict[str, Any]: Structure dictionary
135
+ - file_path
136
+ - classes
137
+ - methods
138
+ - fields
139
+ - imports
140
+
141
+ Example:
142
+ >>> adapter = CLIAdapter()
143
+ >>> structure = adapter.analyze_structure("example.java")
144
+ >>> print(structure["classes"])
145
+ """
146
+ # 詳細情報を含めて解析
147
+ kwargs["include_details"] = True
148
+ kwargs["format_type"] = "structure"
149
+
150
+ result = self.analyze_file(file_path, **kwargs)
151
+
152
+ # 構造情報を辞書形式に変換
153
+ return {
154
+ "file_path": result.file_path,
155
+ "language": result.language,
156
+ "package": result.package,
157
+ "imports": [
158
+ {"name": imp.name, "type": str(type(imp).__name__)}
159
+ for imp in result.imports
160
+ ],
161
+ "classes": [
162
+ {"name": cls.name, "type": str(type(cls).__name__)}
163
+ for cls in result.classes
164
+ ],
165
+ "methods": [
166
+ {"name": method.name, "type": str(type(method).__name__)}
167
+ for method in result.methods
168
+ ],
169
+ "fields": [
170
+ {"name": field.name, "type": str(type(field).__name__)}
171
+ for field in result.fields
172
+ ],
173
+ "annotations": [
174
+ {
175
+ "name": getattr(ann, "name", str(ann)),
176
+ "type": str(type(ann).__name__),
177
+ }
178
+ for ann in getattr(result, "annotations", [])
179
+ ],
180
+ "analysis_time": result.analysis_time,
181
+ "elements": [
182
+ {"name": elem.name, "type": str(type(elem).__name__)}
183
+ for elem in result.elements
184
+ ],
185
+ "success": result.success,
186
+ }
187
+
188
+ def analyze_batch(
189
+ self, file_paths: list[str], **kwargs: Any
190
+ ) -> list[AnalysisResult]:
191
+ """
192
+ Analyze multiple files in batch
193
+
194
+ Args:
195
+ file_paths: List of file paths
196
+ **kwargs: Analysis options
197
+
198
+ Returns:
199
+ list[AnalysisResult]: List of results
200
+
201
+ Example:
202
+ >>> adapter = CLIAdapter()
203
+ >>> results = adapter.analyze_batch(["file1.java", "file2.java"])
204
+ >>> print(f"Analyzed {len(results)} files")
205
+ """
206
+ results = []
207
+
208
+ for file_path in file_paths:
209
+ try:
210
+ result = self.analyze_file(file_path, **kwargs)
211
+ results.append(result)
212
+ except Exception as e:
213
+ logger.warning(f"Failed to analyze {file_path}: {e}")
214
+ # Include failed item with error message
215
+ error_result = AnalysisResult(
216
+ file_path=file_path,
217
+ package=None,
218
+ imports=[],
219
+ classes=[],
220
+ methods=[],
221
+ fields=[],
222
+ annotations=[],
223
+ analysis_time=0.0,
224
+ success=False,
225
+ error_message=str(e),
226
+ )
227
+ results.append(error_result)
228
+
229
+ return results
230
+
231
+ def get_supported_languages(self) -> list[str]:
232
+ """
233
+ Get list of supported languages
234
+
235
+ Returns:
236
+ list[str]
237
+
238
+ Example:
239
+ >>> adapter = CLIAdapter()
240
+ >>> languages = adapter.get_supported_languages()
241
+ >>> print(languages)
242
+ """
243
+ return self._engine.get_supported_languages()
244
+
245
+ def clear_cache(self) -> None:
246
+ """
247
+ Clear cache
248
+
249
+ Example:
250
+ >>> adapter = CLIAdapter()
251
+ >>> adapter.clear_cache()
252
+ """
253
+ self._engine.clear_cache()
254
+ logger.info("CLI adapter cache cleared")
255
+
256
+ def get_cache_stats(self) -> dict[str, Any]:
257
+ """
258
+ Get cache statistics
259
+
260
+ Returns:
261
+ Dict[str, Any]
262
+
263
+ Example:
264
+ >>> adapter = CLIAdapter()
265
+ >>> stats = adapter.get_cache_stats()
266
+ >>> print(f"Cache hit rate: {stats['hit_rate']:.2%}")
267
+ """
268
+ return self._engine.get_cache_stats()
269
+
270
+ def validate_file(self, file_path: str) -> bool:
271
+ """
272
+ Validate whether a file is analyzable
273
+
274
+ Args:
275
+ file_path: File path to validate
276
+
277
+ Returns:
278
+ bool
279
+
280
+ Example:
281
+ >>> adapter = CLIAdapter()
282
+ >>> if adapter.validate_file("example.java"):
283
+ ... result = adapter.analyze_file("example.java")
284
+ """
285
+ try:
286
+ # ファイル存在チェック
287
+ if not Path(file_path).exists():
288
+ return False
289
+
290
+ # 言語サポートチェック
291
+ supported_languages = self.get_supported_languages()
292
+ file_extension = Path(file_path).suffix.lower()
293
+
294
+ # 拡張子から言語を推定
295
+ extension_map = {
296
+ ".java": "java",
297
+ ".py": "python",
298
+ ".js": "javascript",
299
+ ".ts": "typescript",
300
+ ".cpp": "cpp",
301
+ ".c": "c",
302
+ ".cs": "csharp",
303
+ ".go": "go",
304
+ ".rs": "rust",
305
+ ".php": "php",
306
+ ".rb": "ruby",
307
+ }
308
+
309
+ language = extension_map.get(file_extension)
310
+ return language in supported_languages if language else False
311
+
312
+ except Exception as e:
313
+ logger.warning(f"File validation failed for {file_path}: {e}")
314
+ return False
315
+
316
+ def get_engine_info(self) -> dict[str, Any]:
317
+ """
318
+ Get engine information
319
+
320
+ Returns:
321
+ Dict[str, Any]
322
+
323
+ Example:
324
+ >>> adapter = CLIAdapter()
325
+ >>> info = adapter.get_engine_info()
326
+ >>> print(f"Engine version: {info['version']}")
327
+ """
328
+ return {
329
+ "adapter_type": "CLI",
330
+ "engine_type": "UnifiedAnalysisEngine",
331
+ "supported_languages": self.get_supported_languages(),
332
+ "cache_enabled": True,
333
+ "async_support": True,
334
+ }
335
+
336
+
337
+ # Legacy AdvancedAnalyzerAdapter removed - use UnifiedAnalysisEngine directly
338
+
339
+
340
+ def get_analysis_engine() -> "UnifiedAnalysisEngine":
341
+ """Get analysis engine instance for testing compatibility."""
342
+ from ..core.analysis_engine import UnifiedAnalysisEngine
343
+
344
+ return UnifiedAnalysisEngine()