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

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

Potentially problematic release.


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

Files changed (78) hide show
  1. tree_sitter_analyzer/__init__.py +133 -121
  2. tree_sitter_analyzer/__main__.py +11 -12
  3. tree_sitter_analyzer/api.py +531 -539
  4. tree_sitter_analyzer/cli/__init__.py +39 -39
  5. tree_sitter_analyzer/cli/__main__.py +12 -13
  6. tree_sitter_analyzer/cli/commands/__init__.py +26 -27
  7. tree_sitter_analyzer/cli/commands/advanced_command.py +88 -88
  8. tree_sitter_analyzer/cli/commands/base_command.py +160 -155
  9. tree_sitter_analyzer/cli/commands/default_command.py +18 -19
  10. tree_sitter_analyzer/cli/commands/partial_read_command.py +141 -133
  11. tree_sitter_analyzer/cli/commands/query_command.py +81 -82
  12. tree_sitter_analyzer/cli/commands/structure_command.py +138 -121
  13. tree_sitter_analyzer/cli/commands/summary_command.py +101 -93
  14. tree_sitter_analyzer/cli/commands/table_command.py +232 -233
  15. tree_sitter_analyzer/cli/info_commands.py +120 -121
  16. tree_sitter_analyzer/cli_main.py +277 -276
  17. tree_sitter_analyzer/core/__init__.py +15 -20
  18. tree_sitter_analyzer/core/analysis_engine.py +591 -574
  19. tree_sitter_analyzer/core/cache_service.py +320 -330
  20. tree_sitter_analyzer/core/engine.py +557 -560
  21. tree_sitter_analyzer/core/parser.py +293 -288
  22. tree_sitter_analyzer/core/query.py +494 -502
  23. tree_sitter_analyzer/encoding_utils.py +458 -460
  24. tree_sitter_analyzer/exceptions.py +337 -340
  25. tree_sitter_analyzer/file_handler.py +217 -222
  26. tree_sitter_analyzer/formatters/__init__.py +1 -1
  27. tree_sitter_analyzer/formatters/base_formatter.py +167 -168
  28. tree_sitter_analyzer/formatters/formatter_factory.py +78 -74
  29. tree_sitter_analyzer/formatters/java_formatter.py +287 -270
  30. tree_sitter_analyzer/formatters/python_formatter.py +255 -235
  31. tree_sitter_analyzer/interfaces/__init__.py +9 -10
  32. tree_sitter_analyzer/interfaces/cli.py +528 -557
  33. tree_sitter_analyzer/interfaces/cli_adapter.py +322 -319
  34. tree_sitter_analyzer/interfaces/mcp_adapter.py +180 -170
  35. tree_sitter_analyzer/interfaces/mcp_server.py +405 -416
  36. tree_sitter_analyzer/java_analyzer.py +218 -219
  37. tree_sitter_analyzer/language_detector.py +398 -400
  38. tree_sitter_analyzer/language_loader.py +224 -228
  39. tree_sitter_analyzer/languages/__init__.py +10 -11
  40. tree_sitter_analyzer/languages/java_plugin.py +1129 -1113
  41. tree_sitter_analyzer/languages/python_plugin.py +737 -712
  42. tree_sitter_analyzer/mcp/__init__.py +31 -32
  43. tree_sitter_analyzer/mcp/resources/__init__.py +44 -47
  44. tree_sitter_analyzer/mcp/resources/code_file_resource.py +212 -213
  45. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +560 -550
  46. tree_sitter_analyzer/mcp/server.py +333 -345
  47. tree_sitter_analyzer/mcp/tools/__init__.py +30 -31
  48. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +621 -557
  49. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +242 -245
  50. tree_sitter_analyzer/mcp/tools/base_tool.py +54 -55
  51. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +300 -302
  52. tree_sitter_analyzer/mcp/tools/table_format_tool.py +362 -359
  53. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +543 -476
  54. tree_sitter_analyzer/mcp/utils/__init__.py +105 -106
  55. tree_sitter_analyzer/mcp/utils/error_handler.py +549 -549
  56. tree_sitter_analyzer/models.py +470 -481
  57. tree_sitter_analyzer/output_manager.py +261 -264
  58. tree_sitter_analyzer/plugins/__init__.py +333 -334
  59. tree_sitter_analyzer/plugins/base.py +477 -446
  60. tree_sitter_analyzer/plugins/java_plugin.py +608 -625
  61. tree_sitter_analyzer/plugins/javascript_plugin.py +446 -439
  62. tree_sitter_analyzer/plugins/manager.py +362 -355
  63. tree_sitter_analyzer/plugins/plugin_loader.py +85 -83
  64. tree_sitter_analyzer/plugins/python_plugin.py +606 -598
  65. tree_sitter_analyzer/plugins/registry.py +374 -366
  66. tree_sitter_analyzer/queries/__init__.py +26 -27
  67. tree_sitter_analyzer/queries/java.py +391 -394
  68. tree_sitter_analyzer/queries/javascript.py +148 -149
  69. tree_sitter_analyzer/queries/python.py +285 -286
  70. tree_sitter_analyzer/queries/typescript.py +229 -230
  71. tree_sitter_analyzer/query_loader.py +254 -260
  72. tree_sitter_analyzer/table_formatter.py +468 -448
  73. tree_sitter_analyzer/utils.py +277 -277
  74. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/METADATA +21 -6
  75. tree_sitter_analyzer-0.3.0.dist-info/RECORD +77 -0
  76. tree_sitter_analyzer-0.2.0.dist-info/RECORD +0 -77
  77. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/WHEEL +0 -0
  78. {tree_sitter_analyzer-0.2.0.dist-info → tree_sitter_analyzer-0.3.0.dist-info}/entry_points.txt +0 -0
