tree-sitter-analyzer 0.3.0__py3-none-any.whl → 0.6.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.
- tree_sitter_analyzer/__init__.py +5 -6
- tree_sitter_analyzer/__main__.py +2 -2
- tree_sitter_analyzer/api.py +4 -2
- tree_sitter_analyzer/cli/__init__.py +3 -3
- tree_sitter_analyzer/cli/commands/advanced_command.py +1 -1
- tree_sitter_analyzer/cli/commands/base_command.py +1 -1
- tree_sitter_analyzer/cli/commands/default_command.py +1 -1
- tree_sitter_analyzer/cli/commands/partial_read_command.py +2 -2
- tree_sitter_analyzer/cli/commands/query_command.py +5 -5
- tree_sitter_analyzer/cli/commands/summary_command.py +2 -2
- tree_sitter_analyzer/cli/commands/table_command.py +14 -11
- tree_sitter_analyzer/cli/info_commands.py +14 -13
- tree_sitter_analyzer/cli_main.py +51 -31
- tree_sitter_analyzer/core/analysis_engine.py +54 -90
- tree_sitter_analyzer/core/cache_service.py +31 -31
- tree_sitter_analyzer/core/engine.py +6 -4
- tree_sitter_analyzer/core/parser.py +1 -1
- tree_sitter_analyzer/core/query.py +502 -494
- tree_sitter_analyzer/encoding_utils.py +3 -2
- tree_sitter_analyzer/exceptions.py +23 -23
- tree_sitter_analyzer/file_handler.py +7 -14
- tree_sitter_analyzer/formatters/base_formatter.py +18 -18
- tree_sitter_analyzer/formatters/formatter_factory.py +15 -15
- tree_sitter_analyzer/formatters/java_formatter.py +291 -287
- tree_sitter_analyzer/formatters/python_formatter.py +259 -255
- tree_sitter_analyzer/interfaces/cli.py +1 -1
- tree_sitter_analyzer/interfaces/cli_adapter.py +62 -41
- tree_sitter_analyzer/interfaces/mcp_adapter.py +43 -17
- tree_sitter_analyzer/interfaces/mcp_server.py +9 -9
- tree_sitter_analyzer/language_detector.py +398 -398
- tree_sitter_analyzer/language_loader.py +224 -224
- tree_sitter_analyzer/languages/java_plugin.py +1174 -1129
- tree_sitter_analyzer/{plugins → languages}/javascript_plugin.py +3 -3
- tree_sitter_analyzer/languages/python_plugin.py +26 -8
- tree_sitter_analyzer/mcp/resources/code_file_resource.py +0 -3
- tree_sitter_analyzer/mcp/resources/project_stats_resource.py +555 -560
- tree_sitter_analyzer/mcp/server.py +4 -4
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +63 -30
- tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +9 -4
- tree_sitter_analyzer/mcp/tools/table_format_tool.py +2 -2
- tree_sitter_analyzer/mcp/utils/__init__.py +10 -8
- tree_sitter_analyzer/models.py +470 -470
- tree_sitter_analyzer/output_manager.py +12 -20
- tree_sitter_analyzer/plugins/__init__.py +9 -62
- tree_sitter_analyzer/plugins/base.py +53 -1
- tree_sitter_analyzer/plugins/manager.py +29 -12
- tree_sitter_analyzer/queries/java.py +78 -78
- tree_sitter_analyzer/queries/javascript.py +7 -7
- tree_sitter_analyzer/queries/python.py +18 -18
- tree_sitter_analyzer/queries/typescript.py +12 -12
- tree_sitter_analyzer/query_loader.py +17 -14
- tree_sitter_analyzer/table_formatter.py +24 -19
- tree_sitter_analyzer/utils.py +7 -7
- {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/METADATA +11 -11
- tree_sitter_analyzer-0.6.0.dist-info/RECORD +72 -0
- {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/entry_points.txt +2 -1
- tree_sitter_analyzer/java_analyzer.py +0 -218
- tree_sitter_analyzer/plugins/java_plugin.py +0 -608
- tree_sitter_analyzer/plugins/plugin_loader.py +0 -85
- tree_sitter_analyzer/plugins/python_plugin.py +0 -606
- tree_sitter_analyzer/plugins/registry.py +0 -374
- tree_sitter_analyzer-0.3.0.dist-info/RECORD +0 -77
- {tree_sitter_analyzer-0.3.0.dist-info → tree_sitter_analyzer-0.6.0.dist-info}/WHEEL +0 -0
|
@@ -86,22 +86,22 @@ class OutputManager:
|
|
|
86
86
|
f"\n{index}. {result.get('capture_name', 'Unknown')} ({result.get('node_type', 'Unknown')})"
|
|
87
87
|
)
|
|
88
88
|
print(
|
|
89
|
-
f"
|
|
89
|
+
f" Position: Line {result.get('start_line', '?')}-{result.get('end_line', '?')}"
|
|
90
90
|
)
|
|
91
91
|
if "content" in result:
|
|
92
|
-
print(f"
|
|
92
|
+
print(f" Content:\n{result['content']}")
|
|
93
93
|
|
|
94
94
|
def analysis_summary(self, stats: dict[str, Any]) -> None:
|
|
95
95
|
"""Output analysis summary"""
|
|
96
96
|
if self.json_output:
|
|
97
97
|
self.data(stats)
|
|
98
98
|
else:
|
|
99
|
-
self.results_header("
|
|
99
|
+
self.results_header("Statistics")
|
|
100
100
|
for key, value in stats.items():
|
|
101
101
|
print(f"{key}: {value}")
|
|
102
102
|
|
|
103
103
|
def language_list(
|
|
104
|
-
self, languages: list[str], title: str = "
|
|
104
|
+
self, languages: list[str], title: str = "Supported Languages"
|
|
105
105
|
) -> None:
|
|
106
106
|
"""Output language list"""
|
|
107
107
|
if not self.quiet:
|
|
@@ -112,18 +112,18 @@ class OutputManager:
|
|
|
112
112
|
def query_list(self, queries: dict[str, str], language: str) -> None:
|
|
113
113
|
"""Output query list for a language"""
|
|
114
114
|
if not self.quiet:
|
|
115
|
-
print(f"
|
|
115
|
+
print(f"Available query keys ({language}):")
|
|
116
116
|
for query_key, description in queries.items():
|
|
117
117
|
print(f" {query_key:<20} - {description}")
|
|
118
118
|
|
|
119
119
|
def extension_list(self, extensions: list[str]) -> None:
|
|
120
120
|
"""Output supported extensions"""
|
|
121
121
|
if not self.quiet:
|
|
122
|
-
print("
|
|
122
|
+
print("Supported file extensions:")
|
|
123
123
|
for i in range(0, len(extensions), 10):
|
|
124
124
|
chunk = extensions[i : i + 10]
|
|
125
125
|
print(f" {' '.join(chunk)}")
|
|
126
|
-
print(f"
|
|
126
|
+
print(f"Total {len(extensions)} extensions supported")
|
|
127
127
|
|
|
128
128
|
def output_json(self, data: Any) -> None:
|
|
129
129
|
"""Output JSON data"""
|
|
@@ -159,11 +159,8 @@ class OutputManager:
|
|
|
159
159
|
|
|
160
160
|
def output_queries(self, queries: list[str]) -> None:
|
|
161
161
|
"""Output available queries"""
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
self.query_list(query_dict, "All")
|
|
165
|
-
else:
|
|
166
|
-
self.query_list(queries, "All")
|
|
162
|
+
query_dict = {q: f"Query {q}" for q in queries}
|
|
163
|
+
self.query_list(query_dict, "All")
|
|
167
164
|
|
|
168
165
|
def output_extensions(self, extensions: list[str]) -> None:
|
|
169
166
|
"""Output file extensions"""
|
|
@@ -235,20 +232,15 @@ def output_statistics(stats: dict[str, Any]) -> None:
|
|
|
235
232
|
_output_manager.output_statistics(stats)
|
|
236
233
|
|
|
237
234
|
|
|
238
|
-
def output_languages(
|
|
239
|
-
languages: list[str], title: str = "サポートされている言語"
|
|
240
|
-
) -> None:
|
|
235
|
+
def output_languages(languages: list[str], title: str = "Supported Languages") -> None:
|
|
241
236
|
"""Output available languages"""
|
|
242
237
|
_output_manager.language_list(languages, title)
|
|
243
238
|
|
|
244
239
|
|
|
245
240
|
def output_queries(queries: list[str], language: str = "All") -> None:
|
|
246
241
|
"""Output available queries"""
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
_output_manager.query_list(query_dict, language)
|
|
250
|
-
else:
|
|
251
|
-
_output_manager.query_list(queries, language)
|
|
242
|
+
query_dict = {q: f"Query {q}" for q in queries}
|
|
243
|
+
_output_manager.query_list(query_dict, language)
|
|
252
244
|
|
|
253
245
|
|
|
254
246
|
def output_extensions(extensions: list[str]) -> None:
|
|
@@ -21,7 +21,12 @@ from ..models import Import as ModelImport
|
|
|
21
21
|
from ..models import Variable as ModelVariable
|
|
22
22
|
from ..utils import log_debug, log_error, log_warning
|
|
23
23
|
|
|
24
|
-
__all__ = [
|
|
24
|
+
__all__ = [
|
|
25
|
+
"LanguagePlugin",
|
|
26
|
+
"ElementExtractor",
|
|
27
|
+
"DefaultExtractor",
|
|
28
|
+
"DefaultLanguagePlugin",
|
|
29
|
+
]
|
|
25
30
|
|
|
26
31
|
|
|
27
32
|
class ElementExtractor(ABC):
|
|
@@ -255,50 +260,7 @@ class DefaultExtractor(ElementExtractor):
|
|
|
255
260
|
return None
|
|
256
261
|
|
|
257
262
|
|
|
258
|
-
|
|
259
|
-
"""Registry for managing language plugins"""
|
|
260
|
-
|
|
261
|
-
def __init__(self) -> None:
|
|
262
|
-
self._plugins: dict[str, LanguagePlugin] = {}
|
|
263
|
-
self._extension_map: dict[str, LanguagePlugin] = {}
|
|
264
|
-
self._default_plugin = DefaultLanguagePlugin()
|
|
265
|
-
|
|
266
|
-
def register_plugin(self, plugin: LanguagePlugin) -> None:
|
|
267
|
-
"""Register a language plugin"""
|
|
268
|
-
try:
|
|
269
|
-
language = plugin.get_language_name()
|
|
270
|
-
self._plugins[language] = plugin
|
|
271
|
-
|
|
272
|
-
# Register file extensions
|
|
273
|
-
for ext in plugin.get_file_extensions():
|
|
274
|
-
self._extension_map[ext] = plugin
|
|
275
|
-
|
|
276
|
-
log_debug(f"Registered plugin for language: {language}")
|
|
277
|
-
except Exception as e:
|
|
278
|
-
log_error(f"Failed to register plugin: {e}")
|
|
279
|
-
|
|
280
|
-
def get_plugin(self, language: str) -> LanguagePlugin | None:
|
|
281
|
-
"""Get plugin for specified language"""
|
|
282
|
-
return self._plugins.get(language)
|
|
283
|
-
|
|
284
|
-
def get_plugin_by_extension(self, extension: str) -> LanguagePlugin | None:
|
|
285
|
-
"""Get plugin for specified file extension"""
|
|
286
|
-
return self._extension_map.get(extension)
|
|
287
|
-
|
|
288
|
-
def get_plugin_for_file(self, file_path: str) -> LanguagePlugin:
|
|
289
|
-
"""Get appropriate plugin for a file"""
|
|
290
|
-
for plugin in self._plugins.values():
|
|
291
|
-
if plugin.is_applicable(file_path):
|
|
292
|
-
return plugin
|
|
293
|
-
return self._default_plugin
|
|
294
|
-
|
|
295
|
-
def list_supported_languages(self) -> list[str]:
|
|
296
|
-
"""List all supported languages"""
|
|
297
|
-
return list(self._plugins.keys())
|
|
298
|
-
|
|
299
|
-
def list_supported_extensions(self) -> list[str]:
|
|
300
|
-
"""List all supported file extensions"""
|
|
301
|
-
return list(self._extension_map.keys())
|
|
263
|
+
# Legacy PluginRegistry removed - now using PluginManager from .manager
|
|
302
264
|
|
|
303
265
|
|
|
304
266
|
class DefaultLanguagePlugin(LanguagePlugin):
|
|
@@ -314,20 +276,5 @@ class DefaultLanguagePlugin(LanguagePlugin):
|
|
|
314
276
|
return DefaultExtractor()
|
|
315
277
|
|
|
316
278
|
|
|
317
|
-
#
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
# Auto-load all plugins when the package is imported
|
|
322
|
-
try:
|
|
323
|
-
# from .plugin_loader import (
|
|
324
|
-
# get_supported_extensions, # Not used currently
|
|
325
|
-
# get_supported_languages, # Not used currently
|
|
326
|
-
# load_all_plugins, # Not used currently
|
|
327
|
-
# )
|
|
328
|
-
pass
|
|
329
|
-
# Plugins are automatically loaded when plugin_loader is imported
|
|
330
|
-
except ImportError as e:
|
|
331
|
-
from ..utils import log_warning
|
|
332
|
-
|
|
333
|
-
log_warning(f"Could not load plugin loader: {e}")
|
|
279
|
+
# Legacy plugin registry removed - now using PluginManager
|
|
280
|
+
# from .manager import PluginManager
|
|
@@ -13,6 +13,9 @@ from typing import TYPE_CHECKING, Any
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
14
|
import tree_sitter
|
|
15
15
|
|
|
16
|
+
from ..core.analysis_engine import AnalysisRequest
|
|
17
|
+
from ..models import AnalysisResult
|
|
18
|
+
|
|
16
19
|
from ..models import Class as ModelClass
|
|
17
20
|
from ..models import CodeElement
|
|
18
21
|
from ..models import Function as ModelFunction
|
|
@@ -108,7 +111,7 @@ class ElementExtractor(ABC):
|
|
|
108
111
|
Returns:
|
|
109
112
|
List of all extracted code elements
|
|
110
113
|
"""
|
|
111
|
-
elements = []
|
|
114
|
+
elements: list[CodeElement] = []
|
|
112
115
|
|
|
113
116
|
try:
|
|
114
117
|
elements.extend(self.extract_functions(tree, source_code))
|
|
@@ -159,6 +162,22 @@ class LanguagePlugin(ABC):
|
|
|
159
162
|
"""
|
|
160
163
|
pass
|
|
161
164
|
|
|
165
|
+
@abstractmethod
|
|
166
|
+
async def analyze_file(
|
|
167
|
+
self, file_path: str, request: "AnalysisRequest"
|
|
168
|
+
) -> "AnalysisResult":
|
|
169
|
+
"""
|
|
170
|
+
Analyze a file and return analysis results.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
file_path: Path to the file to analyze
|
|
174
|
+
request: Analysis request with configuration
|
|
175
|
+
|
|
176
|
+
Returns:
|
|
177
|
+
AnalysisResult containing extracted information
|
|
178
|
+
"""
|
|
179
|
+
pass
|
|
180
|
+
|
|
162
181
|
def is_applicable(self, file_path: str) -> bool:
|
|
163
182
|
"""
|
|
164
183
|
Check if this plugin is applicable for the given file.
|
|
@@ -475,3 +494,36 @@ class DefaultLanguagePlugin(LanguagePlugin):
|
|
|
475
494
|
|
|
476
495
|
def create_extractor(self) -> ElementExtractor:
|
|
477
496
|
return DefaultExtractor()
|
|
497
|
+
|
|
498
|
+
async def analyze_file(
|
|
499
|
+
self, file_path: str, request: "AnalysisRequest"
|
|
500
|
+
) -> "AnalysisResult":
|
|
501
|
+
"""
|
|
502
|
+
Analyze a file using the default extractor.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
file_path: Path to the file to analyze
|
|
506
|
+
request: Analysis request with configuration
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
AnalysisResult containing extracted information
|
|
510
|
+
"""
|
|
511
|
+
from ..core.analysis_engine import UnifiedAnalysisEngine
|
|
512
|
+
from ..models import AnalysisResult
|
|
513
|
+
|
|
514
|
+
try:
|
|
515
|
+
engine = UnifiedAnalysisEngine()
|
|
516
|
+
return await engine.analyze_file(file_path)
|
|
517
|
+
except Exception as e:
|
|
518
|
+
log_error(f"Failed to analyze file {file_path}: {e}")
|
|
519
|
+
return AnalysisResult(
|
|
520
|
+
file_path=file_path,
|
|
521
|
+
language=self.get_language_name(),
|
|
522
|
+
line_count=0,
|
|
523
|
+
elements=[],
|
|
524
|
+
node_count=0,
|
|
525
|
+
query_results={},
|
|
526
|
+
source_code="",
|
|
527
|
+
success=False,
|
|
528
|
+
error_message=str(e),
|
|
529
|
+
)
|
|
@@ -11,6 +11,7 @@ import importlib.metadata
|
|
|
11
11
|
import logging
|
|
12
12
|
import pkgutil
|
|
13
13
|
from pathlib import Path
|
|
14
|
+
from typing import Any
|
|
14
15
|
|
|
15
16
|
from ..utils import log_debug, log_error, log_info, log_warning
|
|
16
17
|
from .base import LanguagePlugin
|
|
@@ -29,7 +30,7 @@ class PluginManager:
|
|
|
29
30
|
- Error handling and fallback mechanisms
|
|
30
31
|
"""
|
|
31
32
|
|
|
32
|
-
def __init__(self):
|
|
33
|
+
def __init__(self) -> None:
|
|
33
34
|
"""Initialize the plugin manager."""
|
|
34
35
|
self._loaded_plugins: dict[str, LanguagePlugin] = {}
|
|
35
36
|
self._plugin_classes: dict[str, type[LanguagePlugin]] = {}
|
|
@@ -52,13 +53,19 @@ class PluginManager:
|
|
|
52
53
|
local_plugins = self._load_from_local_directory()
|
|
53
54
|
loaded_plugins.extend(local_plugins)
|
|
54
55
|
|
|
55
|
-
# Store loaded plugins
|
|
56
|
+
# Store loaded plugins and deduplicate by language
|
|
57
|
+
unique_plugins = {}
|
|
56
58
|
for plugin in loaded_plugins:
|
|
57
59
|
language = plugin.get_language_name()
|
|
58
|
-
|
|
60
|
+
if language not in unique_plugins:
|
|
61
|
+
unique_plugins[language] = plugin
|
|
62
|
+
self._loaded_plugins[language] = plugin
|
|
63
|
+
else:
|
|
64
|
+
log_debug(f"Skipping duplicate plugin for language: {language}")
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
final_plugins = list(unique_plugins.values())
|
|
67
|
+
log_info(f"Successfully loaded {len(final_plugins)} plugins")
|
|
68
|
+
return final_plugins
|
|
62
69
|
|
|
63
70
|
def _load_from_entry_points(self) -> list[LanguagePlugin]:
|
|
64
71
|
"""
|
|
@@ -74,12 +81,22 @@ class PluginManager:
|
|
|
74
81
|
entry_points = importlib.metadata.entry_points()
|
|
75
82
|
|
|
76
83
|
# Handle both old and new entry_points API
|
|
84
|
+
plugin_entries: Any = []
|
|
77
85
|
if hasattr(entry_points, "select"):
|
|
78
86
|
# New API (Python 3.10+)
|
|
79
87
|
plugin_entries = entry_points.select(group=self._entry_point_group)
|
|
80
88
|
else:
|
|
81
|
-
# Old API
|
|
82
|
-
|
|
89
|
+
# Old API - handle different return types
|
|
90
|
+
try:
|
|
91
|
+
# Try to get entry points, handling different API versions
|
|
92
|
+
if hasattr(entry_points, "get"):
|
|
93
|
+
result = entry_points.get(self._entry_point_group)
|
|
94
|
+
plugin_entries = list(result) if result else []
|
|
95
|
+
else:
|
|
96
|
+
plugin_entries = []
|
|
97
|
+
except (TypeError, AttributeError):
|
|
98
|
+
# Fallback for incompatible entry_points types
|
|
99
|
+
plugin_entries = []
|
|
83
100
|
|
|
84
101
|
for entry_point in plugin_entries:
|
|
85
102
|
try:
|
|
@@ -116,7 +133,7 @@ class PluginManager:
|
|
|
116
133
|
Returns:
|
|
117
134
|
List of plugin instances loaded from local directory
|
|
118
135
|
"""
|
|
119
|
-
plugins = []
|
|
136
|
+
plugins: list[LanguagePlugin] = []
|
|
120
137
|
|
|
121
138
|
try:
|
|
122
139
|
# Get the languages directory path
|
|
@@ -171,7 +188,7 @@ class PluginManager:
|
|
|
171
188
|
|
|
172
189
|
return plugins
|
|
173
190
|
|
|
174
|
-
def _find_plugin_classes(self, module) -> list[type[LanguagePlugin]]:
|
|
191
|
+
def _find_plugin_classes(self, module: Any) -> list[type[LanguagePlugin]]:
|
|
175
192
|
"""
|
|
176
193
|
Find LanguagePlugin classes in a module.
|
|
177
194
|
|
|
@@ -181,7 +198,7 @@ class PluginManager:
|
|
|
181
198
|
Returns:
|
|
182
199
|
List of LanguagePlugin classes found in the module
|
|
183
200
|
"""
|
|
184
|
-
plugin_classes = []
|
|
201
|
+
plugin_classes: list[type[LanguagePlugin]] = []
|
|
185
202
|
|
|
186
203
|
for attr_name in dir(module):
|
|
187
204
|
attr = getattr(module, attr_name)
|
|
@@ -285,7 +302,7 @@ class PluginManager:
|
|
|
285
302
|
|
|
286
303
|
return False
|
|
287
304
|
|
|
288
|
-
def get_plugin_info(self, language: str) -> dict[str,
|
|
305
|
+
def get_plugin_info(self, language: str) -> dict[str, Any] | None:
|
|
289
306
|
"""
|
|
290
307
|
Get information about a specific plugin.
|
|
291
308
|
|
|
@@ -347,7 +364,7 @@ class PluginManager:
|
|
|
347
364
|
|
|
348
365
|
extensions = plugin.get_file_extensions()
|
|
349
366
|
if not isinstance(extensions, list):
|
|
350
|
-
log_error("Plugin get_file_extensions() must return a list")
|
|
367
|
+
log_error("Plugin get_file_extensions() must return a list") # type: ignore[unreachable]
|
|
351
368
|
return False
|
|
352
369
|
|
|
353
370
|
extractor = plugin.create_extractor()
|
|
@@ -6,9 +6,9 @@ Tree-sitter queries specific to Java language constructs.
|
|
|
6
6
|
Covers classes, methods, annotations, imports, and other Java-specific elements.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
# Java
|
|
9
|
+
# Java-specific query library
|
|
10
10
|
JAVA_QUERIES: dict[str, str] = {
|
|
11
|
-
# ---
|
|
11
|
+
# --- Basic Structure ---
|
|
12
12
|
"class": """
|
|
13
13
|
(class_declaration) @class
|
|
14
14
|
""",
|
|
@@ -21,7 +21,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
21
21
|
"annotation_type": """
|
|
22
22
|
(annotation_type_declaration) @annotation_type
|
|
23
23
|
""",
|
|
24
|
-
# ---
|
|
24
|
+
# --- Methods and Constructors ---
|
|
25
25
|
"method": """
|
|
26
26
|
(method_declaration) @method
|
|
27
27
|
""",
|
|
@@ -33,7 +33,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
33
33
|
(modifiers) @mod
|
|
34
34
|
(#match? @mod "abstract")) @abstract_method
|
|
35
35
|
""",
|
|
36
|
-
# ---
|
|
36
|
+
# --- Fields and Variables ---
|
|
37
37
|
"field": """
|
|
38
38
|
(field_declaration) @field
|
|
39
39
|
""",
|
|
@@ -47,7 +47,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
47
47
|
(modifiers) @mod
|
|
48
48
|
(#match? @mod "final")) @final_field
|
|
49
49
|
""",
|
|
50
|
-
# ---
|
|
50
|
+
# --- Imports and Packages ---
|
|
51
51
|
"import": """
|
|
52
52
|
(import_declaration) @import
|
|
53
53
|
""",
|
|
@@ -58,7 +58,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
58
58
|
"package": """
|
|
59
59
|
(package_declaration) @package
|
|
60
60
|
""",
|
|
61
|
-
# ---
|
|
61
|
+
# --- Annotations ---
|
|
62
62
|
"annotation": """
|
|
63
63
|
(annotation) @annotation
|
|
64
64
|
""",
|
|
@@ -69,7 +69,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
69
69
|
(annotation
|
|
70
70
|
(annotation_argument_list)) @annotation_with_params
|
|
71
71
|
""",
|
|
72
|
-
# --- Java
|
|
72
|
+
# --- Java-specific Constructs ---
|
|
73
73
|
"lambda": """
|
|
74
74
|
(lambda_expression) @lambda
|
|
75
75
|
""",
|
|
@@ -82,7 +82,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
82
82
|
"generic_type": """
|
|
83
83
|
(generic_type) @generic_type
|
|
84
84
|
""",
|
|
85
|
-
# ---
|
|
85
|
+
# --- Name-only Extraction ---
|
|
86
86
|
"class_name": """
|
|
87
87
|
(class_declaration
|
|
88
88
|
name: (identifier) @class_name)
|
|
@@ -96,7 +96,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
96
96
|
declarator: (variable_declarator
|
|
97
97
|
name: (identifier) @field_name))
|
|
98
98
|
""",
|
|
99
|
-
# ---
|
|
99
|
+
# --- Detailed Queries ---
|
|
100
100
|
"class_with_body": """
|
|
101
101
|
(class_declaration
|
|
102
102
|
name: (identifier) @name
|
|
@@ -112,7 +112,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
112
112
|
(modifiers (annotation) @annotation)*
|
|
113
113
|
name: (identifier) @name) @method_with_annotations
|
|
114
114
|
""",
|
|
115
|
-
# ---
|
|
115
|
+
# --- Inheritance Relations ---
|
|
116
116
|
"extends_clause": """
|
|
117
117
|
(class_declaration
|
|
118
118
|
(superclass) @extends_clause)
|
|
@@ -121,7 +121,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
121
121
|
(class_declaration
|
|
122
122
|
(super_interfaces) @implements_clause)
|
|
123
123
|
""",
|
|
124
|
-
# ---
|
|
124
|
+
# --- By Modifiers ---
|
|
125
125
|
"public_methods": """
|
|
126
126
|
(method_declaration
|
|
127
127
|
(modifiers) @mod
|
|
@@ -140,7 +140,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
140
140
|
(#match? @mod "static")
|
|
141
141
|
name: (identifier) @name) @static_methods
|
|
142
142
|
""",
|
|
143
|
-
# --- Spring Framework
|
|
143
|
+
# --- Spring Framework Annotations ---
|
|
144
144
|
"spring_controller": """
|
|
145
145
|
(class_declaration
|
|
146
146
|
(modifiers (annotation
|
|
@@ -162,7 +162,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
162
162
|
(#match? @annotation_name "Repository")))
|
|
163
163
|
name: (identifier) @repository_name) @spring_repository
|
|
164
164
|
""",
|
|
165
|
-
# --- JPA
|
|
165
|
+
# --- JPA Annotations ---
|
|
166
166
|
"jpa_entity": """
|
|
167
167
|
(class_declaration
|
|
168
168
|
(modifiers (annotation
|
|
@@ -178,7 +178,7 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
178
178
|
declarator: (variable_declarator
|
|
179
179
|
name: (identifier) @field_name)) @jpa_id_field
|
|
180
180
|
""",
|
|
181
|
-
# ---
|
|
181
|
+
# --- Structural Information Extraction Queries ---
|
|
182
182
|
"javadoc_comment": """
|
|
183
183
|
(block_comment) @javadoc_comment
|
|
184
184
|
(#match? @javadoc_comment "^/\\*\\*")
|
|
@@ -257,108 +257,108 @@ JAVA_QUERIES: dict[str, str] = {
|
|
|
257
257
|
""",
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
#
|
|
260
|
+
# Query descriptions
|
|
261
261
|
JAVA_QUERY_DESCRIPTIONS: dict[str, str] = {
|
|
262
|
-
"class": "Java
|
|
263
|
-
"interface": "Java
|
|
264
|
-
"enum": "Java
|
|
265
|
-
"annotation_type": "Java
|
|
266
|
-
"method": "Java
|
|
267
|
-
"constructor": "Java
|
|
268
|
-
"field": "Java
|
|
269
|
-
"import": "Java
|
|
270
|
-
"package": "Java
|
|
271
|
-
"annotation": "Java
|
|
272
|
-
"lambda": "Java
|
|
273
|
-
"try_catch": "Java try-catch
|
|
274
|
-
"class_name": "
|
|
275
|
-
"method_name": "
|
|
276
|
-
"field_name": "
|
|
277
|
-
"class_with_body": "
|
|
278
|
-
"method_with_body": "
|
|
279
|
-
"extends_clause": "
|
|
280
|
-
"implements_clause": "
|
|
281
|
-
"public_methods": "public
|
|
282
|
-
"private_methods": "private
|
|
283
|
-
"static_methods": "static
|
|
284
|
-
#
|
|
285
|
-
"javadoc_comment": "JavaDoc
|
|
286
|
-
"class_with_javadoc": "JavaDoc
|
|
287
|
-
"method_with_javadoc": "JavaDoc
|
|
288
|
-
"field_with_javadoc": "JavaDoc
|
|
289
|
-
"method_parameters_detailed": "
|
|
290
|
-
"class_inheritance_detailed": "
|
|
291
|
-
"annotation_detailed": "
|
|
292
|
-
"import_detailed": "
|
|
293
|
-
"package_detailed": "
|
|
294
|
-
"constructor_detailed": "
|
|
295
|
-
"enum_constant": "
|
|
296
|
-
"interface_method": "
|
|
297
|
-
"spring_controller": "Spring Controller
|
|
298
|
-
"spring_service": "Spring Service
|
|
299
|
-
"spring_repository": "Spring Repository
|
|
300
|
-
"jpa_entity": "JPA Entity
|
|
301
|
-
"abstract_method": "
|
|
302
|
-
"static_field": "
|
|
303
|
-
"final_field": "final
|
|
304
|
-
"static_import": "
|
|
305
|
-
"marker_annotation": "
|
|
306
|
-
"annotation_with_params": "
|
|
307
|
-
"synchronized_block": "synchronized
|
|
308
|
-
"generic_type": "
|
|
309
|
-
"method_with_annotations": "
|
|
310
|
-
"jpa_id_field": "JPA ID
|
|
262
|
+
"class": "Extract Java class declarations",
|
|
263
|
+
"interface": "Extract Java interface declarations",
|
|
264
|
+
"enum": "Extract Java enum declarations",
|
|
265
|
+
"annotation_type": "Extract Java annotation type declarations",
|
|
266
|
+
"method": "Extract Java method declarations",
|
|
267
|
+
"constructor": "Extract Java constructor declarations",
|
|
268
|
+
"field": "Extract Java field declarations",
|
|
269
|
+
"import": "Extract Java import statements",
|
|
270
|
+
"package": "Extract Java package declarations",
|
|
271
|
+
"annotation": "Extract Java annotations",
|
|
272
|
+
"lambda": "Extract Java lambda expressions",
|
|
273
|
+
"try_catch": "Extract Java try-catch statements",
|
|
274
|
+
"class_name": "Extract class names only",
|
|
275
|
+
"method_name": "Extract method names only",
|
|
276
|
+
"field_name": "Extract field names only",
|
|
277
|
+
"class_with_body": "Extract class declarations with body",
|
|
278
|
+
"method_with_body": "Extract method declarations with body",
|
|
279
|
+
"extends_clause": "Extract class inheritance clauses",
|
|
280
|
+
"implements_clause": "Extract class implementation clauses",
|
|
281
|
+
"public_methods": "Extract public methods",
|
|
282
|
+
"private_methods": "Extract private methods",
|
|
283
|
+
"static_methods": "Extract static methods",
|
|
284
|
+
# Structural information extraction query descriptions
|
|
285
|
+
"javadoc_comment": "Extract JavaDoc comments",
|
|
286
|
+
"class_with_javadoc": "Extract classes with JavaDoc",
|
|
287
|
+
"method_with_javadoc": "Extract methods with JavaDoc",
|
|
288
|
+
"field_with_javadoc": "Extract fields with JavaDoc",
|
|
289
|
+
"method_parameters_detailed": "Extract detailed method parameter information",
|
|
290
|
+
"class_inheritance_detailed": "Extract detailed class inheritance relationships",
|
|
291
|
+
"annotation_detailed": "Extract detailed annotation information",
|
|
292
|
+
"import_detailed": "Extract detailed import statement information",
|
|
293
|
+
"package_detailed": "Extract detailed package declaration information",
|
|
294
|
+
"constructor_detailed": "Extract detailed constructor information",
|
|
295
|
+
"enum_constant": "Extract enum constants",
|
|
296
|
+
"interface_method": "Extract interface methods",
|
|
297
|
+
"spring_controller": "Extract Spring Controller classes",
|
|
298
|
+
"spring_service": "Extract Spring Service classes",
|
|
299
|
+
"spring_repository": "Extract Spring Repository classes",
|
|
300
|
+
"jpa_entity": "Extract JPA Entity classes",
|
|
301
|
+
"abstract_method": "Extract abstract methods",
|
|
302
|
+
"static_field": "Extract static fields",
|
|
303
|
+
"final_field": "Extract final fields",
|
|
304
|
+
"static_import": "Extract static import statements",
|
|
305
|
+
"marker_annotation": "Extract marker annotations",
|
|
306
|
+
"annotation_with_params": "Extract annotations with parameters",
|
|
307
|
+
"synchronized_block": "Extract synchronized statements",
|
|
308
|
+
"generic_type": "Extract generic types",
|
|
309
|
+
"method_with_annotations": "Extract methods with annotations",
|
|
310
|
+
"jpa_id_field": "Extract JPA ID fields",
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
|
|
314
314
|
def get_java_query(name: str) -> str:
|
|
315
315
|
"""
|
|
316
|
-
|
|
316
|
+
Get the specified Java query
|
|
317
317
|
|
|
318
318
|
Args:
|
|
319
|
-
name:
|
|
319
|
+
name: Query name
|
|
320
320
|
|
|
321
321
|
Returns:
|
|
322
|
-
|
|
322
|
+
Query string
|
|
323
323
|
|
|
324
324
|
Raises:
|
|
325
|
-
ValueError:
|
|
325
|
+
ValueError: When query is not found
|
|
326
326
|
"""
|
|
327
327
|
if name not in JAVA_QUERIES:
|
|
328
328
|
available = list(JAVA_QUERIES.keys())
|
|
329
|
-
raise ValueError(f"Java
|
|
329
|
+
raise ValueError(f"Java query '{name}' does not exist. Available: {available}")
|
|
330
330
|
|
|
331
331
|
return JAVA_QUERIES[name]
|
|
332
332
|
|
|
333
333
|
|
|
334
334
|
def get_java_query_description(name: str) -> str:
|
|
335
335
|
"""
|
|
336
|
-
|
|
336
|
+
Get the description of the specified Java query
|
|
337
337
|
|
|
338
338
|
Args:
|
|
339
|
-
name:
|
|
339
|
+
name: Query name
|
|
340
340
|
|
|
341
341
|
Returns:
|
|
342
|
-
|
|
342
|
+
Query description
|
|
343
343
|
"""
|
|
344
|
-
return JAVA_QUERY_DESCRIPTIONS.get(name, "
|
|
344
|
+
return JAVA_QUERY_DESCRIPTIONS.get(name, "No description")
|
|
345
345
|
|
|
346
346
|
|
|
347
347
|
# Convert to ALL_QUERIES format for dynamic loader compatibility
|
|
348
348
|
ALL_QUERIES = {}
|
|
349
349
|
for query_name, query_string in JAVA_QUERIES.items():
|
|
350
|
-
description = JAVA_QUERY_DESCRIPTIONS.get(query_name, "
|
|
350
|
+
description = JAVA_QUERY_DESCRIPTIONS.get(query_name, "No description")
|
|
351
351
|
ALL_QUERIES[query_name] = {"query": query_string, "description": description}
|
|
352
352
|
|
|
353
353
|
# Add common query aliases for cross-language compatibility
|
|
354
354
|
ALL_QUERIES["functions"] = {
|
|
355
355
|
"query": JAVA_QUERIES["method"],
|
|
356
|
-
"description": "
|
|
356
|
+
"description": "Search all function/method declarations (alias for method)",
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
ALL_QUERIES["classes"] = {
|
|
360
360
|
"query": JAVA_QUERIES["class"],
|
|
361
|
-
"description": "
|
|
361
|
+
"description": "Search all class declarations (alias for class)",
|
|
362
362
|
}
|
|
363
363
|
|
|
364
364
|
|
|
@@ -383,9 +383,9 @@ def list_queries() -> list:
|
|
|
383
383
|
|
|
384
384
|
def get_available_java_queries() -> list[str]:
|
|
385
385
|
"""
|
|
386
|
-
|
|
386
|
+
Get list of available Java queries
|
|
387
387
|
|
|
388
388
|
Returns:
|
|
389
|
-
|
|
389
|
+
List of query names
|
|
390
390
|
"""
|
|
391
391
|
return list(JAVA_QUERIES.keys())
|