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,391 +1,391 @@
1
- #!/usr/bin/env python3
2
- """
3
- Java Language Queries
4
-
5
- Tree-sitter queries specific to Java language constructs.
6
- Covers classes, methods, annotations, imports, and other Java-specific elements.
7
- """
8
-
9
- # Java-specific query library
10
- JAVA_QUERIES: dict[str, str] = {
11
- # --- Basic Structure ---
12
- "class": """
13
- (class_declaration) @class
14
- """,
15
- "interface": """
16
- (interface_declaration) @interface
17
- """,
18
- "enum": """
19
- (enum_declaration) @enum
20
- """,
21
- "annotation_type": """
22
- (annotation_type_declaration) @annotation_type
23
- """,
24
- # --- Methods and Constructors ---
25
- "method": """
26
- (method_declaration) @method
27
- """,
28
- "constructor": """
29
- (constructor_declaration) @constructor
30
- """,
31
- "abstract_method": """
32
- (method_declaration
33
- (modifiers) @mod
34
- (#match? @mod "abstract")) @abstract_method
35
- """,
36
- # --- Fields and Variables ---
37
- "field": """
38
- (field_declaration) @field
39
- """,
40
- "static_field": """
41
- (field_declaration
42
- (modifiers) @mod
43
- (#match? @mod "static")) @static_field
44
- """,
45
- "final_field": """
46
- (field_declaration
47
- (modifiers) @mod
48
- (#match? @mod "final")) @final_field
49
- """,
50
- # --- Imports and Packages ---
51
- "import": """
52
- (import_declaration) @import
53
- """,
54
- "static_import": """
55
- (import_declaration
56
- "static") @static_import
57
- """,
58
- "package": """
59
- (package_declaration) @package
60
- """,
61
- # --- Annotations ---
62
- "annotation": """
63
- (annotation) @annotation
64
- """,
65
- "marker_annotation": """
66
- (marker_annotation) @marker_annotation
67
- """,
68
- "annotation_with_params": """
69
- (annotation
70
- (annotation_argument_list)) @annotation_with_params
71
- """,
72
- # --- Java-specific Constructs ---
73
- "lambda": """
74
- (lambda_expression) @lambda
75
- """,
76
- "try_catch": """
77
- (try_statement) @try_catch
78
- """,
79
- "synchronized_block": """
80
- (synchronized_statement) @synchronized_block
81
- """,
82
- "generic_type": """
83
- (generic_type) @generic_type
84
- """,
85
- # --- Name-only Extraction ---
86
- "class_name": """
87
- (class_declaration
88
- name: (identifier) @class_name)
89
- """,
90
- "method_name": """
91
- (method_declaration
92
- name: (identifier) @method_name)
93
- """,
94
- "field_name": """
95
- (field_declaration
96
- declarator: (variable_declarator
97
- name: (identifier) @field_name))
98
- """,
99
- # --- Detailed Queries ---
100
- "class_with_body": """
101
- (class_declaration
102
- name: (identifier) @name
103
- body: (class_body) @body) @class_with_body
104
- """,
105
- "method_with_body": """
106
- (method_declaration
107
- name: (identifier) @name
108
- body: (block) @body) @method_with_body
109
- """,
110
- "method_with_annotations": """
111
- (method_declaration
112
- (modifiers (annotation) @annotation)*
113
- name: (identifier) @name) @method_with_annotations
114
- """,
115
- # --- Inheritance Relations ---
116
- "extends_clause": """
117
- (class_declaration
118
- (superclass) @extends_clause)
119
- """,
120
- "implements_clause": """
121
- (class_declaration
122
- (super_interfaces) @implements_clause)
123
- """,
124
- # --- By Modifiers ---
125
- "public_methods": """
126
- (method_declaration
127
- (modifiers) @mod
128
- (#match? @mod "public")
129
- name: (identifier) @name) @public_methods
130
- """,
131
- "private_methods": """
132
- (method_declaration
133
- (modifiers) @mod
134
- (#match? @mod "private")
135
- name: (identifier) @name) @private_methods
136
- """,
137
- "static_methods": """
138
- (method_declaration
139
- (modifiers) @mod
140
- (#match? @mod "static")
141
- name: (identifier) @name) @static_methods
142
- """,
143
- # --- Spring Framework Annotations ---
144
- "spring_controller": """
145
- (class_declaration
146
- (modifiers (annotation
147
- name: (identifier) @annotation_name
148
- (#match? @annotation_name "Controller|RestController")))
149
- name: (identifier) @controller_name) @spring_controller
150
- """,
151
- "spring_service": """
152
- (class_declaration
153
- (modifiers (annotation
154
- name: (identifier) @annotation_name
155
- (#match? @annotation_name "Service")))
156
- name: (identifier) @service_name) @spring_service
157
- """,
158
- "spring_repository": """
159
- (class_declaration
160
- (modifiers (annotation
161
- name: (identifier) @annotation_name
162
- (#match? @annotation_name "Repository")))
163
- name: (identifier) @repository_name) @spring_repository
164
- """,
165
- # --- JPA Annotations ---
166
- "jpa_entity": """
167
- (class_declaration
168
- (modifiers (annotation
169
- name: (identifier) @annotation_name
170
- (#match? @annotation_name "Entity")))
171
- name: (identifier) @entity_name) @jpa_entity
172
- """,
173
- "jpa_id_field": """
174
- (field_declaration
175
- (modifiers (annotation
176
- name: (identifier) @annotation_name
177
- (#match? @annotation_name "Id")))
178
- declarator: (variable_declarator
179
- name: (identifier) @field_name)) @jpa_id_field
180
- """,
181
- # --- Structural Information Extraction Queries ---
182
- "javadoc_comment": """
183
- (block_comment) @javadoc_comment
184
- (#match? @javadoc_comment "^/\\*\\*")
185
- """,
186
- "class_with_javadoc": """
187
- (class_declaration
188
- name: (identifier) @class_name
189
- body: (class_body) @class_body) @class_with_javadoc
190
- """,
191
- "method_with_javadoc": """
192
- (method_declaration
193
- name: (identifier) @method_name
194
- parameters: (formal_parameters) @parameters
195
- body: (block) @method_body) @method_with_javadoc
196
- """,
197
- "field_with_javadoc": """
198
- (field_declaration
199
- type: (_) @field_type
200
- declarator: (variable_declarator
201
- name: (identifier) @field_name)) @field_with_javadoc
202
- """,
203
- "method_parameters_detailed": """
204
- (method_declaration
205
- name: (identifier) @method_name
206
- parameters: (formal_parameters
207
- (formal_parameter
208
- type: (_) @param_type
209
- name: (identifier) @param_name)*) @parameters) @method_parameters_detailed
210
- """,
211
- "class_inheritance_detailed": """
212
- (class_declaration
213
- name: (identifier) @class_name
214
- (superclass
215
- (type_identifier) @extends_class)?
216
- (super_interfaces
217
- (interface_type_list
218
- (type_identifier) @implements_interface)*)?
219
- body: (class_body) @class_body) @class_inheritance_detailed
220
- """,
221
- "annotation_detailed": """
222
- (annotation
223
- name: (identifier) @annotation_name
224
- (annotation_argument_list
225
- (element_value_pair
226
- key: (identifier) @param_key
227
- value: (_) @param_value)*)?
228
- ) @annotation_detailed
229
- """,
230
- "import_detailed": """
231
- (import_declaration
232
- "static"? @static_modifier
233
- (scoped_identifier) @import_path) @import_detailed
234
- """,
235
- "package_detailed": """
236
- (package_declaration
237
- (scoped_identifier) @package_name) @package_detailed
238
- """,
239
- "constructor_detailed": """
240
- (constructor_declaration
241
- name: (identifier) @constructor_name
242
- parameters: (formal_parameters) @parameters
243
- body: (constructor_body) @constructor_body) @constructor_detailed
244
- """,
245
- "enum_constant": """
246
- (enum_declaration
247
- body: (enum_body
248
- (enum_constant
249
- name: (identifier) @constant_name)*)) @enum_constant
250
- """,
251
- "interface_method": """
252
- (interface_declaration
253
- body: (interface_body
254
- (method_declaration
255
- name: (identifier) @method_name
256
- parameters: (formal_parameters) @parameters)*)) @interface_method
257
- """,
258
- }
259
-
260
- # Query descriptions
261
- JAVA_QUERY_DESCRIPTIONS: dict[str, str] = {
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
- }
312
-
313
-
314
- def get_java_query(name: str) -> str:
315
- """
316
- Get the specified Java query
317
-
318
- Args:
319
- name: Query name
320
-
321
- Returns:
322
- Query string
323
-
324
- Raises:
325
- ValueError: When query is not found
326
- """
327
- if name not in JAVA_QUERIES:
328
- available = list(JAVA_QUERIES.keys())
329
- raise ValueError(f"Java query '{name}' does not exist. Available: {available}")
330
-
331
- return JAVA_QUERIES[name]
332
-
333
-
334
- def get_java_query_description(name: str) -> str:
335
- """
336
- Get the description of the specified Java query
337
-
338
- Args:
339
- name: Query name
340
-
341
- Returns:
342
- Query description
343
- """
344
- return JAVA_QUERY_DESCRIPTIONS.get(name, "No description")
345
-
346
-
347
- # Convert to ALL_QUERIES format for dynamic loader compatibility
348
- ALL_QUERIES = {}
349
- for query_name, query_string in JAVA_QUERIES.items():
350
- description = JAVA_QUERY_DESCRIPTIONS.get(query_name, "No description")
351
- ALL_QUERIES[query_name] = {"query": query_string, "description": description}
352
-
353
- # Add common query aliases for cross-language compatibility
354
- ALL_QUERIES["functions"] = {
355
- "query": JAVA_QUERIES["method"],
356
- "description": "Search all function/method declarations (alias for method)",
357
- }
358
-
359
- ALL_QUERIES["classes"] = {
360
- "query": JAVA_QUERIES["class"],
361
- "description": "Search all class declarations (alias for class)",
362
- }
363
-
364
-
365
- def get_query(name: str) -> str:
366
- """Get a specific query by name."""
367
- if name in ALL_QUERIES:
368
- return ALL_QUERIES[name]["query"]
369
- raise ValueError(
370
- f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
371
- )
372
-
373
-
374
- def get_all_queries() -> dict:
375
- """Get all available queries."""
376
- return ALL_QUERIES
377
-
378
-
379
- def list_queries() -> list:
380
- """List all available query names."""
381
- return list(ALL_QUERIES.keys())
382
-
383
-
384
- def get_available_java_queries() -> list[str]:
385
- """
386
- Get list of available Java queries
387
-
388
- Returns:
389
- List of query names
390
- """
391
- return list(JAVA_QUERIES.keys())
1
+ #!/usr/bin/env python3
2
+ """
3
+ Java Language Queries
4
+
5
+ Tree-sitter queries specific to Java language constructs.
6
+ Covers classes, methods, annotations, imports, and other Java-specific elements.
7
+ """
8
+
9
+ # Java-specific query library
10
+ JAVA_QUERIES: dict[str, str] = {
11
+ # --- Basic Structure ---
12
+ "class": """
13
+ (class_declaration) @class
14
+ """,
15
+ "interface": """
16
+ (interface_declaration) @interface
17
+ """,
18
+ "enum": """
19
+ (enum_declaration) @enum
20
+ """,
21
+ "annotation_type": """
22
+ (annotation_type_declaration) @annotation_type
23
+ """,
24
+ # --- Methods and Constructors ---
25
+ "method": """
26
+ (method_declaration) @method
27
+ """,
28
+ "constructor": """
29
+ (constructor_declaration) @constructor
30
+ """,
31
+ "abstract_method": """
32
+ (method_declaration
33
+ (modifiers) @mod
34
+ (#match? @mod "abstract")) @abstract_method
35
+ """,
36
+ # --- Fields and Variables ---
37
+ "field": """
38
+ (field_declaration) @field
39
+ """,
40
+ "static_field": """
41
+ (field_declaration
42
+ (modifiers) @mod
43
+ (#match? @mod "static")) @static_field
44
+ """,
45
+ "final_field": """
46
+ (field_declaration
47
+ (modifiers) @mod
48
+ (#match? @mod "final")) @final_field
49
+ """,
50
+ # --- Imports and Packages ---
51
+ "import": """
52
+ (import_declaration) @import
53
+ """,
54
+ "static_import": """
55
+ (import_declaration
56
+ "static") @static_import
57
+ """,
58
+ "package": """
59
+ (package_declaration) @package
60
+ """,
61
+ # --- Annotations ---
62
+ "annotation": """
63
+ (annotation) @annotation
64
+ """,
65
+ "marker_annotation": """
66
+ (marker_annotation) @marker_annotation
67
+ """,
68
+ "annotation_with_params": """
69
+ (annotation
70
+ (annotation_argument_list)) @annotation_with_params
71
+ """,
72
+ # --- Java-specific Constructs ---
73
+ "lambda": """
74
+ (lambda_expression) @lambda
75
+ """,
76
+ "try_catch": """
77
+ (try_statement) @try_catch
78
+ """,
79
+ "synchronized_block": """
80
+ (synchronized_statement) @synchronized_block
81
+ """,
82
+ "generic_type": """
83
+ (generic_type) @generic_type
84
+ """,
85
+ # --- Name-only Extraction ---
86
+ "class_name": """
87
+ (class_declaration
88
+ name: (identifier) @class_name)
89
+ """,
90
+ "method_name": """
91
+ (method_declaration
92
+ name: (identifier) @method_name)
93
+ """,
94
+ "field_name": """
95
+ (field_declaration
96
+ declarator: (variable_declarator
97
+ name: (identifier) @field_name))
98
+ """,
99
+ # --- Detailed Queries ---
100
+ "class_with_body": """
101
+ (class_declaration
102
+ name: (identifier) @name
103
+ body: (class_body) @body) @class_with_body
104
+ """,
105
+ "method_with_body": """
106
+ (method_declaration
107
+ name: (identifier) @name
108
+ body: (block) @body) @method_with_body
109
+ """,
110
+ "method_with_annotations": """
111
+ (method_declaration
112
+ (modifiers (annotation) @annotation)*
113
+ name: (identifier) @name) @method_with_annotations
114
+ """,
115
+ # --- Inheritance Relations ---
116
+ "extends_clause": """
117
+ (class_declaration
118
+ (superclass) @extends_clause)
119
+ """,
120
+ "implements_clause": """
121
+ (class_declaration
122
+ (super_interfaces) @implements_clause)
123
+ """,
124
+ # --- By Modifiers ---
125
+ "public_methods": """
126
+ (method_declaration
127
+ (modifiers) @mod
128
+ (#match? @mod "public")
129
+ name: (identifier) @name) @public_methods
130
+ """,
131
+ "private_methods": """
132
+ (method_declaration
133
+ (modifiers) @mod
134
+ (#match? @mod "private")
135
+ name: (identifier) @name) @private_methods
136
+ """,
137
+ "static_methods": """
138
+ (method_declaration
139
+ (modifiers) @mod
140
+ (#match? @mod "static")
141
+ name: (identifier) @name) @static_methods
142
+ """,
143
+ # --- Spring Framework Annotations ---
144
+ "spring_controller": """
145
+ (class_declaration
146
+ (modifiers (annotation
147
+ name: (identifier) @annotation_name
148
+ (#match? @annotation_name "Controller|RestController")))
149
+ name: (identifier) @controller_name) @spring_controller
150
+ """,
151
+ "spring_service": """
152
+ (class_declaration
153
+ (modifiers (annotation
154
+ name: (identifier) @annotation_name
155
+ (#match? @annotation_name "Service")))
156
+ name: (identifier) @service_name) @spring_service
157
+ """,
158
+ "spring_repository": """
159
+ (class_declaration
160
+ (modifiers (annotation
161
+ name: (identifier) @annotation_name
162
+ (#match? @annotation_name "Repository")))
163
+ name: (identifier) @repository_name) @spring_repository
164
+ """,
165
+ # --- JPA Annotations ---
166
+ "jpa_entity": """
167
+ (class_declaration
168
+ (modifiers (annotation
169
+ name: (identifier) @annotation_name
170
+ (#match? @annotation_name "Entity")))
171
+ name: (identifier) @entity_name) @jpa_entity
172
+ """,
173
+ "jpa_id_field": """
174
+ (field_declaration
175
+ (modifiers (annotation
176
+ name: (identifier) @annotation_name
177
+ (#match? @annotation_name "Id")))
178
+ declarator: (variable_declarator
179
+ name: (identifier) @field_name)) @jpa_id_field
180
+ """,
181
+ # --- Structural Information Extraction Queries ---
182
+ "javadoc_comment": """
183
+ (block_comment) @javadoc_comment
184
+ (#match? @javadoc_comment "^/\\*\\*")
185
+ """,
186
+ "class_with_javadoc": """
187
+ (class_declaration
188
+ name: (identifier) @class_name
189
+ body: (class_body) @class_body) @class_with_javadoc
190
+ """,
191
+ "method_with_javadoc": """
192
+ (method_declaration
193
+ name: (identifier) @method_name
194
+ parameters: (formal_parameters) @parameters
195
+ body: (block) @method_body) @method_with_javadoc
196
+ """,
197
+ "field_with_javadoc": """
198
+ (field_declaration
199
+ type: (_) @field_type
200
+ declarator: (variable_declarator
201
+ name: (identifier) @field_name)) @field_with_javadoc
202
+ """,
203
+ "method_parameters_detailed": """
204
+ (method_declaration
205
+ name: (identifier) @method_name
206
+ parameters: (formal_parameters
207
+ (formal_parameter
208
+ type: (_) @param_type
209
+ name: (identifier) @param_name)*) @parameters) @method_parameters_detailed
210
+ """,
211
+ "class_inheritance_detailed": """
212
+ (class_declaration
213
+ name: (identifier) @class_name
214
+ (superclass
215
+ (type_identifier) @extends_class)?
216
+ (super_interfaces
217
+ (interface_type_list
218
+ (type_identifier) @implements_interface)*)?
219
+ body: (class_body) @class_body) @class_inheritance_detailed
220
+ """,
221
+ "annotation_detailed": """
222
+ (annotation
223
+ name: (identifier) @annotation_name
224
+ (annotation_argument_list
225
+ (element_value_pair
226
+ key: (identifier) @param_key
227
+ value: (_) @param_value)*)?
228
+ ) @annotation_detailed
229
+ """,
230
+ "import_detailed": """
231
+ (import_declaration
232
+ "static"? @static_modifier
233
+ (scoped_identifier) @import_path) @import_detailed
234
+ """,
235
+ "package_detailed": """
236
+ (package_declaration
237
+ (scoped_identifier) @package_name) @package_detailed
238
+ """,
239
+ "constructor_detailed": """
240
+ (constructor_declaration
241
+ name: (identifier) @constructor_name
242
+ parameters: (formal_parameters) @parameters
243
+ body: (constructor_body) @constructor_body) @constructor_detailed
244
+ """,
245
+ "enum_constant": """
246
+ (enum_declaration
247
+ body: (enum_body
248
+ (enum_constant
249
+ name: (identifier) @constant_name)*)) @enum_constant
250
+ """,
251
+ "interface_method": """
252
+ (interface_declaration
253
+ body: (interface_body
254
+ (method_declaration
255
+ name: (identifier) @method_name
256
+ parameters: (formal_parameters) @parameters)*)) @interface_method
257
+ """,
258
+ }
259
+
260
+ # Query descriptions
261
+ JAVA_QUERY_DESCRIPTIONS: dict[str, str] = {
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
+ }
312
+
313
+
314
+ def get_java_query(name: str) -> str:
315
+ """
316
+ Get the specified Java query
317
+
318
+ Args:
319
+ name: Query name
320
+
321
+ Returns:
322
+ Query string
323
+
324
+ Raises:
325
+ ValueError: When query is not found
326
+ """
327
+ if name not in JAVA_QUERIES:
328
+ available = list(JAVA_QUERIES.keys())
329
+ raise ValueError(f"Java query '{name}' does not exist. Available: {available}")
330
+
331
+ return JAVA_QUERIES[name]
332
+
333
+
334
+ def get_java_query_description(name: str) -> str:
335
+ """
336
+ Get the description of the specified Java query
337
+
338
+ Args:
339
+ name: Query name
340
+
341
+ Returns:
342
+ Query description
343
+ """
344
+ return JAVA_QUERY_DESCRIPTIONS.get(name, "No description")
345
+
346
+
347
+ # Convert to ALL_QUERIES format for dynamic loader compatibility
348
+ ALL_QUERIES = {}
349
+ for query_name, query_string in JAVA_QUERIES.items():
350
+ description = JAVA_QUERY_DESCRIPTIONS.get(query_name, "No description")
351
+ ALL_QUERIES[query_name] = {"query": query_string, "description": description}
352
+
353
+ # Add common query aliases for cross-language compatibility
354
+ ALL_QUERIES["functions"] = {
355
+ "query": JAVA_QUERIES["method"],
356
+ "description": "Search all function/method declarations (alias for method)",
357
+ }
358
+
359
+ ALL_QUERIES["classes"] = {
360
+ "query": JAVA_QUERIES["class"],
361
+ "description": "Search all class declarations (alias for class)",
362
+ }
363
+
364
+
365
+ def get_query(name: str) -> str:
366
+ """Get a specific query by name."""
367
+ if name in ALL_QUERIES:
368
+ return ALL_QUERIES[name]["query"]
369
+ raise ValueError(
370
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
371
+ )
372
+
373
+
374
+ def get_all_queries() -> dict:
375
+ """Get all available queries."""
376
+ return ALL_QUERIES
377
+
378
+
379
+ def list_queries() -> list:
380
+ """List all available query names."""
381
+ return list(ALL_QUERIES.keys())
382
+
383
+
384
+ def get_available_java_queries() -> list[str]:
385
+ """
386
+ Get list of available Java queries
387
+
388
+ Returns:
389
+ List of query names
390
+ """
391
+ return list(JAVA_QUERIES.keys())