tree-sitter-analyzer 0.8.3__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.
- tree_sitter_analyzer/__init__.py +132 -132
- tree_sitter_analyzer/__main__.py +11 -11
- tree_sitter_analyzer/api.py +533 -533
- tree_sitter_analyzer/cli/__init__.py +39 -39
- tree_sitter_analyzer/cli/__main__.py +12 -12
- tree_sitter_analyzer/cli/commands/__init__.py +26 -26
- tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
- tree_sitter_analyzer/cli/commands/base_command.py +182 -180
- tree_sitter_analyzer/cli/commands/structure_command.py +138 -138
- tree_sitter_analyzer/cli/commands/summary_command.py +101 -101
- tree_sitter_analyzer/core/__init__.py +15 -15
- tree_sitter_analyzer/core/analysis_engine.py +74 -78
- tree_sitter_analyzer/core/cache_service.py +320 -320
- tree_sitter_analyzer/core/engine.py +566 -566
- tree_sitter_analyzer/core/parser.py +293 -293
- tree_sitter_analyzer/encoding_utils.py +459 -459
- tree_sitter_analyzer/file_handler.py +210 -210
- tree_sitter_analyzer/formatters/__init__.py +1 -1
- tree_sitter_analyzer/formatters/base_formatter.py +167 -167
- tree_sitter_analyzer/formatters/formatter_factory.py +78 -78
- tree_sitter_analyzer/formatters/java_formatter.py +18 -18
- tree_sitter_analyzer/formatters/python_formatter.py +19 -19
- tree_sitter_analyzer/interfaces/__init__.py +9 -9
- tree_sitter_analyzer/interfaces/cli.py +528 -528
- tree_sitter_analyzer/interfaces/cli_adapter.py +344 -343
- tree_sitter_analyzer/interfaces/mcp_adapter.py +206 -206
- tree_sitter_analyzer/language_detector.py +53 -53
- tree_sitter_analyzer/languages/__init__.py +10 -10
- tree_sitter_analyzer/languages/java_plugin.py +1 -1
- tree_sitter_analyzer/languages/javascript_plugin.py +446 -446
- tree_sitter_analyzer/languages/python_plugin.py +755 -755
- tree_sitter_analyzer/mcp/__init__.py +34 -31
- tree_sitter_analyzer/mcp/resources/__init__.py +44 -44
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +209 -209
- tree_sitter_analyzer/mcp/server.py +623 -436
- tree_sitter_analyzer/mcp/tools/__init__.py +30 -30
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +10 -6
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +247 -242
- tree_sitter_analyzer/mcp/tools/base_tool.py +54 -54
- tree_sitter_analyzer/mcp/tools/read_partial_tool.py +310 -308
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +386 -379
- tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +563 -559
- tree_sitter_analyzer/mcp/utils/__init__.py +107 -107
- tree_sitter_analyzer/models.py +10 -10
- tree_sitter_analyzer/output_manager.py +253 -253
- tree_sitter_analyzer/plugins/__init__.py +280 -280
- tree_sitter_analyzer/plugins/base.py +529 -529
- tree_sitter_analyzer/plugins/manager.py +379 -379
- tree_sitter_analyzer/queries/__init__.py +26 -26
- tree_sitter_analyzer/queries/java.py +391 -391
- tree_sitter_analyzer/queries/javascript.py +148 -148
- tree_sitter_analyzer/queries/python.py +285 -285
- tree_sitter_analyzer/queries/typescript.py +229 -229
- tree_sitter_analyzer/query_loader.py +257 -257
- tree_sitter_analyzer/security/boundary_manager.py +237 -279
- tree_sitter_analyzer/security/validator.py +60 -58
- tree_sitter_analyzer/utils.py +294 -277
- {tree_sitter_analyzer-0.8.3.dist-info → tree_sitter_analyzer-0.9.2.dist-info}/METADATA +28 -19
- tree_sitter_analyzer-0.9.2.dist-info/RECORD +77 -0
- {tree_sitter_analyzer-0.8.3.dist-info → tree_sitter_analyzer-0.9.2.dist-info}/entry_points.txt +1 -0
- tree_sitter_analyzer-0.8.3.dist-info/RECORD +0 -77
- {tree_sitter_analyzer-0.8.3.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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
-
|
|
136
|
-
-
|
|
137
|
-
-
|
|
138
|
-
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
>>>
|
|
143
|
-
>>>
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
kwargs["
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
"
|
|
155
|
-
"
|
|
156
|
-
"
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
"
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
>>>
|
|
203
|
-
>>>
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
>>>
|
|
240
|
-
>>>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
>>> adapter
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
>>>
|
|
265
|
-
>>>
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
>>>
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
".
|
|
297
|
-
".
|
|
298
|
-
".
|
|
299
|
-
".
|
|
300
|
-
".
|
|
301
|
-
".
|
|
302
|
-
".
|
|
303
|
-
".
|
|
304
|
-
".
|
|
305
|
-
".
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
>>>
|
|
325
|
-
>>>
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
"
|
|
330
|
-
"
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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()
|