@aiready/core 0.24.22 → 0.24.25
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/dist/chunk-3GCIM6XG.mjs +904 -0
- package/dist/chunk-3S5WU6KX.mjs +552 -0
- package/dist/chunk-4OMXBYX7.mjs +167 -0
- package/dist/chunk-6YWGFKZG.mjs +250 -0
- package/dist/chunk-A3BIROBZ.mjs +902 -0
- package/dist/chunk-BYMQDORS.mjs +256 -0
- package/dist/chunk-CBZNRNEF.mjs +309 -0
- package/dist/chunk-ET2WRQSM.mjs +262 -0
- package/dist/chunk-F4FTHFHK.mjs +552 -0
- package/dist/chunk-G737F72Q.mjs +256 -0
- package/dist/chunk-GVFUAIWU.mjs +864 -0
- package/dist/chunk-KSEA5XDH.mjs +894 -0
- package/dist/chunk-LMIZRJFV.mjs +256 -0
- package/dist/chunk-LRPBPWBM.mjs +170 -0
- package/dist/chunk-MOTBXU6W.mjs +902 -0
- package/dist/chunk-OAH6FVVF.mjs +919 -0
- package/dist/chunk-OCM6HLBM.mjs +262 -0
- package/dist/chunk-OFBRNGKT.mjs +893 -0
- package/dist/chunk-P3KYGPO4.mjs +262 -0
- package/dist/chunk-PNWSO6XQ.mjs +250 -0
- package/dist/chunk-SO6UKAPR.mjs +164 -0
- package/dist/chunk-T2FW6AAF.mjs +552 -0
- package/dist/chunk-TQX77RIC.mjs +250 -0
- package/dist/chunk-X64EJ3ZO.mjs +314 -0
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +32 -5
- package/dist/client/index.mjs +1 -1
- package/dist/csharp-parser-3CGM6FKB.mjs +9 -0
- package/dist/csharp-parser-UWRUYHUH.mjs +9 -0
- package/dist/csharp-parser-WIAIE3DD.mjs +9 -0
- package/dist/go-parser-AH5QNS4O.mjs +9 -0
- package/dist/go-parser-CSAB23BL.mjs +9 -0
- package/dist/go-parser-Q3HI32B7.mjs +9 -0
- package/dist/index-CL_0jxiJ.d.mts +1315 -0
- package/dist/index-CL_0jxiJ.d.ts +1315 -0
- package/dist/index-ClwnZa_Y.d.mts +1333 -0
- package/dist/index-ClwnZa_Y.d.ts +1333 -0
- package/dist/index-DC0cdf0g.d.mts +1321 -0
- package/dist/index-DC0cdf0g.d.ts +1321 -0
- package/dist/index-DKqKGhcJ.d.mts +1309 -0
- package/dist/index-DKqKGhcJ.d.ts +1309 -0
- package/dist/index-DNnlhdk0.d.mts +1318 -0
- package/dist/index-DNnlhdk0.d.ts +1318 -0
- package/dist/index-De2xy_k5.d.mts +1326 -0
- package/dist/index-De2xy_k5.d.ts +1326 -0
- package/dist/index.d.mts +104 -20
- package/dist/index.d.ts +104 -20
- package/dist/index.js +581 -147
- package/dist/index.mjs +507 -134
- package/dist/java-parser-GUKWCEYS.mjs +9 -0
- package/dist/java-parser-XTWT5Y5I.mjs +9 -0
- package/dist/java-parser-YP5XWLQK.mjs +9 -0
- package/dist/python-parser-AOPXUEIV.mjs +8 -0
- package/dist/python-parser-FB55P6UA.mjs +8 -0
- package/dist/python-parser-WIJPSRKC.mjs +8 -0
- package/dist/typescript-parser-5ZWLLMWJ.mjs +7 -0
- package/dist/typescript-parser-TWPRLYK6.mjs +7 -0
- package/package.json +5 -1
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeGeneralMetadata,
|
|
3
|
+
extractParameterNames
|
|
4
|
+
} from "./chunk-3D3I5K5W.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseLanguageParser
|
|
7
|
+
} from "./chunk-SO6UKAPR.mjs";
|
|
8
|
+
|
|
9
|
+
// src/parsers/go-parser.ts
|
|
10
|
+
var GoParser = class extends BaseLanguageParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.language = "go" /* Go */;
|
|
14
|
+
this.extensions = [".go"];
|
|
15
|
+
}
|
|
16
|
+
getParserName() {
|
|
17
|
+
return "go";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze metadata for a Go node (purity, side effects).
|
|
21
|
+
*
|
|
22
|
+
* @param node - Tree-sitter node to analyze.
|
|
23
|
+
* @param code - Source code for context.
|
|
24
|
+
* @returns Partial ExportInfo containing discovered metadata.
|
|
25
|
+
*/
|
|
26
|
+
analyzeMetadata(node, code) {
|
|
27
|
+
return analyzeGeneralMetadata(node, code, {
|
|
28
|
+
sideEffectSignatures: ["<-", "fmt.Print", "fmt.Fprintf", "os.Exit"]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fallback regex-based parsing when tree-sitter is unavailable.
|
|
33
|
+
*
|
|
34
|
+
* @param code - Source code content.
|
|
35
|
+
* @returns Consolidated ParseResult.
|
|
36
|
+
*/
|
|
37
|
+
parseRegex(code) {
|
|
38
|
+
const lines = code.split("\n");
|
|
39
|
+
const exports = [];
|
|
40
|
+
const imports = [];
|
|
41
|
+
const importRegex = /^import\s+"([^"]+)"/;
|
|
42
|
+
const funcRegex = /^func\s+([A-Z][a-zA-Z0-9_]*)\s*\(/;
|
|
43
|
+
const typeRegex = /^type\s+([A-Z][a-zA-Z0-9_]*)\s+(struct|interface)/;
|
|
44
|
+
lines.forEach((line, idx) => {
|
|
45
|
+
const importMatch = line.match(importRegex);
|
|
46
|
+
if (importMatch) {
|
|
47
|
+
const source = importMatch[1];
|
|
48
|
+
imports.push({
|
|
49
|
+
source,
|
|
50
|
+
specifiers: [source.split("/").pop() || source],
|
|
51
|
+
loc: {
|
|
52
|
+
start: { line: idx + 1, column: 0 },
|
|
53
|
+
end: { line: idx + 1, column: line.length }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const funcMatch = line.match(funcRegex);
|
|
58
|
+
if (funcMatch) {
|
|
59
|
+
const name = funcMatch[1];
|
|
60
|
+
const isPublic = /^[A-Z]/.test(name);
|
|
61
|
+
let docContent;
|
|
62
|
+
const prevLines = lines.slice(Math.max(0, idx - 3), idx);
|
|
63
|
+
for (let i = prevLines.length - 1; i >= 0; i--) {
|
|
64
|
+
const prevLine = prevLines[i].trim();
|
|
65
|
+
if (prevLine.startsWith("//")) {
|
|
66
|
+
const content = prevLine.slice(2).trim();
|
|
67
|
+
docContent = docContent ? content + "\n" + docContent : content;
|
|
68
|
+
} else if (prevLine.endsWith("*/")) {
|
|
69
|
+
const blockMatch = prevLine.match(/\/\*([\s\S]*)\*\//);
|
|
70
|
+
if (blockMatch) docContent = blockMatch[1].trim();
|
|
71
|
+
break;
|
|
72
|
+
} else if (!prevLine) {
|
|
73
|
+
if (docContent) break;
|
|
74
|
+
} else {
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes("fmt.Print");
|
|
79
|
+
exports.push({
|
|
80
|
+
name,
|
|
81
|
+
type: "function",
|
|
82
|
+
visibility: isPublic ? "public" : "private",
|
|
83
|
+
isPure: !isImpure,
|
|
84
|
+
hasSideEffects: isImpure,
|
|
85
|
+
documentation: docContent ? { content: docContent, type: "comment" } : void 0,
|
|
86
|
+
loc: {
|
|
87
|
+
start: { line: idx + 1, column: 0 },
|
|
88
|
+
end: { line: idx + 1, column: line.length }
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const typeMatch = line.match(typeRegex);
|
|
93
|
+
if (typeMatch) {
|
|
94
|
+
exports.push({
|
|
95
|
+
name: typeMatch[1],
|
|
96
|
+
type: typeMatch[2] === "struct" ? "class" : "interface",
|
|
97
|
+
visibility: "public",
|
|
98
|
+
isPure: true,
|
|
99
|
+
hasSideEffects: false,
|
|
100
|
+
loc: {
|
|
101
|
+
start: { line: idx + 1, column: 0 },
|
|
102
|
+
end: { line: idx + 1, column: line.length }
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
exports,
|
|
109
|
+
imports,
|
|
110
|
+
language: "go" /* Go */,
|
|
111
|
+
warnings: ["Parser falling back to regex-based analysis"]
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Extract import information using AST walk.
|
|
116
|
+
*
|
|
117
|
+
* @param rootNode - Root node of the Go AST.
|
|
118
|
+
* @returns Array of discovered FileImport objects.
|
|
119
|
+
*/
|
|
120
|
+
extractImportsAST(rootNode) {
|
|
121
|
+
const imports = [];
|
|
122
|
+
const findImports = (node) => {
|
|
123
|
+
if (node.type === "import_spec") {
|
|
124
|
+
const pathNode = node.children.find(
|
|
125
|
+
(c) => c.type === "interpreted_string_literal"
|
|
126
|
+
);
|
|
127
|
+
if (pathNode) {
|
|
128
|
+
const source = pathNode.text.replace(/"/g, "");
|
|
129
|
+
imports.push({
|
|
130
|
+
source,
|
|
131
|
+
specifiers: [source.split("/").pop() || source],
|
|
132
|
+
loc: {
|
|
133
|
+
start: {
|
|
134
|
+
line: node.startPosition.row + 1,
|
|
135
|
+
column: node.startPosition.column
|
|
136
|
+
},
|
|
137
|
+
end: {
|
|
138
|
+
line: node.endPosition.row + 1,
|
|
139
|
+
column: node.endPosition.column
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
146
|
+
const child = node.child(i);
|
|
147
|
+
if (child) findImports(child);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
findImports(rootNode);
|
|
151
|
+
return imports;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Extract export information (functions, types, vars) using AST walk.
|
|
155
|
+
*
|
|
156
|
+
* @param rootNode - Root node of the Go AST.
|
|
157
|
+
* @param code - Source code for documentation extraction.
|
|
158
|
+
* @returns Array of discovered ExportInfo objects.
|
|
159
|
+
*/
|
|
160
|
+
extractExportsAST(rootNode, code) {
|
|
161
|
+
const exports = [];
|
|
162
|
+
const isExported = (name) => {
|
|
163
|
+
return /^[A-Z]/.test(name);
|
|
164
|
+
};
|
|
165
|
+
const traverse = (node) => {
|
|
166
|
+
if (node.type === "function_declaration" || node.type === "method_declaration") {
|
|
167
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "identifier");
|
|
168
|
+
if (nameNode && isExported(nameNode.text)) {
|
|
169
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
170
|
+
exports.push({
|
|
171
|
+
name: nameNode.text,
|
|
172
|
+
type: "function",
|
|
173
|
+
loc: {
|
|
174
|
+
start: {
|
|
175
|
+
line: node.startPosition.row + 1,
|
|
176
|
+
column: node.startPosition.column
|
|
177
|
+
},
|
|
178
|
+
end: {
|
|
179
|
+
line: node.endPosition.row + 1,
|
|
180
|
+
column: node.endPosition.column
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
visibility: "public",
|
|
184
|
+
parameters: this.extractParameters(node),
|
|
185
|
+
...metadata
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
} else if (node.type === "type_spec") {
|
|
189
|
+
const nameNode = node.childForFieldName("name") || node.children.find((c) => c.type === "type_identifier");
|
|
190
|
+
if (nameNode && isExported(nameNode.text)) {
|
|
191
|
+
const metadata = this.analyzeMetadata(node.parent || node, code);
|
|
192
|
+
const type = node.children.some((c) => c.type === "struct_type") ? "class" : "interface";
|
|
193
|
+
exports.push({
|
|
194
|
+
name: nameNode.text,
|
|
195
|
+
type,
|
|
196
|
+
loc: {
|
|
197
|
+
start: {
|
|
198
|
+
line: node.startPosition.row + 1,
|
|
199
|
+
column: node.startPosition.column
|
|
200
|
+
},
|
|
201
|
+
end: {
|
|
202
|
+
line: node.endPosition.row + 1,
|
|
203
|
+
column: node.endPosition.column
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
visibility: "public",
|
|
207
|
+
...metadata
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
} else if (node.type === "var_spec" || node.type === "const_spec") {
|
|
211
|
+
const identifiers = node.children.filter(
|
|
212
|
+
(c) => c.type === "identifier"
|
|
213
|
+
);
|
|
214
|
+
for (const idNode of identifiers) {
|
|
215
|
+
if (isExported(idNode.text)) {
|
|
216
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
217
|
+
exports.push({
|
|
218
|
+
name: idNode.text,
|
|
219
|
+
type: "variable",
|
|
220
|
+
loc: {
|
|
221
|
+
start: {
|
|
222
|
+
line: idNode.startPosition.row + 1,
|
|
223
|
+
column: idNode.startPosition.column
|
|
224
|
+
},
|
|
225
|
+
end: {
|
|
226
|
+
line: idNode.endPosition.row + 1,
|
|
227
|
+
column: idNode.endPosition.column
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
visibility: "public",
|
|
231
|
+
...metadata
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
237
|
+
const child = node.child(i);
|
|
238
|
+
if (child) traverse(child);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
traverse(rootNode);
|
|
242
|
+
return exports;
|
|
243
|
+
}
|
|
244
|
+
extractParameters(node) {
|
|
245
|
+
return extractParameterNames(node);
|
|
246
|
+
}
|
|
247
|
+
getNamingConventions() {
|
|
248
|
+
return {
|
|
249
|
+
variablePattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
250
|
+
functionPattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
251
|
+
classPattern: /^[a-zA-Z][a-zA-Z0-9]*$/,
|
|
252
|
+
constantPattern: /^[a-zA-Z_][a-zA-Z0-9_]*$/
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
canHandle(filePath) {
|
|
256
|
+
return filePath.toLowerCase().endsWith(".go");
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
export {
|
|
261
|
+
GoParser
|
|
262
|
+
};
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import {
|
|
2
|
+
analyzeGeneralMetadata,
|
|
3
|
+
extractParameterNames
|
|
4
|
+
} from "./chunk-3D3I5K5W.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseLanguageParser
|
|
7
|
+
} from "./chunk-SO6UKAPR.mjs";
|
|
8
|
+
|
|
9
|
+
// src/parsers/java-parser.ts
|
|
10
|
+
var JavaParser = class extends BaseLanguageParser {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.language = "java" /* Java */;
|
|
14
|
+
this.extensions = [".java"];
|
|
15
|
+
}
|
|
16
|
+
getParserName() {
|
|
17
|
+
return "java";
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Analyze metadata for a Java node (purity, side effects).
|
|
21
|
+
*
|
|
22
|
+
* @param node - Tree-sitter node to analyze.
|
|
23
|
+
* @param code - Source code for context.
|
|
24
|
+
* @returns Partial ExportInfo containing discovered metadata.
|
|
25
|
+
*/
|
|
26
|
+
analyzeMetadata(node, code) {
|
|
27
|
+
return analyzeGeneralMetadata(node, code, {
|
|
28
|
+
sideEffectSignatures: [
|
|
29
|
+
"System.out",
|
|
30
|
+
"System.err",
|
|
31
|
+
"Files.write",
|
|
32
|
+
"Logging."
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
parseRegex(code) {
|
|
37
|
+
const lines = code.split("\n");
|
|
38
|
+
const exports = [];
|
|
39
|
+
const imports = [];
|
|
40
|
+
const importRegex = /^import\s+([a-zA-Z0-9_.]+)/;
|
|
41
|
+
const classRegex = /^\s*(?:public\s+)?(?:class|interface|enum)\s+([a-zA-Z0-9_]+)/;
|
|
42
|
+
const methodRegex = /^\s*public\s+(?:static\s+)?[a-zA-Z0-9_<>[\]]+\s+([a-zA-Z0-9_]+)\s*\(/;
|
|
43
|
+
let currentClassName = "";
|
|
44
|
+
lines.forEach((line, idx) => {
|
|
45
|
+
const importMatch = line.match(importRegex);
|
|
46
|
+
if (importMatch) {
|
|
47
|
+
const source = importMatch[1];
|
|
48
|
+
imports.push({
|
|
49
|
+
source,
|
|
50
|
+
specifiers: [source.split(".").pop() || source],
|
|
51
|
+
loc: {
|
|
52
|
+
start: { line: idx + 1, column: 0 },
|
|
53
|
+
end: { line: idx + 1, column: line.length }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const classMatch = line.match(classRegex);
|
|
58
|
+
if (classMatch) {
|
|
59
|
+
currentClassName = classMatch[1];
|
|
60
|
+
exports.push({
|
|
61
|
+
name: currentClassName,
|
|
62
|
+
type: line.includes("interface") ? "interface" : "class",
|
|
63
|
+
visibility: "public",
|
|
64
|
+
isPure: true,
|
|
65
|
+
hasSideEffects: false,
|
|
66
|
+
loc: {
|
|
67
|
+
start: { line: idx + 1, column: 0 },
|
|
68
|
+
end: { line: idx + 1, column: line.length }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const methodMatch = line.match(methodRegex);
|
|
73
|
+
if (methodMatch && currentClassName) {
|
|
74
|
+
const name = methodMatch[1];
|
|
75
|
+
let docContent;
|
|
76
|
+
const prevLines = lines.slice(Math.max(0, idx - 5), idx);
|
|
77
|
+
const prevText = prevLines.join("\n");
|
|
78
|
+
const javadocMatch = prevText.match(/\/\*\*([\s\S]*?)\*\/\s*$/);
|
|
79
|
+
if (javadocMatch) {
|
|
80
|
+
docContent = javadocMatch[1].replace(/^\s*\*+/gm, "").trim();
|
|
81
|
+
}
|
|
82
|
+
const isImpure = name.toLowerCase().includes("impure") || line.includes("System.out");
|
|
83
|
+
exports.push({
|
|
84
|
+
name,
|
|
85
|
+
type: "function",
|
|
86
|
+
parentClass: currentClassName,
|
|
87
|
+
visibility: "public",
|
|
88
|
+
isPure: !isImpure,
|
|
89
|
+
hasSideEffects: isImpure,
|
|
90
|
+
documentation: docContent ? { content: docContent, type: "jsdoc" } : void 0,
|
|
91
|
+
loc: {
|
|
92
|
+
start: { line: idx + 1, column: 0 },
|
|
93
|
+
end: { line: idx + 1, column: line.length }
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
exports,
|
|
100
|
+
imports,
|
|
101
|
+
language: "java" /* Java */,
|
|
102
|
+
warnings: ["Parser falling back to regex-based analysis"]
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Extract import information using AST walk.
|
|
107
|
+
*
|
|
108
|
+
* @param rootNode - Root node of the Java AST.
|
|
109
|
+
* @returns Array of discovered FileImport objects.
|
|
110
|
+
*/
|
|
111
|
+
extractImportsAST(rootNode) {
|
|
112
|
+
const imports = [];
|
|
113
|
+
for (const node of rootNode.children) {
|
|
114
|
+
if (node.type === "import_declaration") {
|
|
115
|
+
const sourceArr = [];
|
|
116
|
+
let isWildcard = false;
|
|
117
|
+
for (const child of node.children) {
|
|
118
|
+
if (child.type === "scoped_identifier" || child.type === "identifier") {
|
|
119
|
+
sourceArr.push(child.text);
|
|
120
|
+
}
|
|
121
|
+
if (child.type === "asterisk") isWildcard = true;
|
|
122
|
+
}
|
|
123
|
+
const source = sourceArr.join(".");
|
|
124
|
+
if (source) {
|
|
125
|
+
imports.push({
|
|
126
|
+
source: isWildcard ? `${source}.*` : source,
|
|
127
|
+
specifiers: isWildcard ? ["*"] : [source.split(".").pop() || source],
|
|
128
|
+
loc: {
|
|
129
|
+
start: {
|
|
130
|
+
line: node.startPosition.row + 1,
|
|
131
|
+
column: node.startPosition.column
|
|
132
|
+
},
|
|
133
|
+
end: {
|
|
134
|
+
line: node.endPosition.row + 1,
|
|
135
|
+
column: node.endPosition.column
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return imports;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Extract export information (classes, interfaces, methods) using AST walk.
|
|
146
|
+
*
|
|
147
|
+
* @param rootNode - Root node of the Java AST.
|
|
148
|
+
* @param code - Source code for documentation extraction.
|
|
149
|
+
* @returns Array of discovered ExportInfo objects.
|
|
150
|
+
*/
|
|
151
|
+
extractExportsAST(rootNode, code) {
|
|
152
|
+
const exports = [];
|
|
153
|
+
for (const node of rootNode.children) {
|
|
154
|
+
if (node.type === "class_declaration" || node.type === "interface_declaration" || node.type === "enum_declaration") {
|
|
155
|
+
const nameNode = node.children.find((c) => c.type === "identifier");
|
|
156
|
+
if (nameNode) {
|
|
157
|
+
const modifiers = this.getModifiers(node);
|
|
158
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
159
|
+
exports.push({
|
|
160
|
+
name: nameNode.text,
|
|
161
|
+
type: node.type === "class_declaration" ? "class" : "interface",
|
|
162
|
+
loc: {
|
|
163
|
+
start: {
|
|
164
|
+
line: node.startPosition.row + 1,
|
|
165
|
+
column: node.startPosition.column
|
|
166
|
+
},
|
|
167
|
+
end: {
|
|
168
|
+
line: node.endPosition.row + 1,
|
|
169
|
+
column: node.endPosition.column
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
visibility: modifiers.includes("public") ? "public" : "private",
|
|
173
|
+
...metadata
|
|
174
|
+
});
|
|
175
|
+
this.extractSubExports(node, nameNode.text, exports, code);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return exports;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Extract modifiers (visibility, static, etc.) from a node.
|
|
183
|
+
*
|
|
184
|
+
* @param node - AST node to extract modifiers from.
|
|
185
|
+
* @returns Array of modifier strings.
|
|
186
|
+
*/
|
|
187
|
+
getModifiers(node) {
|
|
188
|
+
const modifiersNode = node.children.find((c) => c.type === "modifiers");
|
|
189
|
+
if (!modifiersNode) return [];
|
|
190
|
+
return modifiersNode.children.map((c) => c.text);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Extract methods and nested exports from a class or interface body.
|
|
194
|
+
*
|
|
195
|
+
* @param parentNode - Class or interface declaration node.
|
|
196
|
+
* @param parentName - Name of the parent class/interface.
|
|
197
|
+
* @param exports - Array to collect discovered exports into.
|
|
198
|
+
* @param code - Source code for context.
|
|
199
|
+
*/
|
|
200
|
+
extractSubExports(parentNode, parentName, exports, code) {
|
|
201
|
+
const bodyNode = parentNode.children.find((c) => c.type === "class_body");
|
|
202
|
+
if (!bodyNode) return;
|
|
203
|
+
for (const node of bodyNode.children) {
|
|
204
|
+
if (node.type === "method_declaration") {
|
|
205
|
+
const nameNode = node.children.find((c) => c.type === "identifier");
|
|
206
|
+
const modifiers = this.getModifiers(node);
|
|
207
|
+
if (nameNode && modifiers.includes("public")) {
|
|
208
|
+
const metadata = this.analyzeMetadata(node, code);
|
|
209
|
+
exports.push({
|
|
210
|
+
name: nameNode.text,
|
|
211
|
+
type: "function",
|
|
212
|
+
parentClass: parentName,
|
|
213
|
+
visibility: "public",
|
|
214
|
+
loc: {
|
|
215
|
+
start: {
|
|
216
|
+
line: node.startPosition.row + 1,
|
|
217
|
+
column: node.startPosition.column
|
|
218
|
+
},
|
|
219
|
+
end: {
|
|
220
|
+
line: node.endPosition.row + 1,
|
|
221
|
+
column: node.endPosition.column
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
parameters: this.extractParameters(node),
|
|
225
|
+
...metadata
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
extractParameters(node) {
|
|
232
|
+
return extractParameterNames(node);
|
|
233
|
+
}
|
|
234
|
+
getNamingConventions() {
|
|
235
|
+
return {
|
|
236
|
+
variablePattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
237
|
+
functionPattern: /^[a-z][a-zA-Z0-9]*$/,
|
|
238
|
+
classPattern: /^[A-Z][a-zA-Z0-9]*$/,
|
|
239
|
+
constantPattern: /^[A-Z][A-Z0-9_]*$/,
|
|
240
|
+
exceptions: ["main", "serialVersionUID"]
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
canHandle(filePath) {
|
|
244
|
+
return filePath.toLowerCase().endsWith(".java");
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export {
|
|
249
|
+
JavaParser
|
|
250
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// src/utils/path-utils.ts
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
function getDirname(importMetaUrl) {
|
|
5
|
+
return dirname(fileURLToPath(importMetaUrl));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/parsers/tree-sitter-utils.ts
|
|
9
|
+
import * as Parser from "web-tree-sitter";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as fs from "fs";
|
|
12
|
+
var getDirname2 = () => {
|
|
13
|
+
try {
|
|
14
|
+
return getDirname(import.meta.url);
|
|
15
|
+
} catch {
|
|
16
|
+
return process.cwd();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var __dirname = getDirname2();
|
|
20
|
+
var isTreeSitterInitialized = false;
|
|
21
|
+
async function initTreeSitter() {
|
|
22
|
+
if (isTreeSitterInitialized) return;
|
|
23
|
+
try {
|
|
24
|
+
const wasmPath = getWasmPath("web-tree-sitter");
|
|
25
|
+
await Parser.Parser.init({
|
|
26
|
+
locateFile() {
|
|
27
|
+
return wasmPath || "web-tree-sitter.wasm";
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
isTreeSitterInitialized = true;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Failed to initialize web-tree-sitter:", error);
|
|
33
|
+
isTreeSitterInitialized = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function findInPnpmStore(startDir, fileName, depth = 0) {
|
|
37
|
+
if (depth > 8) return null;
|
|
38
|
+
const pnpmDir = path.join(startDir, "node_modules", ".pnpm");
|
|
39
|
+
if (fs.existsSync(pnpmDir)) {
|
|
40
|
+
return findFileRecursively(pnpmDir, fileName, 0);
|
|
41
|
+
}
|
|
42
|
+
const parent = path.dirname(startDir);
|
|
43
|
+
if (parent === startDir) return null;
|
|
44
|
+
return findInPnpmStore(parent, fileName, depth + 1);
|
|
45
|
+
}
|
|
46
|
+
function findFileRecursively(dir, fileName, depth) {
|
|
47
|
+
if (depth > 6) return null;
|
|
48
|
+
try {
|
|
49
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
50
|
+
for (const entry of entries) {
|
|
51
|
+
if (entry.isFile() && entry.name === fileName) {
|
|
52
|
+
return path.join(dir, entry.name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
if (entry.isDirectory()) {
|
|
57
|
+
const found = findFileRecursively(
|
|
58
|
+
path.join(dir, entry.name),
|
|
59
|
+
fileName,
|
|
60
|
+
depth + 1
|
|
61
|
+
);
|
|
62
|
+
if (found) return found;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
function getWasmPath(language) {
|
|
70
|
+
const wasmFileName = language === "web-tree-sitter" ? "web-tree-sitter.wasm" : `tree-sitter-${language}.wasm`;
|
|
71
|
+
const immediatePaths = [
|
|
72
|
+
path.join(process.cwd(), wasmFileName),
|
|
73
|
+
path.join(__dirname, wasmFileName),
|
|
74
|
+
path.join(__dirname, "assets", wasmFileName)
|
|
75
|
+
];
|
|
76
|
+
for (const p of immediatePaths) {
|
|
77
|
+
if (fs.existsSync(p)) return p;
|
|
78
|
+
}
|
|
79
|
+
const pnpmPath = findInPnpmStore(__dirname, wasmFileName);
|
|
80
|
+
if (pnpmPath) return pnpmPath;
|
|
81
|
+
const pnpmPathCwd = findInPnpmStore(process.cwd(), wasmFileName);
|
|
82
|
+
if (pnpmPathCwd) return pnpmPathCwd;
|
|
83
|
+
console.warn(
|
|
84
|
+
`[Parser] WASM file for ${language} not found. CWD: ${process.cwd()}, DIR: ${__dirname}`
|
|
85
|
+
);
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
async function setupParser(language) {
|
|
89
|
+
await initTreeSitter();
|
|
90
|
+
const wasmPath = getWasmPath(language);
|
|
91
|
+
if (!wasmPath) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const parser = new Parser.Parser();
|
|
96
|
+
const Lang = await Parser.Language.load(wasmPath);
|
|
97
|
+
parser.setLanguage(Lang);
|
|
98
|
+
return parser;
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/parsers/base-parser.ts
|
|
105
|
+
var BaseLanguageParser = class {
|
|
106
|
+
constructor() {
|
|
107
|
+
this.parser = null;
|
|
108
|
+
this.initialized = false;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Initialize the tree-sitter parser
|
|
112
|
+
*/
|
|
113
|
+
async initialize() {
|
|
114
|
+
if (this.initialized) return;
|
|
115
|
+
try {
|
|
116
|
+
this.parser = await setupParser(this.getParserName());
|
|
117
|
+
this.initialized = true;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.warn(`Failed to initialize ${this.language} parser:`, error);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async getAST(code, _filePath) {
|
|
123
|
+
void _filePath;
|
|
124
|
+
if (!this.initialized) await this.initialize();
|
|
125
|
+
if (!this.parser) return null;
|
|
126
|
+
return this.parser.parse(code);
|
|
127
|
+
}
|
|
128
|
+
parse(code, filePath) {
|
|
129
|
+
if (!this.initialized || !this.parser) {
|
|
130
|
+
return this.parseRegex(code, filePath);
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const tree = this.parser.parse(code);
|
|
134
|
+
if (!tree || tree.rootNode.type === "ERROR" || tree.rootNode.hasError) {
|
|
135
|
+
return this.parseRegex(code, filePath);
|
|
136
|
+
}
|
|
137
|
+
const imports = this.extractImportsAST(tree.rootNode);
|
|
138
|
+
const exports = this.extractExportsAST(tree.rootNode, code);
|
|
139
|
+
return {
|
|
140
|
+
exports,
|
|
141
|
+
imports,
|
|
142
|
+
language: this.language,
|
|
143
|
+
warnings: []
|
|
144
|
+
};
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.warn(
|
|
147
|
+
`AST parsing failed for ${filePath}, falling back to regex: ${error.message}`
|
|
148
|
+
);
|
|
149
|
+
return this.parseRegex(code, filePath);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
canHandle(filePath) {
|
|
153
|
+
const lowerPath = filePath.toLowerCase();
|
|
154
|
+
return this.extensions.some((ext) => lowerPath.endsWith(ext));
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export {
|
|
159
|
+
getDirname,
|
|
160
|
+
initTreeSitter,
|
|
161
|
+
getWasmPath,
|
|
162
|
+
setupParser,
|
|
163
|
+
BaseLanguageParser
|
|
164
|
+
};
|