@codua/codeoutline-win32-x64 0.1.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/DISTRIBUTION.md +98 -0
- package/LICENSE +24 -0
- package/README.md +132 -0
- package/README.zh-CN.md +132 -0
- package/THIRD_PARTY.md +32 -0
- package/build-info.json +1 -0
- package/codeoutline +4 -0
- package/codeoutline.cmd +3 -0
- package/licenses/libdeflate.txt +22 -0
- package/licenses/lua-cmsgpack.txt +22 -0
- package/licenses/luajit.txt +56 -0
- package/licenses/mbedtls.txt +553 -0
- package/licenses/rpmalloc.txt +12 -0
- package/licenses/xnet2lua.txt +24 -0
- package/licenses/yyjson.txt +21 -0
- package/package.json +1 -0
- package/scripts/codeoutline/cli.lua +32 -0
- package/scripts/codeoutline/command.lua +155 -0
- package/scripts/codeoutline/common.lua +124 -0
- package/scripts/codeoutline/control.lua +4 -0
- package/scripts/codeoutline/explore.lua +500 -0
- package/scripts/codeoutline/graph.lua +380 -0
- package/scripts/codeoutline/http.lua +156 -0
- package/scripts/codeoutline/index.lua +404 -0
- package/scripts/codeoutline/index_worker.lua +43 -0
- package/scripts/codeoutline/lang/c.lua +362 -0
- package/scripts/codeoutline/lang/cpp.lua +539 -0
- package/scripts/codeoutline/lang/csharp.lua +334 -0
- package/scripts/codeoutline/lang/go.lua +233 -0
- package/scripts/codeoutline/lang/java.lua +274 -0
- package/scripts/codeoutline/lang/js.lua +466 -0
- package/scripts/codeoutline/lang/lua.lua +218 -0
- package/scripts/codeoutline/lang/python.lua +184 -0
- package/scripts/codeoutline/lang/rust.lua +276 -0
- package/scripts/codeoutline/main.lua +104 -0
- package/scripts/codeoutline/mcp.lua +188 -0
- package/scripts/codeoutline/parse.lua +49 -0
- package/scripts/codeoutline/path.lua +36 -0
- package/scripts/codeoutline/service.lua +135 -0
- package/scripts/codeoutline/text.lua +43 -0
- package/scripts/codeoutline/version.lua +1 -0
- package/scripts/codeoutline/xscan.lua +625 -0
- package/xnet2lua/bin/xnet.exe +0 -0
- package/xnet2lua/scripts/core/share/xhttp_codec.lua +835 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
-- lang/java.lua — index-level Java parser: package, imports, classes /
|
|
2
|
+
-- interfaces / enums / records / annotation types (+ extends/implements),
|
|
3
|
+
-- methods, constructors, fields, enum constants, and calls.
|
|
4
|
+
--
|
|
5
|
+
-- Generics are not bracket-matched by xscan ('<' is also less-than), so
|
|
6
|
+
-- declarations track angle depth themselves; bodies need no generics
|
|
7
|
+
-- handling because they are only scanned for call sites.
|
|
8
|
+
|
|
9
|
+
local xscan = require('codeoutline.xscan')
|
|
10
|
+
local common = require('codeoutline.common')
|
|
11
|
+
|
|
12
|
+
local M = {}
|
|
13
|
+
|
|
14
|
+
M.config = {
|
|
15
|
+
keywords = {
|
|
16
|
+
'abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch', 'char', 'class',
|
|
17
|
+
'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extends', 'final',
|
|
18
|
+
'finally', 'float', 'for', 'goto', 'if', 'implements', 'import', 'instanceof', 'int',
|
|
19
|
+
'interface', 'long', 'native', 'new', 'package', 'private', 'protected', 'public',
|
|
20
|
+
'return', 'short', 'static', 'strictfp', 'super', 'switch', 'synchronized', 'this',
|
|
21
|
+
'throw', 'throws', 'transient', 'try', 'void', 'volatile', 'while',
|
|
22
|
+
'true', 'false', 'null',
|
|
23
|
+
},
|
|
24
|
+
ops = {
|
|
25
|
+
'>>>=', '<<=', '>>=', '->', '::', '++', '--', '&&', '||', '==', '!=', '<=', '>=',
|
|
26
|
+
'+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '...', '<<', '>>>', '>>',
|
|
27
|
+
},
|
|
28
|
+
ident_start = 'A-Za-z_$',
|
|
29
|
+
ident_char = 'A-Za-z0-9_$',
|
|
30
|
+
line_comment = { '//' },
|
|
31
|
+
block_comment = { { '/*', '*/' } },
|
|
32
|
+
strings = {
|
|
33
|
+
{ '"""', '"""', escape = '\\', multiline = true }, -- text blocks
|
|
34
|
+
{ '"', '"', escape = '\\' },
|
|
35
|
+
{ "'", "'", escape = '\\' },
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
M.lang = xscan.lang(M.config)
|
|
40
|
+
|
|
41
|
+
local TYPE_KW = { class = 'class', interface = 'interface', enum = 'enum' }
|
|
42
|
+
|
|
43
|
+
local function is(T, i, s) return T.k[i] == 'op' and T:text(i) == s end
|
|
44
|
+
|
|
45
|
+
-- Change in generic angle depth for token i ('>>' closes two levels).
|
|
46
|
+
local function angle(T, i)
|
|
47
|
+
if T.k[i] ~= 'op' then return 0 end
|
|
48
|
+
local t = T:text(i)
|
|
49
|
+
if t == '<' then return 1 end
|
|
50
|
+
if t == '>' then return -1 end
|
|
51
|
+
if t == '>>' then return -2 end
|
|
52
|
+
if t == '>>>' then return -3 end
|
|
53
|
+
return 0
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
-- Next index after an annotation starting at '@' i: @A, @a.b.C, @A(...).
|
|
57
|
+
local function skip_annotation(T, i)
|
|
58
|
+
local j = i + 1
|
|
59
|
+
while T.k[j] == 'id' or is(T, j, '.') do j = j + 1 end
|
|
60
|
+
if is(T, j, '(') and T.m[j] then j = T.m[j] + 1 end
|
|
61
|
+
return j
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
-- Type names listed after extends/implements up to '{' (generic args dropped).
|
|
65
|
+
local function supertypes(T, a, b)
|
|
66
|
+
local out, depth, x = {}, 0, a
|
|
67
|
+
while x < b do
|
|
68
|
+
depth = depth + angle(T, x)
|
|
69
|
+
if depth == 0 and T.k[x] == 'id' then
|
|
70
|
+
local name, y = T:text(x), x + 1
|
|
71
|
+
while is(T, y, '.') and T.k[y + 1] == 'id' do
|
|
72
|
+
name = name .. '.' .. T:text(y + 1)
|
|
73
|
+
y = y + 2
|
|
74
|
+
end
|
|
75
|
+
out[#out + 1] = name
|
|
76
|
+
x = y
|
|
77
|
+
else
|
|
78
|
+
x = x + 1
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
return out
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
local parse_members
|
|
85
|
+
|
|
86
|
+
-- Type declaration: keyword token at kw, '{' at o. Returns the node index.
|
|
87
|
+
local function type_decl(T, r, i, kwi, o, parent, kind)
|
|
88
|
+
local name_tok = kwi + 1
|
|
89
|
+
local node = common.add_node(r, T, {
|
|
90
|
+
kind = kind, name = T:text(name_tok), parent = parent,
|
|
91
|
+
ti = i, tj = T.m[o] or T.n, sig = common.sig(T, i, o - 1),
|
|
92
|
+
})
|
|
93
|
+
local n = r.nodes[node]
|
|
94
|
+
for x = name_tok + 1, o - 1 do
|
|
95
|
+
local t = T.k[x] == 'kw' and T:text(x)
|
|
96
|
+
if t == 'extends' or t == 'implements' then
|
|
97
|
+
local stop = o
|
|
98
|
+
for y = x + 1, o - 1 do
|
|
99
|
+
if T.k[y] == 'kw' and (T:text(y) == 'implements' or T:text(y) == 'extends') or (T.k[y] == 'id' and T:text(y) == 'permits') then
|
|
100
|
+
stop = y; break
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
local list = supertypes(T, x + 1, stop)
|
|
104
|
+
if t == 'extends' then
|
|
105
|
+
n.extends = list
|
|
106
|
+
else
|
|
107
|
+
n.implements = list
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
if kind == 'record' and is(T, name_tok + 1, '(') and T.m[name_tok + 1] then
|
|
112
|
+
-- record components become fields
|
|
113
|
+
local c = T.m[name_tok + 1]
|
|
114
|
+
for x = name_tok + 2, c - 1 do
|
|
115
|
+
if T.k[x] == 'id' and (is(T, x + 1, ',') or x + 1 == c) then
|
|
116
|
+
common.add_node(r, T, { kind = 'field', name = T:text(x), parent = node, ti = x, tj = x })
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
local close = T.m[o] or T.n
|
|
121
|
+
local start = o + 1
|
|
122
|
+
if kind == 'enum' then
|
|
123
|
+
-- constants: NAME [(args)] [{ body }] , ... up to ';' or '}'
|
|
124
|
+
local x = o + 1
|
|
125
|
+
while x < close and not is(T, x, ';') do
|
|
126
|
+
while is(T, x, '@') do x = skip_annotation(T, x) end
|
|
127
|
+
if T.k[x] == 'id' then
|
|
128
|
+
local y = x + 1
|
|
129
|
+
if is(T, y, '(') and T.m[y] then y = T.m[y] + 1 end
|
|
130
|
+
if is(T, y, '{') and T.m[y] then y = T.m[y] + 1 end
|
|
131
|
+
common.add_node(r, T, { kind = 'enum_member', name = T:text(x), parent = node, ti = x, tj = y - 1 })
|
|
132
|
+
common.add_calls(r, T, x + 1, y - 1)
|
|
133
|
+
x = y
|
|
134
|
+
end
|
|
135
|
+
if is(T, x, ',') then
|
|
136
|
+
x = x + 1
|
|
137
|
+
elseif not (T.k[x] == 'id' or is(T, x, '@') or is(T, x, ';')) then
|
|
138
|
+
x = x + 1
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
start = x + 1
|
|
142
|
+
end
|
|
143
|
+
parse_members(T, r, start, close - 1, node, T:text(name_tok))
|
|
144
|
+
return node
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
-- Members of a type body in [a, b].
|
|
148
|
+
parse_members = function(T, r, a, b, parent, class_name)
|
|
149
|
+
local i = a
|
|
150
|
+
local ann_start -- annotations before a member start its range (as javac does)
|
|
151
|
+
while i <= b do
|
|
152
|
+
if is(T, i, ';') then
|
|
153
|
+
i = i + 1
|
|
154
|
+
elseif is(T, i, '@') and not (T.k[i + 1] == 'kw' and T:text(i + 1) == 'interface') then
|
|
155
|
+
ann_start = ann_start or i
|
|
156
|
+
i = skip_annotation(T, i)
|
|
157
|
+
else
|
|
158
|
+
local mstart = ann_start or i
|
|
159
|
+
ann_start = nil
|
|
160
|
+
-- scan one member to ';' or a '{'
|
|
161
|
+
local j, done = i, false
|
|
162
|
+
local eq
|
|
163
|
+
while j <= b and not done do
|
|
164
|
+
if is(T, j, '=') and not eq then eq = j end
|
|
165
|
+
if is(T, j, ';') then
|
|
166
|
+
-- field(s) or abstract method
|
|
167
|
+
local p
|
|
168
|
+
for y = i, j - 1 do
|
|
169
|
+
if is(T, y, '(') and T.m[y] and T.k[y - 1] == 'id' and not eq then p = y - 1; break end
|
|
170
|
+
if eq and y >= eq then break end
|
|
171
|
+
end
|
|
172
|
+
if p then
|
|
173
|
+
common.add_node(r, T, { kind = 'method', name = T:text(p), parent = parent, ti = mstart, tj = j, sig = common.sig(T, i, T.m[p + 1]), abstract = true })
|
|
174
|
+
else
|
|
175
|
+
-- field names: identifiers at angle depth 0 followed by = , ;
|
|
176
|
+
-- (initializer bracket groups are skipped whole, so
|
|
177
|
+
-- commas inside call args don't start a new name)
|
|
178
|
+
local d, init, y = 0, false, i
|
|
179
|
+
while y < j do
|
|
180
|
+
d = d + angle(T, y)
|
|
181
|
+
if is(T, y, '=') then init = true
|
|
182
|
+
elseif is(T, y, ',') and d == 0 then init = false
|
|
183
|
+
elseif not init and d == 0 and T.k[y] == 'id' and T.k[y + 1] == 'op' then
|
|
184
|
+
local nx = T:text(y + 1)
|
|
185
|
+
-- `Type[] name`: a '[' after the type, not the name
|
|
186
|
+
local array_type = nx == '[' and T.m[y + 1] and T.k[T.m[y + 1] + 1] == 'id'
|
|
187
|
+
if (nx == '=' or nx == ';' or nx == ',' or nx == '[') and not array_type then
|
|
188
|
+
common.add_node(r, T, { kind = 'field', name = T:text(y), parent = parent, ti = y, tj = j, sig = common.sig(T, i, math.min(j - 1, y + 1)) })
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
if init and T.m[y] and T.m[y] > y and T.k[y] == 'op' then y = T.m[y] end
|
|
192
|
+
y = y + 1
|
|
193
|
+
end
|
|
194
|
+
common.add_calls(r, T, i, j)
|
|
195
|
+
end
|
|
196
|
+
done = true
|
|
197
|
+
elseif is(T, j, '{') then
|
|
198
|
+
local kwi, kind
|
|
199
|
+
for y = i, j - 1 do
|
|
200
|
+
local t = T:text(y)
|
|
201
|
+
if T.k[y] == 'kw' and TYPE_KW[t] then
|
|
202
|
+
kwi, kind = y, TYPE_KW[t]
|
|
203
|
+
if is(T, y - 1, '@') then kind = 'annotation_type' end
|
|
204
|
+
break
|
|
205
|
+
elseif T.k[y] == 'id' and t == 'record' and T.k[y + 1] == 'id' then
|
|
206
|
+
kwi, kind = y, 'record'
|
|
207
|
+
break
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
local close = T.m[j] or b
|
|
211
|
+
if kwi and not eq then
|
|
212
|
+
type_decl(T, r, mstart, kwi, j, parent, kind)
|
|
213
|
+
j = close
|
|
214
|
+
elseif eq then
|
|
215
|
+
j = close -- array initializer / anonymous class: continue to ';'
|
|
216
|
+
else
|
|
217
|
+
-- method / constructor: '(' group before '{' (skip throws ...)
|
|
218
|
+
local x = j - 1
|
|
219
|
+
while x >= i and not is(T, x, ')') do x = x - 1 end
|
|
220
|
+
local o = x >= i and T.m[x]
|
|
221
|
+
local calls_from = i
|
|
222
|
+
if o and T.k[o - 1] == 'id' then
|
|
223
|
+
calls_from = o -- skip `name(`: not a call to itself
|
|
224
|
+
local name = T:text(o - 1)
|
|
225
|
+
common.add_node(r, T, {
|
|
226
|
+
kind = (name == class_name) and 'constructor' or 'method',
|
|
227
|
+
name = name, parent = parent, ti = mstart, tj = close,
|
|
228
|
+
sig = common.sig(T, i, x),
|
|
229
|
+
})
|
|
230
|
+
end
|
|
231
|
+
-- initializer blocks and bodies: calls only
|
|
232
|
+
common.add_calls(r, T, calls_from, close)
|
|
233
|
+
j = close
|
|
234
|
+
end
|
|
235
|
+
done = not eq
|
|
236
|
+
elseif T.m[j] and T.m[j] > j and T.k[j] == 'op' and T:text(j) ~= '{' then
|
|
237
|
+
j = T.m[j]
|
|
238
|
+
end
|
|
239
|
+
if not done then j = j + 1 end
|
|
240
|
+
end
|
|
241
|
+
i = j + 1
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
function M.parse(path, src)
|
|
247
|
+
local T = M.lang:tokenize(src)
|
|
248
|
+
local r = common.new(path, 'java')
|
|
249
|
+
local i = 1
|
|
250
|
+
while i <= T.n do
|
|
251
|
+
if T.k[i] == 'kw' and T:text(i) == 'package' then
|
|
252
|
+
local j = i + 1
|
|
253
|
+
local parts = {}
|
|
254
|
+
while not is(T, j, ';') and j <= T.n do parts[#parts + 1] = T:text(j); j = j + 1 end
|
|
255
|
+
r.package = table.concat(parts)
|
|
256
|
+
r.prefix = r.package
|
|
257
|
+
i = j + 1
|
|
258
|
+
elseif T.k[i] == 'kw' and T:text(i) == 'import' then
|
|
259
|
+
local j = i + 1
|
|
260
|
+
local static = T.k[j] == 'kw' and T:text(j) == 'static'
|
|
261
|
+
if static then j = j + 1 end
|
|
262
|
+
local parts = {}
|
|
263
|
+
while not is(T, j, ';') and j <= T.n do parts[#parts + 1] = T:text(j); j = j + 1 end
|
|
264
|
+
r.imports[#r.imports + 1] = { path = table.concat(parts), line = T:line(i), static = static or nil }
|
|
265
|
+
i = j + 1
|
|
266
|
+
else
|
|
267
|
+
break
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
parse_members(T, r, i, T.n, nil, nil)
|
|
271
|
+
return common.finish(r), T
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
return M
|