@@ -1,394 +1,391 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- Java Language Queries
5
-
6
- Tree-sitter queries specific to Java language constructs.
7
- Covers classes, methods, annotations, imports, and other Java-specific elements.
8
- """
9
-
10
- from typing import Dict
11
-
12
- # Java専用クエリライブラリ
13
- JAVA_QUERIES: Dict[str, str] = {
14
- # --- 基本構造 ---
15
- "class": """
16
- (class_declaration) @class
17
- """,
18
- "interface": """
19
- (interface_declaration) @interface
20
- """,
21
- "enum": """
22
- (enum_declaration) @enum
23
- """,
24
- "annotation_type": """
25
- (annotation_type_declaration) @annotation_type
26
- """,
27
- # --- メソッドと構築子 ---
28
- "method": """
29
- (method_declaration) @method
30
- """,
31
- "constructor": """
32
- (constructor_declaration) @constructor
33
- """,
34
- "abstract_method": """
35
- (method_declaration
36
- (modifiers) @mod
37
- (#match? @mod "abstract")) @abstract_method
38
- """,
39
- # --- フィールドと変数 ---
40
- "field": """
41
- (field_declaration) @field
42
- """,
43
- "static_field": """
44
- (field_declaration
45
- (modifiers) @mod
46
- (#match? @mod "static")) @static_field
47
- """,
48
- "final_field": """
49
- (field_declaration
50
- (modifiers) @mod
51
- (#match? @mod "final")) @final_field
52
- """,
53
- # --- インポートとパッケージ ---
54
- "import": """
55
- (import_declaration) @import
56
- """,
57
- "static_import": """
58
- (import_declaration
59
- "static") @static_import
60
- """,
61
- "package": """
62
- (package_declaration) @package
63
- """,
64
- # --- アノテーション ---
65
- "annotation": """
66
- (annotation) @annotation
67
- """,
68
- "marker_annotation": """
69
- (marker_annotation) @marker_annotation
70
- """,
71
- "annotation_with_params": """
72
- (annotation
73
- (annotation_argument_list)) @annotation_with_params
74
- """,
75
- # --- Java特有のコンストラクト ---
76
- "lambda": """
77
- (lambda_expression) @lambda
78
- """,
79
- "try_catch": """
80
- (try_statement) @try_catch
81
- """,
82
- "synchronized_block": """
83
- (synchronized_statement) @synchronized_block
84
- """,
85
- "generic_type": """
86
- (generic_type) @generic_type
87
- """,
88
- # --- 名前のみ抽出 ---
89
- "class_name": """
90
- (class_declaration
91
- name: (identifier) @class_name)
92
- """,
93
- "method_name": """
94
- (method_declaration
95
- name: (identifier) @method_name)
96
- """,
97
- "field_name": """
98
- (field_declaration
99
- declarator: (variable_declarator
100
- name: (identifier) @field_name))
101
- """,
102
- # --- 詳細付きクエリ ---
103
- "class_with_body": """
104
- (class_declaration
105
- name: (identifier) @name
106
- body: (class_body) @body) @class_with_body
107
- """,
108
- "method_with_body": """
109
- (method_declaration
110
- name: (identifier) @name
111
- body: (block) @body) @method_with_body
112
- """,
113
- "method_with_annotations": """
114
- (method_declaration
115
- (modifiers (annotation) @annotation)*
116
- name: (identifier) @name) @method_with_annotations
117
- """,
118
- # --- 継承関係 ---
119
- "extends_clause": """
120
- (class_declaration
121
- (superclass) @extends_clause)
122
- """,
123
- "implements_clause": """
124
- (class_declaration
125
- (super_interfaces) @implements_clause)
126
- """,
127
- # --- 修飾子別 ---
128
- "public_methods": """
129
- (method_declaration
130
- (modifiers) @mod
131
- (#match? @mod "public")
132
- name: (identifier) @name) @public_methods
133
- """,
134
- "private_methods": """
135
- (method_declaration
136
- (modifiers) @mod
137
- (#match? @mod "private")
138
- name: (identifier) @name) @private_methods
139
- """,
140
- "static_methods": """
141
- (method_declaration
142
- (modifiers) @mod
143
- (#match? @mod "static")
144
- name: (identifier) @name) @static_methods
145
- """,
146
- # --- Spring Framework アノテーション ---
147
- "spring_controller": """
148
- (class_declaration
149
- (modifiers (annotation
150
- name: (identifier) @annotation_name
151
- (#match? @annotation_name "Controller|RestController")))
152
- name: (identifier) @controller_name) @spring_controller
153
- """,
154
- "spring_service": """
155
- (class_declaration
156
- (modifiers (annotation
157
- name: (identifier) @annotation_name
158
- (#match? @annotation_name "Service")))
159
- name: (identifier) @service_name) @spring_service
160
- """,
161
- "spring_repository": """
162
- (class_declaration
163
- (modifiers (annotation
164
- name: (identifier) @annotation_name
165
- (#match? @annotation_name "Repository")))
166
- name: (identifier) @repository_name) @spring_repository
167
- """,
168
- # --- JPA アノテーション ---
169
- "jpa_entity": """
170
- (class_declaration
171
- (modifiers (annotation
172
- name: (identifier) @annotation_name
173
- (#match? @annotation_name "Entity")))
174
- name: (identifier) @entity_name) @jpa_entity
175
- """,
176
- "jpa_id_field": """
177
- (field_declaration
178
- (modifiers (annotation
179
- name: (identifier) @annotation_name
180
- (#match? @annotation_name "Id")))
181
- declarator: (variable_declarator
182
- name: (identifier) @field_name)) @jpa_id_field
183
- """,
184
- # --- 構造情報抽出用クエリ ---
185
- "javadoc_comment": """
186
- (block_comment) @javadoc_comment
187
- (#match? @javadoc_comment "^/\\*\\*")
188
- """,
189
- "class_with_javadoc": """
190
- (class_declaration
191
- name: (identifier) @class_name
192
- body: (class_body) @class_body) @class_with_javadoc
193
- """,
194
- "method_with_javadoc": """
195
- (method_declaration
196
- name: (identifier) @method_name
197
- parameters: (formal_parameters) @parameters
198
- body: (block) @method_body) @method_with_javadoc
199
- """,
200
- "field_with_javadoc": """
201
- (field_declaration
202
- type: (_) @field_type
203
- declarator: (variable_declarator
204
- name: (identifier) @field_name)) @field_with_javadoc
205
- """,
206
- "method_parameters_detailed": """
207
- (method_declaration
208
- name: (identifier) @method_name
209
- parameters: (formal_parameters
210
- (formal_parameter
211
- type: (_) @param_type
212
- name: (identifier) @param_name)*) @parameters) @method_parameters_detailed
213
- """,
214
- "class_inheritance_detailed": """
215
- (class_declaration
216
- name: (identifier) @class_name
217
- (superclass
218
- (type_identifier) @extends_class)?
219
- (super_interfaces
220
- (interface_type_list
221
- (type_identifier) @implements_interface)*)?
222
- body: (class_body) @class_body) @class_inheritance_detailed
223
- """,
224
- "annotation_detailed": """
225
- (annotation
226
- name: (identifier) @annotation_name
227
- (annotation_argument_list
228
- (element_value_pair
229
- key: (identifier) @param_key
230
- value: (_) @param_value)*)?
231
- ) @annotation_detailed
232
- """,
233
- "import_detailed": """
234
- (import_declaration
235
- "static"? @static_modifier
236
- (scoped_identifier) @import_path) @import_detailed
237
- """,
238
- "package_detailed": """
239
- (package_declaration
240
- (scoped_identifier) @package_name) @package_detailed
241
- """,
242
- "constructor_detailed": """
243
- (constructor_declaration
244
- name: (identifier) @constructor_name
245
- parameters: (formal_parameters) @parameters
246
- body: (constructor_body) @constructor_body) @constructor_detailed
247
- """,
248
- "enum_constant": """
249
- (enum_declaration
250
- body: (enum_body
251
- (enum_constant
252
- name: (identifier) @constant_name)*)) @enum_constant
253
- """,
254
- "interface_method": """
255
- (interface_declaration
256
- body: (interface_body
257
- (method_declaration
258
- name: (identifier) @method_name
259
- parameters: (formal_parameters) @parameters)*)) @interface_method
260
- """,
261
- }
262
-
263
- # クエリの説明
264
- JAVA_QUERY_DESCRIPTIONS: Dict[str, str] = {
265
- "class": "Javaクラス宣言を抽出",
266
- "interface": "Javaインターフェース宣言を抽出",
267
- "enum": "Java列挙型宣言を抽出",
268
- "annotation_type": "Javaアノテーション型宣言を抽出",
269
- "method": "Javaメソッド宣言を抽出",
270
- "constructor": "Javaコンストラクタ宣言を抽出",
271
- "field": "Javaフィールド宣言を抽出",
272
- "import": "Javaインポート文を抽出",
273
- "package": "Javaパッケージ宣言を抽出",
274
- "annotation": "Javaアノテーションを抽出",
275
- "lambda": "Javaラムダ式を抽出",
276
- "try_catch": "Java try-catch文を抽出",
277
- "class_name": "クラス名のみを抽出",
278
- "method_name": "メソッド名のみを抽出",
279
- "field_name": "フィールド名のみを抽出",
280
- "class_with_body": "クラス宣言と本体を抽出",
281
- "method_with_body": "メソッド宣言と本体を抽出",
282
- "extends_clause": "クラスの継承句を抽出",
283
- "implements_clause": "クラスの実装句を抽出",
284
- "public_methods": "publicメソッドを抽出",
285
- "private_methods": "privateメソッドを抽出",
286
- "static_methods": "staticメソッドを抽出",
287
- # 構造情報抽出用クエリの説明
288
- "javadoc_comment": "JavaDocコメントを抽出",
289
- "class_with_javadoc": "JavaDoc付きクラスを抽出",
290
- "method_with_javadoc": "JavaDoc付きメソッドを抽出",
291
- "field_with_javadoc": "JavaDoc付きフィールドを抽出",
292
- "method_parameters_detailed": "メソッドパラメータの詳細情報を抽出",
293
- "class_inheritance_detailed": "クラスの継承関係詳細を抽出",
294
- "annotation_detailed": "アノテーションの詳細情報を抽出",
295
- "import_detailed": "インポート文の詳細情報を抽出",
296
- "package_detailed": "パッケージ宣言の詳細情報を抽出",
297
- "constructor_detailed": "コンストラクタの詳細情報を抽出",
298
- "enum_constant": "列挙型定数を抽出",
299
- "interface_method": "インターフェースメソッドを抽出",
300
- "spring_controller": "Spring Controllerクラスを抽出",
301
- "spring_service": "Spring Serviceクラスを抽出",
302
- "spring_repository": "Spring Repositoryクラスを抽出",
303
- "jpa_entity": "JPA Entityクラスを抽出",
304
- "abstract_method": "抽象メソッドを抽出",
305
- "static_field": "静的フィールドを抽出",
306
- "final_field": "finalフィールドを抽出",
307
- "static_import": "静的インポート文を抽出",
308
- "marker_annotation": "マーカーアノテーションを抽出",
309
- "annotation_with_params": "パラメータ付きアノテーションを抽出",
310
- "synchronized_block": "synchronized文を抽出",
311
- "generic_type": "ジェネリック型を抽出",
312
- "method_with_annotations": "アノテーション付きメソッドを抽出",
313
- "jpa_id_field": "JPA IDフィールドを抽出",
314
- }
315
-
316
-
317
- def get_java_query(name: str) -> str:
318
- """
319
- 指定されたJavaクエリを取得
320
-
321
- Args:
322
- name: クエリ名
323
-
324
- Returns:
325
- クエリ文字列
326
-
327
- Raises:
328
- ValueError: クエリが見つからない場合
329
- """
330
- if name not in JAVA_QUERIES:
331
- available = list(JAVA_QUERIES.keys())
332
- raise ValueError(f"Javaクエリ '{name}' は存在しません。利用可能: {available}")
333
-
334
- return JAVA_QUERIES[name]
335
-
336
-
337
- def get_java_query_description(name: str) -> str:
338
- """
339
- 指定されたJavaクエリの説明を取得
340
-
341
- Args:
342
- name: クエリ名
343
-
344
- Returns:
345
- クエリの説明
346
- """
347
- return JAVA_QUERY_DESCRIPTIONS.get(name, "説明なし")
348
-
349
-
350
- # Convert to ALL_QUERIES format for dynamic loader compatibility
351
- ALL_QUERIES = {}
352
- for query_name, query_string in JAVA_QUERIES.items():
353
- description = JAVA_QUERY_DESCRIPTIONS.get(query_name, "説明なし")
354
- ALL_QUERIES[query_name] = {"query": query_string, "description": description}
355
-
356
- # Add common query aliases for cross-language compatibility
357
- ALL_QUERIES["functions"] = {
358
- "query": JAVA_QUERIES["method"],
359
- "description": "すべての関数/メソッド宣言を検索(methodのエイリアス)",
360
- }
361
-
362
- ALL_QUERIES["classes"] = {
363
- "query": JAVA_QUERIES["class"],
364
- "description": "すべてのクラス宣言を検索(classのエイリアス)",
365
- }
366
-
367
-
368
- def get_query(name: str) -> str:
369
- """Get a specific query by name."""
370
- if name in ALL_QUERIES:
371
- return ALL_QUERIES[name]["query"]
372
- raise ValueError(
373
- f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
374
- )
375
-
376
-
377
- def get_all_queries() -> dict:
378
- """Get all available queries."""
379
- return ALL_QUERIES
380
-
381
-
382
- def list_queries() -> list:
383
- """List all available query names."""
384
- return list(ALL_QUERIES.keys())
385
-
386
-
387
- def get_available_java_queries() -> list[str]:
388
- """
389
- 利用可能なJavaクエリ一覧を取得
390
-
391
- Returns:
392
- クエリ名のリスト
393
- """
394
- 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専用クエリライブラリ
10
+ JAVA_QUERIES: dict[str, str] = {
11
+ # --- 基本構造 ---
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
+ # --- メソッドと構築子 ---
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
+ # --- フィールドと変数 ---
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
+ # --- インポートとパッケージ ---
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
+ # --- アノテーション ---
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特有のコンストラクト ---
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
+ # --- 名前のみ抽出 ---
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
+ # --- 詳細付きクエリ ---
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
+ # --- 継承関係 ---
116
+ "extends_clause": """
117
+ (class_declaration
118
+ (superclass) @extends_clause)
119
+ """,
120
+ "implements_clause": """
121
+ (class_declaration
122
+ (super_interfaces) @implements_clause)
123
+ """,
124
+ # --- 修飾子別 ---
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 アノテーション ---
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 アノテーション ---
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
+ # --- 構造情報抽出用クエリ ---
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
+ # クエリの説明
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フィールドを抽出",
311
+ }
312
+
313
+
314
+ def get_java_query(name: str) -> str:
315
+ """
316
+ 指定されたJavaクエリを取得
317
+
318
+ Args:
319
+ name: クエリ名
320
+
321
+ Returns:
322
+ クエリ文字列
323
+
324
+ Raises:
325
+ ValueError: クエリが見つからない場合
326
+ """
327
+ if name not in JAVA_QUERIES:
328
+ available = list(JAVA_QUERIES.keys())
329
+ raise ValueError(f"Javaクエリ '{name}' は存在しません。利用可能: {available}")
330
+
331
+ return JAVA_QUERIES[name]
332
+
333
+
334
+ def get_java_query_description(name: str) -> str:
335
+ """
336
+ 指定されたJavaクエリの説明を取得
337
+
338
+ Args:
339
+ name: クエリ名
340
+
341
+ Returns:
342
+ クエリの説明
343
+ """
344
+ return JAVA_QUERY_DESCRIPTIONS.get(name, "説明なし")
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, "説明なし")
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": "すべての関数/メソッド宣言を検索(methodのエイリアス)",
357
+ }
358
+
359
+ ALL_QUERIES["classes"] = {
360
+ "query": JAVA_QUERIES["class"],
361
+ "description": "すべてのクラス宣言を検索(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
+ 利用可能なJavaクエリ一覧を取得
387
+
388
+ Returns:
389
+ クエリ名のリスト
390
+ """
391
+ return list(JAVA_QUERIES.keys())