@optave/codegraph 3.1.4 → 3.2.0
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.
- package/README.md +29 -72
- package/package.json +10 -8
- package/src/ast-analysis/engine.js +260 -246
- package/src/ast-analysis/shared.js +2 -14
- package/src/ast-analysis/visitors/cfg-visitor.js +635 -649
- package/src/ast-analysis/visitors/complexity-visitor.js +135 -139
- package/src/ast-analysis/visitors/dataflow-visitor.js +230 -224
- package/src/cli/commands/ast.js +4 -7
- package/src/cli/commands/audit.js +11 -11
- package/src/cli/commands/batch.js +6 -5
- package/src/cli/commands/branch-compare.js +1 -1
- package/src/cli/commands/brief.js +12 -0
- package/src/cli/commands/build.js +1 -1
- package/src/cli/commands/cfg.js +5 -8
- package/src/cli/commands/check.js +28 -36
- package/src/cli/commands/children.js +9 -7
- package/src/cli/commands/co-change.js +5 -3
- package/src/cli/commands/communities.js +2 -6
- package/src/cli/commands/complexity.js +5 -3
- package/src/cli/commands/context.js +9 -8
- package/src/cli/commands/cycles.js +12 -8
- package/src/cli/commands/dataflow.js +5 -8
- package/src/cli/commands/deps.js +9 -8
- package/src/cli/commands/diff-impact.js +2 -6
- package/src/cli/commands/embed.js +1 -1
- package/src/cli/commands/export.js +34 -31
- package/src/cli/commands/exports.js +2 -6
- package/src/cli/commands/flow.js +5 -8
- package/src/cli/commands/fn-impact.js +9 -8
- package/src/cli/commands/impact.js +2 -6
- package/src/cli/commands/info.js +2 -2
- package/src/cli/commands/map.js +1 -1
- package/src/cli/commands/mcp.js +1 -1
- package/src/cli/commands/models.js +1 -1
- package/src/cli/commands/owners.js +5 -3
- package/src/cli/commands/path.js +2 -2
- package/src/cli/commands/plot.js +40 -31
- package/src/cli/commands/query.js +9 -8
- package/src/cli/commands/registry.js +2 -2
- package/src/cli/commands/roles.js +5 -8
- package/src/cli/commands/search.js +9 -3
- package/src/cli/commands/sequence.js +5 -8
- package/src/cli/commands/snapshot.js +6 -1
- package/src/cli/commands/stats.js +1 -1
- package/src/cli/commands/structure.js +5 -4
- package/src/cli/commands/triage.js +41 -30
- package/src/cli/commands/watch.js +1 -1
- package/src/cli/commands/where.js +2 -6
- package/src/cli/index.js +11 -5
- package/src/cli/shared/open-graph.js +13 -0
- package/src/cli/shared/options.js +22 -2
- package/src/cli.js +1 -1
- package/src/db/connection.js +140 -11
- package/src/{db.js → db/index.js} +12 -5
- package/src/db/migrations.js +42 -65
- package/src/db/query-builder.js +72 -9
- package/src/db/repository/base.js +1 -1
- package/src/db/repository/graph-read.js +3 -3
- package/src/db/repository/in-memory-repository.js +30 -28
- package/src/db/repository/nodes.js +10 -17
- package/src/domain/analysis/brief.js +155 -0
- package/src/domain/analysis/context.js +392 -0
- package/src/domain/analysis/dependencies.js +395 -0
- package/src/{analysis → domain/analysis}/exports.js +11 -6
- package/src/domain/analysis/impact.js +581 -0
- package/src/domain/analysis/module-map.js +348 -0
- package/src/{analysis → domain/analysis}/roles.js +12 -9
- package/src/{analysis → domain/analysis}/symbol-lookup.js +19 -11
- package/src/{builder → domain/graph/builder}/helpers.js +4 -4
- package/src/{builder → domain/graph/builder}/incremental.js +119 -93
- package/src/domain/graph/builder/pipeline.js +156 -0
- package/src/domain/graph/builder/stages/build-edges.js +376 -0
- package/src/{builder → domain/graph/builder}/stages/build-structure.js +4 -4
- package/src/{builder → domain/graph/builder}/stages/collect-files.js +2 -2
- package/src/{builder → domain/graph/builder}/stages/detect-changes.js +204 -183
- package/src/{builder → domain/graph/builder}/stages/finalize.js +4 -4
- package/src/domain/graph/builder/stages/insert-nodes.js +203 -0
- package/src/{builder → domain/graph/builder}/stages/parse-files.js +2 -2
- package/src/{builder → domain/graph/builder}/stages/resolve-imports.js +1 -1
- package/src/{builder → domain/graph/builder}/stages/run-analyses.js +2 -2
- package/src/{change-journal.js → domain/graph/change-journal.js} +1 -1
- package/src/{cycles.js → domain/graph/cycles.js} +4 -4
- package/src/{journal.js → domain/graph/journal.js} +1 -1
- package/src/{resolve.js → domain/graph/resolve.js} +2 -2
- package/src/{watcher.js → domain/graph/watcher.js} +7 -7
- package/src/{parser.js → domain/parser.js} +24 -15
- package/src/{queries.js → domain/queries.js} +17 -16
- package/src/{embeddings → domain/search}/generator.js +3 -3
- package/src/{embeddings → domain/search}/models.js +2 -2
- package/src/{embeddings → domain/search}/search/cli-formatter.js +1 -1
- package/src/{embeddings → domain/search}/search/filters.js +9 -5
- package/src/{embeddings → domain/search}/search/hybrid.js +1 -1
- package/src/{embeddings → domain/search}/search/keyword.js +13 -6
- package/src/{embeddings → domain/search}/search/prepare.js +15 -7
- package/src/{embeddings → domain/search}/search/semantic.js +1 -1
- package/src/{embeddings → domain/search}/strategies/structured.js +1 -1
- package/src/extractors/csharp.js +224 -207
- package/src/extractors/go.js +176 -172
- package/src/extractors/hcl.js +94 -78
- package/src/extractors/java.js +213 -207
- package/src/extractors/javascript.js +275 -305
- package/src/extractors/php.js +234 -221
- package/src/extractors/python.js +252 -250
- package/src/extractors/ruby.js +192 -185
- package/src/extractors/rust.js +182 -167
- package/src/{ast.js → features/ast.js} +13 -11
- package/src/{audit.js → features/audit.js} +20 -46
- package/src/{batch.js → features/batch.js} +5 -5
- package/src/{boundaries.js → features/boundaries.js} +100 -85
- package/src/{branch-compare.js → features/branch-compare.js} +3 -3
- package/src/{cfg.js → features/cfg.js} +141 -150
- package/src/{check.js → features/check.js} +13 -30
- package/src/{cochange.js → features/cochange.js} +5 -5
- package/src/{communities.js → features/communities.js} +72 -57
- package/src/{complexity.js → features/complexity.js} +154 -143
- package/src/{dataflow.js → features/dataflow.js} +155 -158
- package/src/{export.js → features/export.js} +6 -6
- package/src/{flow.js → features/flow.js} +4 -4
- package/src/{viewer.js → features/graph-enrichment.js} +8 -8
- package/src/{manifesto.js → features/manifesto.js} +15 -12
- package/src/{owners.js → features/owners.js} +6 -5
- package/src/features/sequence.js +300 -0
- package/src/features/shared/find-nodes.js +31 -0
- package/src/{snapshot.js → features/snapshot.js} +3 -3
- package/src/{structure.js → features/structure.js} +139 -108
- package/src/features/triage.js +141 -0
- package/src/graph/builders/dependency.js +33 -14
- package/src/graph/classifiers/risk.js +3 -2
- package/src/graph/classifiers/roles.js +6 -3
- package/src/index.cjs +16 -0
- package/src/index.js +40 -39
- package/src/{native.js → infrastructure/native.js} +1 -1
- package/src/mcp/middleware.js +1 -1
- package/src/mcp/server.js +68 -59
- package/src/mcp/tool-registry.js +15 -2
- package/src/mcp/tools/ast-query.js +1 -1
- package/src/mcp/tools/audit.js +1 -1
- package/src/mcp/tools/batch-query.js +1 -1
- package/src/mcp/tools/branch-compare.js +3 -1
- package/src/mcp/tools/brief.js +8 -0
- package/src/mcp/tools/cfg.js +1 -1
- package/src/mcp/tools/check.js +3 -3
- package/src/mcp/tools/co-changes.js +1 -1
- package/src/mcp/tools/code-owners.js +1 -1
- package/src/mcp/tools/communities.js +1 -1
- package/src/mcp/tools/complexity.js +1 -1
- package/src/mcp/tools/dataflow.js +2 -2
- package/src/mcp/tools/execution-flow.js +2 -2
- package/src/mcp/tools/export-graph.js +2 -2
- package/src/mcp/tools/find-cycles.js +2 -2
- package/src/mcp/tools/index.js +2 -0
- package/src/mcp/tools/list-repos.js +1 -1
- package/src/mcp/tools/sequence.js +1 -1
- package/src/mcp/tools/structure.js +1 -1
- package/src/mcp/tools/triage.js +2 -2
- package/src/{commands → presentation}/audit.js +2 -2
- package/src/{commands → presentation}/batch.js +1 -1
- package/src/{commands → presentation}/branch-compare.js +2 -2
- package/src/presentation/brief.js +51 -0
- package/src/{commands → presentation}/cfg.js +1 -1
- package/src/{commands → presentation}/check.js +2 -2
- package/src/{commands → presentation}/communities.js +1 -1
- package/src/{commands → presentation}/complexity.js +1 -1
- package/src/{commands → presentation}/dataflow.js +1 -1
- package/src/{commands → presentation}/flow.js +2 -2
- package/src/{commands → presentation}/manifesto.js +1 -1
- package/src/{commands → presentation}/owners.js +1 -1
- package/src/presentation/queries-cli/exports.js +53 -0
- package/src/presentation/queries-cli/impact.js +214 -0
- package/src/presentation/queries-cli/index.js +5 -0
- package/src/presentation/queries-cli/inspect.js +329 -0
- package/src/presentation/queries-cli/overview.js +196 -0
- package/src/presentation/queries-cli/path.js +65 -0
- package/src/presentation/queries-cli.js +27 -0
- package/src/{commands → presentation}/query.js +1 -1
- package/src/presentation/result-formatter.js +126 -3
- package/src/{commands → presentation}/sequence.js +2 -2
- package/src/{commands → presentation}/structure.js +1 -1
- package/src/presentation/table.js +0 -8
- package/src/{commands → presentation}/triage.js +1 -1
- package/src/{constants.js → shared/constants.js} +1 -1
- package/src/shared/file-utils.js +2 -2
- package/src/shared/generators.js +9 -5
- package/src/shared/hierarchy.js +1 -1
- package/src/{kinds.js → shared/kinds.js} +1 -1
- package/src/analysis/context.js +0 -408
- package/src/analysis/dependencies.js +0 -341
- package/src/analysis/impact.js +0 -463
- package/src/analysis/module-map.js +0 -322
- package/src/builder/pipeline.js +0 -130
- package/src/builder/stages/build-edges.js +0 -297
- package/src/builder/stages/insert-nodes.js +0 -195
- package/src/mcp.js +0 -2
- package/src/queries-cli.js +0 -866
- package/src/sequence.js +0 -289
- package/src/triage.js +0 -126
- /package/src/{builder → domain/graph/builder}/context.js +0 -0
- /package/src/{builder.js → domain/graph/builder.js} +0 -0
- /package/src/{embeddings → domain/search}/index.js +0 -0
- /package/src/{embeddings → domain/search}/stores/fts5.js +0 -0
- /package/src/{embeddings → domain/search}/stores/sqlite-blob.js +0 -0
- /package/src/{embeddings → domain/search}/strategies/source.js +0 -0
- /package/src/{embeddings → domain/search}/strategies/text-utils.js +0 -0
- /package/src/{config.js → infrastructure/config.js} +0 -0
- /package/src/{logger.js → infrastructure/logger.js} +0 -0
- /package/src/{registry.js → infrastructure/registry.js} +0 -0
- /package/src/{update-check.js → infrastructure/update-check.js} +0 -0
- /package/src/{commands → presentation}/cochange.js +0 -0
- /package/src/{errors.js → shared/errors.js} +0 -0
- /package/src/{paginate.js → shared/paginate.js} +0 -0
package/src/extractors/java.js
CHANGED
|
@@ -4,239 +4,245 @@ import { extractModifierVisibility, findChild, nodeEndLine } from './helpers.js'
|
|
|
4
4
|
* Extract symbols from Java files.
|
|
5
5
|
*/
|
|
6
6
|
export function extractJavaSymbols(tree, _filePath) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const ctx = {
|
|
8
|
+
definitions: [],
|
|
9
|
+
calls: [],
|
|
10
|
+
imports: [],
|
|
11
|
+
classes: [],
|
|
12
|
+
exports: [],
|
|
13
|
+
};
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
walkJavaNode(tree.rootNode, ctx);
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function walkJavaNode(node, ctx) {
|
|
20
|
+
switch (node.type) {
|
|
21
|
+
case 'class_declaration':
|
|
22
|
+
handleJavaClassDecl(node, ctx);
|
|
23
|
+
break;
|
|
24
|
+
case 'interface_declaration':
|
|
25
|
+
handleJavaInterfaceDecl(node, ctx);
|
|
26
|
+
break;
|
|
27
|
+
case 'enum_declaration':
|
|
28
|
+
handleJavaEnumDecl(node, ctx);
|
|
29
|
+
break;
|
|
30
|
+
case 'method_declaration':
|
|
31
|
+
handleJavaMethodDecl(node, ctx);
|
|
32
|
+
break;
|
|
33
|
+
case 'constructor_declaration':
|
|
34
|
+
handleJavaConstructorDecl(node, ctx);
|
|
35
|
+
break;
|
|
36
|
+
case 'import_declaration':
|
|
37
|
+
handleJavaImportDecl(node, ctx);
|
|
38
|
+
break;
|
|
39
|
+
case 'method_invocation':
|
|
40
|
+
handleJavaMethodInvocation(node, ctx);
|
|
41
|
+
break;
|
|
42
|
+
case 'object_creation_expression':
|
|
43
|
+
handleJavaObjectCreation(node, ctx);
|
|
44
|
+
break;
|
|
27
45
|
}
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case 'class_declaration': {
|
|
32
|
-
const nameNode = node.childForFieldName('name');
|
|
33
|
-
if (nameNode) {
|
|
34
|
-
const classChildren = extractClassFields(node);
|
|
35
|
-
definitions.push({
|
|
36
|
-
name: nameNode.text,
|
|
37
|
-
kind: 'class',
|
|
38
|
-
line: node.startPosition.row + 1,
|
|
39
|
-
endLine: nodeEndLine(node),
|
|
40
|
-
children: classChildren.length > 0 ? classChildren : undefined,
|
|
41
|
-
});
|
|
47
|
+
for (let i = 0; i < node.childCount; i++) walkJavaNode(node.child(i), ctx);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
if (superclass) {
|
|
45
|
-
for (let i = 0; i < superclass.childCount; i++) {
|
|
46
|
-
const child = superclass.child(i);
|
|
47
|
-
if (
|
|
48
|
-
child &&
|
|
49
|
-
(child.type === 'type_identifier' ||
|
|
50
|
-
child.type === 'identifier' ||
|
|
51
|
-
child.type === 'generic_type')
|
|
52
|
-
) {
|
|
53
|
-
const superName = child.type === 'generic_type' ? child.child(0)?.text : child.text;
|
|
54
|
-
if (superName)
|
|
55
|
-
classes.push({
|
|
56
|
-
name: nameNode.text,
|
|
57
|
-
extends: superName,
|
|
58
|
-
line: node.startPosition.row + 1,
|
|
59
|
-
});
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
50
|
+
// ── Walk-path per-node-type handlers ────────────────────────────────────────
|
|
64
51
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (child.type === 'type_list') {
|
|
77
|
-
for (let j = 0; j < child.childCount; j++) {
|
|
78
|
-
const t = child.child(j);
|
|
79
|
-
if (
|
|
80
|
-
t &&
|
|
81
|
-
(t.type === 'type_identifier' ||
|
|
82
|
-
t.type === 'identifier' ||
|
|
83
|
-
t.type === 'generic_type')
|
|
84
|
-
) {
|
|
85
|
-
const ifaceName = t.type === 'generic_type' ? t.child(0)?.text : t.text;
|
|
86
|
-
if (ifaceName)
|
|
87
|
-
classes.push({
|
|
88
|
-
name: nameNode.text,
|
|
89
|
-
implements: ifaceName,
|
|
90
|
-
line: node.startPosition.row + 1,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
const ifaceName =
|
|
96
|
-
child.type === 'generic_type' ? child.child(0)?.text : child.text;
|
|
97
|
-
if (ifaceName)
|
|
98
|
-
classes.push({
|
|
99
|
-
name: nameNode.text,
|
|
100
|
-
implements: ifaceName,
|
|
101
|
-
line: node.startPosition.row + 1,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
52
|
+
function handleJavaClassDecl(node, ctx) {
|
|
53
|
+
const nameNode = node.childForFieldName('name');
|
|
54
|
+
if (!nameNode) return;
|
|
55
|
+
const classChildren = extractClassFields(node);
|
|
56
|
+
ctx.definitions.push({
|
|
57
|
+
name: nameNode.text,
|
|
58
|
+
kind: 'class',
|
|
59
|
+
line: node.startPosition.row + 1,
|
|
60
|
+
endLine: nodeEndLine(node),
|
|
61
|
+
children: classChildren.length > 0 ? classChildren : undefined,
|
|
62
|
+
});
|
|
110
63
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
64
|
+
const superclass = node.childForFieldName('superclass');
|
|
65
|
+
if (superclass) {
|
|
66
|
+
for (let i = 0; i < superclass.childCount; i++) {
|
|
67
|
+
const child = superclass.child(i);
|
|
68
|
+
if (
|
|
69
|
+
child &&
|
|
70
|
+
(child.type === 'type_identifier' ||
|
|
71
|
+
child.type === 'identifier' ||
|
|
72
|
+
child.type === 'generic_type')
|
|
73
|
+
) {
|
|
74
|
+
const superName = child.type === 'generic_type' ? child.child(0)?.text : child.text;
|
|
75
|
+
if (superName)
|
|
76
|
+
ctx.classes.push({
|
|
115
77
|
name: nameNode.text,
|
|
116
|
-
|
|
78
|
+
extends: superName,
|
|
117
79
|
line: node.startPosition.row + 1,
|
|
118
|
-
endLine: nodeEndLine(node),
|
|
119
80
|
});
|
|
120
|
-
const body = node.childForFieldName('body');
|
|
121
|
-
if (body) {
|
|
122
|
-
for (let i = 0; i < body.childCount; i++) {
|
|
123
|
-
const child = body.child(i);
|
|
124
|
-
if (child && child.type === 'method_declaration') {
|
|
125
|
-
const methName = child.childForFieldName('name');
|
|
126
|
-
if (methName) {
|
|
127
|
-
definitions.push({
|
|
128
|
-
name: `${nameNode.text}.${methName.text}`,
|
|
129
|
-
kind: 'method',
|
|
130
|
-
line: child.startPosition.row + 1,
|
|
131
|
-
endLine: child.endPosition.row + 1,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
81
|
break;
|
|
139
82
|
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
140
85
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
name: nameNode.text,
|
|
147
|
-
kind: 'enum',
|
|
148
|
-
line: node.startPosition.row + 1,
|
|
149
|
-
endLine: nodeEndLine(node),
|
|
150
|
-
children: enumChildren.length > 0 ? enumChildren : undefined,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
86
|
+
const interfaces = node.childForFieldName('interfaces');
|
|
87
|
+
if (interfaces) {
|
|
88
|
+
extractJavaInterfaces(interfaces, nameNode.text, node.startPosition.row + 1, ctx);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
155
91
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
92
|
+
function extractJavaInterfaces(interfaces, className, line, ctx) {
|
|
93
|
+
for (let i = 0; i < interfaces.childCount; i++) {
|
|
94
|
+
const child = interfaces.child(i);
|
|
95
|
+
if (
|
|
96
|
+
child &&
|
|
97
|
+
(child.type === 'type_identifier' ||
|
|
98
|
+
child.type === 'identifier' ||
|
|
99
|
+
child.type === 'type_list' ||
|
|
100
|
+
child.type === 'generic_type')
|
|
101
|
+
) {
|
|
102
|
+
if (child.type === 'type_list') {
|
|
103
|
+
for (let j = 0; j < child.childCount; j++) {
|
|
104
|
+
const t = child.child(j);
|
|
105
|
+
if (
|
|
106
|
+
t &&
|
|
107
|
+
(t.type === 'type_identifier' || t.type === 'identifier' || t.type === 'generic_type')
|
|
108
|
+
) {
|
|
109
|
+
const ifaceName = t.type === 'generic_type' ? t.child(0)?.text : t.text;
|
|
110
|
+
if (ifaceName) ctx.classes.push({ name: className, implements: ifaceName, line });
|
|
111
|
+
}
|
|
170
112
|
}
|
|
171
|
-
|
|
113
|
+
} else {
|
|
114
|
+
const ifaceName = child.type === 'generic_type' ? child.child(0)?.text : child.text;
|
|
115
|
+
if (ifaceName) ctx.classes.push({ name: className, implements: ifaceName, line });
|
|
172
116
|
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
173
120
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
121
|
+
function handleJavaInterfaceDecl(node, ctx) {
|
|
122
|
+
const nameNode = node.childForFieldName('name');
|
|
123
|
+
if (!nameNode) return;
|
|
124
|
+
ctx.definitions.push({
|
|
125
|
+
name: nameNode.text,
|
|
126
|
+
kind: 'interface',
|
|
127
|
+
line: node.startPosition.row + 1,
|
|
128
|
+
endLine: nodeEndLine(node),
|
|
129
|
+
});
|
|
130
|
+
const body = node.childForFieldName('body');
|
|
131
|
+
if (body) {
|
|
132
|
+
for (let i = 0; i < body.childCount; i++) {
|
|
133
|
+
const child = body.child(i);
|
|
134
|
+
if (child && child.type === 'method_declaration') {
|
|
135
|
+
const methName = child.childForFieldName('name');
|
|
136
|
+
if (methName) {
|
|
137
|
+
ctx.definitions.push({
|
|
138
|
+
name: `${nameNode.text}.${methName.text}`,
|
|
182
139
|
kind: 'method',
|
|
183
|
-
line:
|
|
184
|
-
endLine:
|
|
185
|
-
children: params.length > 0 ? params : undefined,
|
|
186
|
-
visibility: extractModifierVisibility(node),
|
|
140
|
+
line: child.startPosition.row + 1,
|
|
141
|
+
endLine: child.endPosition.row + 1,
|
|
187
142
|
});
|
|
188
143
|
}
|
|
189
|
-
break;
|
|
190
144
|
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
191
148
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
if (child && child.type === 'asterisk') {
|
|
206
|
-
const lastImport = imports[imports.length - 1];
|
|
207
|
-
if (lastImport) lastImport.names = ['*'];
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
149
|
+
function handleJavaEnumDecl(node, ctx) {
|
|
150
|
+
const nameNode = node.childForFieldName('name');
|
|
151
|
+
if (!nameNode) return;
|
|
152
|
+
const enumChildren = extractEnumConstants(node);
|
|
153
|
+
ctx.definitions.push({
|
|
154
|
+
name: nameNode.text,
|
|
155
|
+
kind: 'enum',
|
|
156
|
+
line: node.startPosition.row + 1,
|
|
157
|
+
endLine: nodeEndLine(node),
|
|
158
|
+
children: enumChildren.length > 0 ? enumChildren : undefined,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
212
161
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
162
|
+
function handleJavaMethodDecl(node, ctx) {
|
|
163
|
+
// Skip interface methods already emitted by handleJavaInterfaceDecl
|
|
164
|
+
if (node.parent?.parent?.type === 'interface_declaration') return;
|
|
165
|
+
const nameNode = node.childForFieldName('name');
|
|
166
|
+
if (!nameNode) return;
|
|
167
|
+
const parentClass = findJavaParentClass(node);
|
|
168
|
+
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
169
|
+
const params = extractJavaParameters(node.childForFieldName('parameters'));
|
|
170
|
+
ctx.definitions.push({
|
|
171
|
+
name: fullName,
|
|
172
|
+
kind: 'method',
|
|
173
|
+
line: node.startPosition.row + 1,
|
|
174
|
+
endLine: nodeEndLine(node),
|
|
175
|
+
children: params.length > 0 ? params : undefined,
|
|
176
|
+
visibility: extractModifierVisibility(node),
|
|
177
|
+
});
|
|
178
|
+
}
|
|
223
179
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
180
|
+
function handleJavaConstructorDecl(node, ctx) {
|
|
181
|
+
const nameNode = node.childForFieldName('name');
|
|
182
|
+
if (!nameNode) return;
|
|
183
|
+
const parentClass = findJavaParentClass(node);
|
|
184
|
+
const fullName = parentClass ? `${parentClass}.${nameNode.text}` : nameNode.text;
|
|
185
|
+
const params = extractJavaParameters(node.childForFieldName('parameters'));
|
|
186
|
+
ctx.definitions.push({
|
|
187
|
+
name: fullName,
|
|
188
|
+
kind: 'method',
|
|
189
|
+
line: node.startPosition.row + 1,
|
|
190
|
+
endLine: nodeEndLine(node),
|
|
191
|
+
children: params.length > 0 ? params : undefined,
|
|
192
|
+
visibility: extractModifierVisibility(node),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
234
195
|
|
|
235
|
-
|
|
196
|
+
function handleJavaImportDecl(node, ctx) {
|
|
197
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
198
|
+
const child = node.child(i);
|
|
199
|
+
if (child && (child.type === 'scoped_identifier' || child.type === 'identifier')) {
|
|
200
|
+
const fullPath = child.text;
|
|
201
|
+
const lastName = fullPath.split('.').pop();
|
|
202
|
+
ctx.imports.push({
|
|
203
|
+
source: fullPath,
|
|
204
|
+
names: [lastName],
|
|
205
|
+
line: node.startPosition.row + 1,
|
|
206
|
+
javaImport: true,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (child && child.type === 'asterisk') {
|
|
210
|
+
const lastImport = ctx.imports[ctx.imports.length - 1];
|
|
211
|
+
if (lastImport) lastImport.names = ['*'];
|
|
212
|
+
}
|
|
236
213
|
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function handleJavaMethodInvocation(node, ctx) {
|
|
217
|
+
const nameNode = node.childForFieldName('name');
|
|
218
|
+
if (!nameNode) return;
|
|
219
|
+
const obj = node.childForFieldName('object');
|
|
220
|
+
const call = { name: nameNode.text, line: node.startPosition.row + 1 };
|
|
221
|
+
if (obj) call.receiver = obj.text;
|
|
222
|
+
ctx.calls.push(call);
|
|
223
|
+
}
|
|
237
224
|
|
|
238
|
-
|
|
239
|
-
|
|
225
|
+
function handleJavaObjectCreation(node, ctx) {
|
|
226
|
+
const typeNode = node.childForFieldName('type');
|
|
227
|
+
if (!typeNode) return;
|
|
228
|
+
const typeName = typeNode.type === 'generic_type' ? typeNode.child(0)?.text : typeNode.text;
|
|
229
|
+
if (typeName) ctx.calls.push({ name: typeName, line: node.startPosition.row + 1 });
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function findJavaParentClass(node) {
|
|
233
|
+
let current = node.parent;
|
|
234
|
+
while (current) {
|
|
235
|
+
if (
|
|
236
|
+
current.type === 'class_declaration' ||
|
|
237
|
+
current.type === 'enum_declaration' ||
|
|
238
|
+
current.type === 'interface_declaration'
|
|
239
|
+
) {
|
|
240
|
+
const nameNode = current.childForFieldName('name');
|
|
241
|
+
return nameNode ? nameNode.text : null;
|
|
242
|
+
}
|
|
243
|
+
current = current.parent;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
240
246
|
}
|
|
241
247
|
|
|
242
248
|
// ── Child extraction helpers ────────────────────────────────────────────────
|