Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bcef6ffd25 | ||
|
|
b7137d39cb | ||
|
|
60bada9243 | ||
|
|
76c34fa098 | ||
|
|
1e92906a43 | ||
|
|
52e97578ae | ||
|
|
f4e1e51d22 | ||
|
|
5820be3f40 | ||
|
|
eb2982e77c | ||
|
|
5a9a95e8da | ||
|
|
38be3c76b1 | ||
|
|
520c6fd907 | ||
|
|
a59d2d0088 | ||
|
|
9c82fabf1b | ||
|
|
956410c345 | ||
|
|
81b3d1c2d3 | ||
|
|
f25b9164d0 | ||
|
|
c0a022c5b5 | ||
|
|
ce8c9b3b94 | ||
|
|
b6e3ee8404 | ||
|
|
85d4bb2628 | ||
|
|
82128ce318 | ||
|
|
390b3446a3 | ||
|
|
f66d2f0193 | ||
|
|
53446e06c6 | ||
|
|
691a7fb2c7 | ||
|
|
57e6934fe5 | ||
|
|
335ffdd074 | ||
|
|
0906378894 | ||
|
|
7282081832 | ||
|
|
a3c7398628 | ||
|
|
07594f574b | ||
|
|
3b7798338f | ||
|
|
eae5a08932 | ||
|
|
547989a6d4 | ||
|
|
f6f19c0e48 | ||
|
|
f8a7241747 | ||
|
|
4ccec31efa | ||
|
|
b7c3c53dc9 | ||
|
|
f1f3b17402 | ||
|
|
254655cb1d | ||
|
|
a212822d45 | ||
|
|
26ae7adac5 | ||
|
|
c797fbec80 | ||
|
|
17c48fab97 | ||
|
|
bcd60d80ea | ||
|
|
71f0ee1973 | ||
|
|
8119515705 | ||
|
|
28d7b02350 | ||
|
|
be4aa2592a | ||
|
|
4b9f2e3b47 | ||
|
|
05c27c5d20 | ||
|
|
6f2288c81f | ||
|
|
88d496137a | ||
|
|
b231f65bfb | ||
|
|
15749c8ad7 | ||
|
|
5cf9b26a2e | ||
|
|
d5356a83ef | ||
|
|
19d6ec7e52 | ||
|
|
5acb371fab | ||
|
|
c6eadbd193 | ||
|
|
f18ae4e08f | ||
|
|
59ba554315 | ||
|
|
9207cc3f43 | ||
|
|
0af3bdfd04 | ||
|
|
102c4fc398 | ||
|
|
f53edb6e64 | ||
|
|
acaefbb68c | ||
|
|
09cbbe75c9 | ||
|
|
81c2b860c6 | ||
|
|
57128a8d8b | ||
|
|
6bf33e4296 | ||
|
|
3aaf54e2c2 | ||
|
|
28b8cda4cf | ||
|
|
b5cff355e6 | ||
|
|
a00dbf4b1a | ||
|
|
627b973175 | ||
|
|
0db8844b4d | ||
|
|
cd0c9640af | ||
|
|
c88bd50be9 | ||
|
|
1289778874 | ||
|
|
00be1a45ba | ||
|
|
f5a8b5c601 | ||
|
|
90c7abca5f | ||
|
|
ef01da4b5b | ||
|
|
f544236230 | ||
|
|
3a57ed57da | ||
|
|
13b71a6c48 | ||
|
|
76fb5d04f7 | ||
|
|
60213303ae | ||
|
|
5ef50c1682 | ||
|
|
57ba3236bc | ||
|
|
5717037012 | ||
|
|
4ddb6d32f3 | ||
|
|
60ea87bd2c | ||
|
|
a7d780565f | ||
|
|
3b1896a696 | ||
|
|
3859bb70cb | ||
|
|
9d65f3d20b | ||
|
|
cddd6cfe57 | ||
|
|
0cc3a48f0b | ||
|
|
9b0c364e13 | ||
|
|
4e1b4dda58 | ||
|
|
ac0bdafb16 | ||
|
|
88d34a970c | ||
|
|
9a07bb36a4 | ||
|
|
7b8ad7c6b5 | ||
|
|
fd4cebf692 | ||
|
|
a37dd308a1 | ||
|
|
30885683f2 | ||
|
|
0ae167cb4f | ||
|
|
ec152e4171 | ||
|
|
2eeb3ae398 | ||
|
|
75b4bdfed8 | ||
|
|
81d5cc25a6 | ||
|
|
ff845325c6 | ||
|
|
6688055434 | ||
|
|
f905e39af2 | ||
|
|
58a07f2ab6 | ||
|
|
c9d685d1ab | ||
|
|
63ebc409f0 | ||
|
|
c631eb8e75 | ||
|
|
96074038e9 | ||
|
|
8b1b40d0f9 | ||
|
|
486abca78b | ||
|
|
2b5b4eb2d7 | ||
|
|
54ba686380 | ||
|
|
7615eda083 | ||
|
|
779d9ce391 | ||
|
|
db909866b8 | ||
|
|
4de90ab9c1 | ||
|
|
41193dbc0d | ||
|
|
8d584f4e4e | ||
|
|
74c79e1a5c | ||
|
|
4d36e74d79 | ||
|
|
eef4e9a922 | ||
|
|
a88fed137a | ||
|
|
62c15cceff | ||
|
|
54d8aa48fb | ||
|
|
dbc276daa7 | ||
|
|
f1e4aa5b6e | ||
|
|
057ef7b80e | ||
|
|
d1d4155c88 | ||
|
|
270cb26460 | ||
|
|
18d788974a | ||
|
|
ba9ae62e51 | ||
|
|
b05a028137 | ||
|
|
f4fdde4a0b | ||
|
|
3d1a0b5418 | ||
|
|
5fda8a2de9 | ||
|
|
b6b6eb5548 | ||
|
|
248b56ec1f | ||
|
|
07ebe90437 | ||
|
|
b0168c1d55 | ||
|
|
676c0626d1 | ||
|
|
b013f412b2 | ||
|
|
86638e20b0 | ||
|
|
2dd34b21e6 | ||
|
|
3bf93a128c | ||
|
|
0244db1e5c | ||
|
|
d8b18d7058 | ||
|
|
d4e0841f16 | ||
|
|
75fcf542a0 | ||
|
|
abf5da8b66 | ||
|
|
c423ab43f1 | ||
|
|
0977f7422a | ||
|
|
5bb0d6db58 | ||
|
|
993c9d09c3 | ||
|
|
b960ef602c | ||
|
|
2f4ddb30ec | ||
|
|
029f460b75 | ||
|
|
2737b6e03b | ||
|
|
1efafeef2f | ||
|
|
f3676cd99e | ||
|
|
24532cea79 | ||
|
|
aae0e64988 | ||
|
|
5700899beb | ||
|
|
d2a13d0e66 | ||
|
|
9368c889d7 | ||
|
|
bff45bd793 | ||
|
|
69f9d218ca | ||
|
|
35b9b8e66f | ||
|
|
f015eef645 | ||
|
|
18c15b13bc | ||
|
|
45cda3cc90 | ||
|
|
d90fd568a6 | ||
|
|
7712b21faa | ||
|
|
42e27a873b | ||
|
|
3276bf9cd3 | ||
|
|
8e29350f12 | ||
|
|
7f4f672d81 | ||
|
|
40cac999c4 | ||
|
|
89fdddfd75 | ||
|
|
96372c05fd | ||
|
|
965267a770 | ||
|
|
bc448c2af2 | ||
|
|
089c6d25bc | ||
|
|
992066d19b | ||
|
|
58d9bafe7a | ||
|
|
182f7d8c9c | ||
|
|
e1afe9afb2 | ||
|
|
44dfec6283 | ||
|
|
8b00733ddf | ||
|
|
70510cf224 | ||
|
|
06dc722aca | ||
|
|
ed176cfaf5 | ||
|
|
27ea836f71 | ||
|
|
e57fab9160 | ||
|
|
8203fc7d6b | ||
|
|
879dca7391 | ||
|
|
e3fc9e8e4a | ||
|
|
dc3e25bcba | ||
|
|
4369f99225 | ||
|
|
14a4c440b6 | ||
|
|
b10dad8bcc | ||
|
|
2e21b36796 | ||
|
|
f546bd72b8 | ||
|
|
68b16fecfe | ||
|
|
c0d5bf3acc | ||
|
|
86c3277075 | ||
|
|
4457352c49 | ||
|
|
180b2d7229 | ||
|
|
4e33891ae5 | ||
|
|
393abc08ed | ||
|
|
ee7e8c17e8 | ||
|
|
f8ed7cfe19 | ||
|
|
959717fafd | ||
|
|
f01bc0a117 | ||
|
|
c00ad8e0a7 | ||
|
|
ec885d5ddb | ||
|
|
19c1458b1d | ||
|
|
5b1301aac5 | ||
|
|
e6ad49327a | ||
|
|
5669fe2fda | ||
|
|
111156da5a | ||
|
|
458162901e | ||
|
|
5ad6a429cc | ||
|
|
cdae8e5e29 | ||
|
|
437b74b353 | ||
|
|
0eeeec5d22 | ||
|
|
fb3d6546e5 | ||
|
|
34b3d9365a | ||
|
|
9f26b27210 | ||
|
|
6547225e8d | ||
|
|
f78d326102 | ||
|
|
740d675294 | ||
|
|
dabaab7675 | ||
|
|
5152be9c4e | ||
|
|
2798e54167 | ||
|
|
831ef6c4f9 | ||
|
|
98885faaa2 | ||
|
|
ef499fd7bd | ||
|
|
ac8ab9b0f0 | ||
|
|
ca7602098f | ||
|
|
ff5626530e | ||
|
|
0bc6751914 | ||
|
|
790b84e7d3 | ||
|
|
ae8dbf43b5 | ||
|
|
fbfc2eb64c | ||
|
|
0f5a191bcf | ||
|
|
948b708223 | ||
|
|
2a55c36b74 | ||
|
|
f25b9fabf8 | ||
|
|
fd25217dee | ||
|
|
fa60ec42f3 | ||
|
|
ce1ac1be84 | ||
|
|
0b1e4f9ed4 | ||
|
|
bac6eec44e | ||
|
|
ff81281337 | ||
|
|
8ccdabef47 | ||
|
|
106f886e83 | ||
|
|
c1b298e46d | ||
|
|
1d1962603b | ||
|
|
18f614d142 | ||
|
|
f0770fb7fc | ||
|
|
c11cd4a6bb | ||
|
|
a4da94792d | ||
|
|
3172e6673f | ||
|
|
eaedb1b88f | ||
|
|
100ed4ecdd | ||
|
|
7c3b823ce1 | ||
|
|
61d1efe943 | ||
|
|
4d2938ac81 | ||
|
|
d762f21c54 | ||
|
|
0a42ea6d57 | ||
|
|
ad2c8c89c1 | ||
|
|
131f0e2d74 | ||
|
|
5899ea7932 | ||
|
|
8539fe96a4 | ||
|
|
8996f2b7f1 | ||
|
|
1885308639 | ||
|
|
211f741a64 | ||
|
|
37d4b97a44 | ||
|
|
3919831857 | ||
|
|
e309794fd7 | ||
|
|
dbca3da639 | ||
|
|
6007b49271 | ||
|
|
ddb4072ac1 | ||
|
|
9cf43d9f7e | ||
|
|
82f9ecaf4a | ||
|
|
66c4b4c4c3 | ||
|
|
8c8815dc45 | ||
|
|
8b41391a5f | ||
|
|
bfcca3e6f9 | ||
|
|
5271f90fa9 | ||
|
|
12cf4b9a85 | ||
|
|
34d2533473 | ||
|
|
9b7528f723 | ||
|
|
1cf1ffd2c0 | ||
|
|
36c2326466 | ||
|
|
f02f8478da | ||
|
|
0b9abf2a57 | ||
|
|
c537a09ad1 | ||
|
|
bee84a622c | ||
|
|
b9b1b0725a | ||
|
|
e8b0c6a542 | ||
|
|
e4033481bc | ||
|
|
88d8af8b96 | ||
|
|
cf49d9a778 | ||
|
|
bed959c658 | ||
|
|
c5cd2d7ce1 | ||
|
|
5a879cd6a5 | ||
|
|
d3346111c7 | ||
|
|
a981060e9e | ||
|
|
d1b32ea8a1 | ||
|
|
2578ce1cf6 | ||
|
|
58f86058d4 | ||
|
|
24af603ce1 | ||
|
|
784fb8da65 | ||
|
|
f08e97af1f | ||
|
|
60fc7ec252 | ||
|
|
789c7f5317 | ||
|
|
2821b5da09 | ||
|
|
bd9d56943e | ||
|
|
b72e6e3466 | ||
|
|
2eecf9c230 | ||
|
|
2f33abc75c | ||
|
|
556d7daa13 | ||
|
|
9e68943b7e | ||
|
|
307a029995 | ||
|
|
54e0ca6510 | ||
|
|
2ba2372bde | ||
|
|
513956062d | ||
|
|
b59f0b8f2f | ||
|
|
6f6e080ee0 | ||
|
|
d9f100d245 | ||
|
|
c3096b320e | ||
|
|
159b740f39 | ||
|
|
9f311903e0 | ||
|
|
ee192a247f | ||
|
|
572a51ad32 | ||
|
|
7df1cfbfb9 | ||
|
|
6489f75b7d | ||
|
|
dad49f1867 | ||
|
|
36aab9e86e | ||
|
|
c16aae75e2 | ||
|
|
dfa6ccb350 | ||
|
|
702dec9c40 | ||
|
|
a5ffe34c2d | ||
|
|
26ebb69f81 | ||
|
|
6b7563cab3 | ||
|
|
4fa7a73704 | ||
|
|
6328826c9e | ||
|
|
006766bc1e | ||
|
|
109e31fd2d | ||
|
|
fbb46ae9f2 | ||
|
|
ce5c85b0ad | ||
|
|
a077c7b32f | ||
|
|
f6a8edfef1 | ||
|
|
d33276407e | ||
|
|
b95aaefe8f | ||
|
|
a5de6d80cc | ||
|
|
7e34d06103 | ||
|
|
c6c023dda7 | ||
|
|
d58e583d22 | ||
|
|
8ed04fb58b | ||
|
|
2448655fc4 | ||
|
|
6500187ca1 | ||
|
|
32fd6af04f | ||
|
|
36f7233297 | ||
|
|
edb285c90b | ||
|
|
29f0282fe4 | ||
|
|
e1be96412d | ||
|
|
d45f09c27c | ||
|
|
61d08882a9 | ||
|
|
0ad15e674a | ||
|
|
edb9686703 | ||
|
|
6eeeddad3f | ||
|
|
b406382564 | ||
|
|
eacb3f8c5f | ||
|
|
de312aaccc | ||
|
|
cf3ba63d01 | ||
|
|
e7fcc3a71a | ||
|
|
a479a9d941 | ||
|
|
d6eccdd556 | ||
|
|
40613fa56a | ||
|
|
b1d7082584 | ||
|
|
aa53d0588c | ||
|
|
6f1a837296 | ||
|
|
7202f74e78 | ||
|
|
f1a6d7488f | ||
|
|
b49316d9bb | ||
|
|
fc71fb5a33 | ||
|
|
d3d9dd352a | ||
|
|
1a0ce41e00 | ||
|
|
de2fcea154 | ||
|
|
988dbe0cd2 | ||
|
|
f71694e210 | ||
|
|
8056640102 | ||
|
|
eaec10e529 | ||
|
|
38df157c40 | ||
|
|
fed82bc932 | ||
|
|
80ab2eaae9 | ||
|
|
3bd25c689b | ||
|
|
3bbde1f748 | ||
|
|
675c4ef4f9 | ||
|
|
936dc7f0cc | ||
|
|
a7edf0e221 | ||
|
|
f1f0df425f | ||
|
|
1c02657282 | ||
|
|
3d21a7634c | ||
|
|
04e6cbe6cf | ||
|
|
6db33c3a27 | ||
|
|
7108f9c7de | ||
|
|
6a10a25389 | ||
|
|
277cc0ec2f | ||
|
|
ab7dcd0be9 | ||
|
|
acf69caf7e | ||
|
|
2f1e67660d | ||
|
|
8b1ef36dc5 | ||
|
|
1cd629f39c | ||
|
|
2e221b42a1 | ||
|
|
690336036d | ||
|
|
9791893d2b | ||
|
|
643de56cf5 | ||
|
|
099f008766 | ||
|
|
ef013e7095 | ||
|
|
9cae588b7c | ||
|
|
d050dd4c5c | ||
|
|
22ca64ccf8 | ||
|
|
81857669b0 | ||
|
|
986c308846 | ||
|
|
be50fdeda5 | ||
|
|
30be75dbae | ||
|
|
28293fd6d7 | ||
|
|
f9f1cb760c | ||
|
|
6c45957b82 | ||
|
|
4d08f85419 | ||
|
|
5b8827549f | ||
|
|
f1d902849e | ||
|
|
2ca145b264 | ||
|
|
f07ec0df33 | ||
|
|
3476f6bd94 | ||
|
|
ae265c83b0 | ||
|
|
008fca66bf | ||
|
|
d8bc3d4177 | ||
|
|
f73e8d02f9 | ||
|
|
744ffc5ab7 | ||
|
|
f877279df0 | ||
|
|
26f5a84f97 | ||
|
|
8a998c6f62 | ||
|
|
481c7ee5cb | ||
|
|
47ebc2889f | ||
|
|
92cfbbcc9d | ||
|
|
455d303971 | ||
|
|
6dce4e5cdc | ||
|
|
90735e6866 | ||
|
|
50fd3c1856 | ||
|
|
39025c41b3 | ||
|
|
01b08f9fbf | ||
|
|
3e1b4fd692 | ||
|
|
edc3fa55c8 | ||
|
|
f832b3bf2d | ||
|
|
dfd016d10c | ||
|
|
5128086ebe | ||
|
|
930b7ed423 | ||
|
|
9eadeaa611 | ||
|
|
b2f89035b9 | ||
|
|
d36ec5c259 | ||
|
|
c492e16cc8 | ||
|
|
e7b033ecf0 | ||
|
|
aa186d8b7d | ||
|
|
4dee23fea2 | ||
|
|
36f76f9cbe | ||
|
|
a023f3ec82 | ||
|
|
bf277bbdfe | ||
|
|
0c842a22b9 | ||
|
|
dd2e7f765c | ||
|
|
86541779db | ||
|
|
7c8f18f65e | ||
|
|
d45bfde162 | ||
|
|
953a706846 | ||
|
|
251c7b109f | ||
|
|
95897dc746 | ||
|
|
a107e045eb | ||
|
|
53f06ab388 | ||
|
|
d59d990b70 | ||
|
|
12850bfe36 | ||
|
|
182c00b142 | ||
|
|
63f6c7c045 | ||
|
|
5c53b7e768 | ||
|
|
fa38f93677 | ||
|
|
81c59cbaf0 | ||
|
|
6ad71a1ebf | ||
|
|
efb11dd332 | ||
|
|
5d16e79767 | ||
|
|
083d38b9d3 | ||
|
|
7d4157774a | ||
|
|
8aa16c882e | ||
|
|
2f170363de | ||
|
|
abc34b3f6f | ||
|
|
08728efcdd | ||
|
|
b360ecf4a8 | ||
|
|
5d4d21359f | ||
|
|
0eec52f6d9 | ||
|
|
aa160ba8fc | ||
|
|
1a368b2bc7 | ||
|
|
670b811e03 | ||
|
|
a724f7f12c | ||
|
|
1f76564b9d | ||
|
|
ed09511952 | ||
|
|
9a791bba25 | ||
|
|
57308e278c | ||
|
|
8e6436dc69 | ||
|
|
dbe835612d | ||
|
|
25f7114340 | ||
|
|
20168406b5 | ||
|
|
1e26cf6cb0 | ||
|
|
5cf69f90fb | ||
|
|
b84294f112 | ||
|
|
b082ccfbd7 | ||
|
|
088b1c211e | ||
|
|
fcbd2545cb | ||
|
|
03bea7461d | ||
|
|
e4fe8c5112 | ||
|
|
21cd8e9e01 | ||
|
|
f95e7afb4e | ||
|
|
37b38daa00 | ||
|
|
6abd29b12d | ||
|
|
5c42308ca3 | ||
|
|
27e9f98862 | ||
|
|
a79ba3a0e4 | ||
|
|
960b223155 | ||
|
|
20dc8e0efc | ||
|
|
adf9cd7012 | ||
|
|
b5534b4a39 | ||
|
|
25320f8de1 | ||
|
|
feecf8d991 | ||
|
|
d2d5bcc59b | ||
|
|
ec60a9bb21 | ||
|
|
da2604e3d6 | ||
|
|
0f00bd6ba3 | ||
|
|
f3fcfd96d3 | ||
|
|
57528f9590 | ||
|
|
c0ce53a814 | ||
|
|
c081efd42e | ||
|
|
2a3417e31b | ||
|
|
0c4238dfb4 | ||
|
|
23aa11e316 | ||
|
|
3de8cd49b6 | ||
|
|
4500b10d7f | ||
|
|
71dbf77def | ||
|
|
de92d57f13 | ||
|
|
f818568bd3 | ||
|
|
9a1bd5f2f8 | ||
|
|
d3ca0622e4 | ||
|
|
7b6e378121 | ||
|
|
f58a6010d9 | ||
|
|
18968bf7c7 | ||
|
|
3a8f829de9 | ||
|
|
b6749e306b | ||
|
|
b4334c2835 | ||
|
|
79fa879eb6 | ||
|
|
26da3ae2f9 | ||
|
|
61d253638a | ||
|
|
8e73428458 | ||
|
|
64e7a5153e | ||
|
|
3b198c927c | ||
|
|
51f35bae56 | ||
|
|
8873705ce7 | ||
|
|
e194bd71cd | ||
|
|
520c810476 | ||
|
|
55370b26a0 | ||
|
|
381da07b46 | ||
|
|
21f6353188 | ||
|
|
ecfedff9d2 | ||
|
|
7d5ad7abfe | ||
|
|
72c6c004b0 | ||
|
|
04679a3406 | ||
|
|
3e58013ad6 | ||
|
|
12c50d5f6a | ||
|
|
06809933ed | ||
|
|
3921b3e654 | ||
|
|
e210bac2bf | ||
|
|
aa58cf8041 | ||
|
|
0a6d9e1ef9 | ||
|
|
5b52c817d7 | ||
|
|
4dde214f94 | ||
|
|
6369cb2b65 | ||
|
|
f538cebd03 | ||
|
|
ce310da9ca | ||
|
|
9dac3d01d9 | ||
|
|
bc3a622d1b | ||
|
|
ef276b8145 | ||
|
|
1b5584c585 | ||
|
|
5c975a339d | ||
|
|
3cdc932684 | ||
|
|
185f06822a | ||
|
|
f2ac1f1817 | ||
|
|
75a58f7e74 | ||
|
|
606bc093df | ||
|
|
8648e019a9 | ||
|
|
99de894d3f | ||
|
|
94c4e76823 | ||
|
|
a18503dfe9 | ||
|
|
b3357a2751 | ||
|
|
e711a9012b | ||
|
|
acb99b5c48 | ||
|
|
36babe51cc | ||
|
|
fb938c2b7d | ||
|
|
8384b6dd64 | ||
|
|
42b7d7e42e | ||
|
|
0a85bb5a7b | ||
|
|
89e87b7656 | ||
|
|
a2e0bb50b9 | ||
|
|
88dee1f544 | ||
|
|
f620e820e8 | ||
|
|
15486a1ea8 | ||
|
|
c121d0c4e2 | ||
|
|
09c2085270 | ||
|
|
14545818bd | ||
|
|
cb57e26d04 | ||
|
|
a6265d7ba3 | ||
|
|
4bd149c01b | ||
|
|
bc9342c2eb | ||
|
|
5edc9b5047 | ||
|
|
44118ec770 | ||
|
|
877fe2b275 | ||
|
|
86fe9fd6bb | ||
|
|
747918c4dc | ||
|
|
077fc3cb1d | ||
|
|
5e24a0cf36 | ||
|
|
0d871b16bf | ||
|
|
1f31ae94c1 | ||
|
|
549dfaa1b9 | ||
|
|
fc8e2e9e7f | ||
|
|
d9b63038dd | ||
|
|
1e8844a3e9 | ||
|
|
8f76e007e4 | ||
|
|
c2f9fdb47f | ||
|
|
2929b0b37a | ||
|
|
eca9cd9d16 | ||
|
|
9ec0f767a6 | ||
|
|
d397cabd51 | ||
|
|
f7d0fbcf33 | ||
|
|
ba520c3224 | ||
|
|
235722fb3a | ||
|
|
bb7791c691 | ||
|
|
024718e7f4 | ||
|
|
6c12c9e742 | ||
|
|
4764b8eb30 | ||
|
|
a94219cd0d | ||
|
|
755a9313e4 | ||
|
|
45eee2be66 | ||
|
|
69568160bc | ||
|
|
e54a9a83bb | ||
|
|
1e45d96253 | ||
|
|
6fdf9daf24 | ||
|
|
e330b517a8 | ||
|
|
ff54c6d9af | ||
|
|
0e4afecf1d | ||
|
|
53185b4833 | ||
|
|
c3e4e2b54f | ||
|
|
e91fe89e6a | ||
|
|
e5fc58366b | ||
|
|
df6beb4f15 | ||
|
|
9f8f742a0e | ||
|
|
0e6ece56c6 | ||
|
|
40a02b73e2 | ||
|
|
48f6c162d5 | ||
|
|
1569204d83 | ||
|
|
1de1c4e710 | ||
|
|
21e920426e | ||
|
|
ca5461c94f | ||
|
|
4510b3bbd1 | ||
|
|
0512588a7a | ||
|
|
0311dc5806 | ||
|
|
2f814c1903 | ||
|
|
6514b217b9 | ||
|
|
375c41daba | ||
|
|
b4c0859759 | ||
|
|
430ff7c3a8 | ||
|
|
e2b35d6d54 | ||
|
|
f39d843c70 | ||
|
|
2bcf3b03d5 | ||
|
|
90e146e7b0 | ||
|
|
8001a14d3a | ||
|
|
c7956a24a6 | ||
|
|
bc336abf9d | ||
|
|
c6b2797b5d | ||
|
|
52269705b5 | ||
|
|
89158cb10a | ||
|
|
fb5029796f | ||
|
|
dcd9572024 | ||
|
|
071cbc9890 | ||
|
|
55149ab5d1 | ||
|
|
7ed68b7efe | ||
|
|
c07e9e7006 | ||
|
|
cbc2b73625 | ||
|
|
a296a533c9 | ||
|
|
dd6a27b915 | ||
|
|
d826206d31 | ||
|
|
6506de70b8 | ||
|
|
d1f2c9695c | ||
|
|
0ebdfafccd | ||
|
|
2a5dd6dfd6 | ||
|
|
01e18e0221 | ||
|
|
6c8e15c014 | ||
|
|
f4ad421c2e | ||
|
|
cd28f69a0e | ||
|
|
21b1571868 | ||
|
|
e722279009 | ||
|
|
071d89cc15 | ||
|
|
1ed012331b | ||
|
|
121563ba24 | ||
|
|
19e2882c4a | ||
|
|
1fb52a4ae9 | ||
|
|
248dbf66da | ||
|
|
3beaf68815 | ||
|
|
eda8931b5f | ||
|
|
ce24c0a4ff | ||
|
|
45d05b9157 | ||
|
|
89464ce6c0 | ||
|
|
2dfdfb19d1 | ||
|
|
ff9f9b9660 | ||
|
|
8c2ef1084a | ||
|
|
e466ef6771 | ||
|
|
61405add97 | ||
|
|
0f774a68fc | ||
|
|
5a9b9a1feb | ||
|
|
f8c75dd79b | ||
|
|
f03d93d6a8 | ||
|
|
3be9104ec3 | ||
|
|
a23b199e7e | ||
|
|
a1f3f5184b | ||
|
|
331361f21e | ||
|
|
19fb0ff5b7 | ||
|
|
da4ee2e20d | ||
|
|
e1eda3ce19 | ||
|
|
7009bddc20 | ||
|
|
41d3361209 | ||
|
|
85874d4eb5 | ||
|
|
2a1a5643d3 | ||
|
|
85db3df355 | ||
|
|
befebdb9f7 | ||
|
|
9fcda980ee | ||
|
|
0b0dcdc58d | ||
|
|
ab1f0d7f92 | ||
|
|
09ab6458a1 | ||
|
|
910f3b3744 | ||
|
|
f4d7861a9d | ||
|
|
185d915928 | ||
|
|
d4100c61dc | ||
|
|
f16c8ae115 | ||
|
|
ac223cbb53 | ||
|
|
bc9fd53ae8 | ||
|
|
105d274955 | ||
|
|
5d682962be | ||
|
|
0cb5a993c7 | ||
|
|
2c00ecae9e | ||
|
|
356ae65b69 | ||
|
|
68cd3cd812 | ||
|
|
9dae4bae55 | ||
|
|
0e7a6c9fe1 | ||
|
|
6f9cafa141 | ||
|
|
b13919b7b3 | ||
|
|
bf3391a1a8 | ||
|
|
2d3106a256 | ||
|
|
ab1de29e47 | ||
|
|
64ba087cc5 | ||
|
|
3500b0f55f | ||
|
|
edc63b7200 | ||
|
|
70ed5a0717 | ||
|
|
20dd01f8e6 | ||
|
|
c2c571ae7e | ||
|
|
be23823404 | ||
|
|
8a3b0b9866 | ||
|
|
5b8e5ea338 | ||
|
|
540903d71f | ||
|
|
cac27535f8 | ||
|
|
171578ad9b | ||
|
|
0dc6f9aab3 | ||
|
|
eee9b32a5b | ||
|
|
91762bb1ba | ||
|
|
bd6953008b | ||
|
|
974cfc8c56 | ||
|
|
4d19e90c0d | ||
|
|
d76f5d40a4 | ||
|
|
2387ece1ff | ||
|
|
c05b6e60b8 | ||
|
|
0fcf37542b | ||
|
|
9054abadeb | ||
|
|
e541f4145a | ||
|
|
4c5e44fb22 | ||
|
|
12380d838b | ||
|
|
74cae17ebd | ||
|
|
af02b0ab1d | ||
|
|
2e5c4c3bf4 | ||
|
|
70583743ce | ||
|
|
55cd8cc5b3 | ||
|
|
4f7773eb3f | ||
|
|
095709b9d2 | ||
|
|
572e94cf33 | ||
|
|
45a4313b70 | ||
|
|
921ec259ee | ||
|
|
a38c2f83ef | ||
|
|
9449d1d0f3 | ||
|
|
69ee5eae48 | ||
|
|
f2673803ee | ||
|
|
aa05ef75bb | ||
|
|
dbafb2cace | ||
|
|
f127a2fa7c | ||
|
|
d644f72eae | ||
|
|
f91baaa6f6 | ||
|
|
de5b62343d | ||
|
|
0de310c5db | ||
|
|
3b7f9627eb | ||
|
|
90a542b6b1 | ||
|
|
f6598205fd | ||
|
|
943605c3e7 | ||
|
|
2ba3bd2148 | ||
|
|
aa4e565646 | ||
|
|
3a16fc3e4e | ||
|
|
74521c9672 | ||
|
|
07292b4d6b | ||
|
|
9b3f35f6b4 | ||
|
|
c9c44d6bf8 | ||
|
|
3f086c8046 | ||
|
|
71860e8dba | ||
|
|
a1038c0e5b | ||
|
|
3513c92a22 | ||
|
|
606cb060fa | ||
|
|
4f873437d8 | ||
|
|
1b755d7c87 | ||
|
|
8e9d2fedc5 | ||
|
|
6e2fe788d2 | ||
|
|
9f30438c4f | ||
|
|
6cce314341 |
No files matched your search
@@ -0,0 +1,44 @@
|
|||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
// Fix uppercase text in table cells
|
||||||
|
// Javadoc 11: method names are in th[scope="row"] a, not td a
|
||||||
|
function fixCase() {
|
||||||
|
document.querySelectorAll("th[scope='row'] a, td a, .memberNameLink a").forEach(function(el) {
|
||||||
|
var t = el.textContent.trim();
|
||||||
|
if (t.length > 2 && t === t.toUpperCase() && t.indexOf(" ") === -1) {
|
||||||
|
el.textContent = t.toLowerCase();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Correct navPadding = topNav height + subNav height
|
||||||
|
// Uses !important to override jQuery's inline style
|
||||||
|
function fixPadding() {
|
||||||
|
var topNav = document.querySelector(".topNav");
|
||||||
|
var subNav = document.querySelector(".subNav");
|
||||||
|
var pad = document.querySelector(".navPadding");
|
||||||
|
if (!pad) return;
|
||||||
|
var h = (topNav ? topNav.offsetHeight : 0) + (subNav ? subNav.offsetHeight : 0);
|
||||||
|
if (h > 0) {
|
||||||
|
pad.style.setProperty("padding-top", h + "px", "important");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
fixCase();
|
||||||
|
// Run fixPadding after jQuery has had its chance
|
||||||
|
setTimeout(fixPadding, 0);
|
||||||
|
setTimeout(fixPadding, 50);
|
||||||
|
setTimeout(fixPadding, 200);
|
||||||
|
|
||||||
|
// Use MutationObserver to permanently override any further jQuery writes
|
||||||
|
var pad = document.querySelector(".navPadding");
|
||||||
|
if (pad) {
|
||||||
|
var observer = new MutationObserver(function() {
|
||||||
|
fixPadding();
|
||||||
|
});
|
||||||
|
observer.observe(pad, { attributes: true, attributeFilter: ["style"] });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<div id="javadoc-header">
|
||||||
|
<a href="/CustomNPC-Plus/" class="header-brand">
|
||||||
|
<div class="header-title">
|
||||||
|
CustomNPC+
|
||||||
|
<span>Javadoc Reference</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a href="/CustomNPC-Plus/" class="header-back">
|
||||||
|
Back to Index
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,954 @@
|
|||||||
|
/* ============================================================
|
||||||
|
CustomNPC+ — Javadoc Theme (Javadoc 11)
|
||||||
|
Tokyo Night — Styled Edition
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* ── Tokyo Night palette ── */
|
||||||
|
--bg: #1a1b26;
|
||||||
|
--bg2: #1f2335;
|
||||||
|
--bg3: #24283b;
|
||||||
|
--bg-elevated: #292e42;
|
||||||
|
--border: #3b4261;
|
||||||
|
--border2: #414868;
|
||||||
|
--text: #c0caf5;
|
||||||
|
--text-mid: #a9b1d6;
|
||||||
|
--text-dim: #565f89;
|
||||||
|
--green: #9ece6a;
|
||||||
|
--green-dim: rgba(158, 206, 106, 0.12);
|
||||||
|
--blue: #7aa2f7;
|
||||||
|
--blue-dim: rgba(122, 162, 247, 0.12);
|
||||||
|
--amber: #e0af68;
|
||||||
|
--amber-dim: rgba(224, 175, 104, 0.10);
|
||||||
|
--purple: #bb9af7;
|
||||||
|
--purple-dim: rgba(187, 154, 247, 0.10);
|
||||||
|
--cyan: #7dcfff;
|
||||||
|
--cyan-dim: rgba(125, 207, 255, 0.10);
|
||||||
|
--red: #f7768e;
|
||||||
|
--highlight-bg: rgba(122, 162, 247, 0.08);
|
||||||
|
--hover-bg: rgba(187, 154, 247, 0.08);
|
||||||
|
--nav-h: 44px;
|
||||||
|
--subnav-h: 36px;
|
||||||
|
|
||||||
|
/* ── Font stacks ── */
|
||||||
|
--font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||||
|
--font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box !important; }
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--bg) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
line-height: 1.6 !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
min-height: 100vh !important;
|
||||||
|
display: flex !important;
|
||||||
|
flex-direction: column !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.skipNav { display: none !important; }
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
NAVIGATION
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
.fixedNav {
|
||||||
|
position: fixed !important;
|
||||||
|
top: 0 !important; left: 0 !important; right: 0 !important;
|
||||||
|
z-index: 100 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Top bar — gradient accent stripe on top */
|
||||||
|
.topNav {
|
||||||
|
position: relative !important;
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
margin: 0 !important; padding: 0 !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: stretch !important;
|
||||||
|
overflow: visible !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Gradient accent line across the very top */
|
||||||
|
.topNav::before {
|
||||||
|
content: '' !important;
|
||||||
|
position: absolute !important;
|
||||||
|
top: 0 !important; left: 0 !important; right: 0 !important;
|
||||||
|
height: 2px !important;
|
||||||
|
background: linear-gradient(90deg, var(--blue), var(--purple), var(--cyan)) !important;
|
||||||
|
z-index: 10 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Nav list — leave room on right for brand */
|
||||||
|
.topNav > ul.navList {
|
||||||
|
list-style: none !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 2px 0 0 8px !important;
|
||||||
|
padding-right: 320px !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: stretch !important;
|
||||||
|
flex-shrink: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topNav > ul.navList > li {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 16px !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
letter-spacing: 0.01em !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
border-bottom: 2px solid transparent !important;
|
||||||
|
transition: color 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topNav > ul.navList > li > a {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
margin: 0 -16px !important;
|
||||||
|
padding: 0 16px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
letter-spacing: 0.01em !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
border-bottom: 2px solid transparent !important;
|
||||||
|
transition: color 0.2s, border-color 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topNav > ul.navList > li > a:hover {
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-bottom-color: var(--purple) !important;
|
||||||
|
background: transparent !important;
|
||||||
|
text-shadow: none !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Active item — gradient underline */
|
||||||
|
.topNav > ul.navList > li.navBarCell1Rev {
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-image: linear-gradient(90deg, var(--blue), var(--purple)) 1 !important;
|
||||||
|
border-bottom-width: 2px !important;
|
||||||
|
border-bottom-style: solid !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Brand — pinned to far right of topNav ── */
|
||||||
|
.topNav > .aboutLanguage {
|
||||||
|
position: absolute !important;
|
||||||
|
top: 0 !important; right: 0 !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
gap: 12px !important;
|
||||||
|
padding: 0 16px !important;
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border-left: 1px solid var(--border) !important;
|
||||||
|
z-index: 5 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide the duplicate in bottom nav */
|
||||||
|
.bottomNav > .aboutLanguage,
|
||||||
|
.bottomNav .aboutLanguage {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#javadoc-header {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
gap: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-brand { text-decoration: none !important; }
|
||||||
|
|
||||||
|
/* Brand title — gradient text */
|
||||||
|
.header-title {
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 14px !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
background: linear-gradient(135deg, var(--blue), var(--purple)) !important;
|
||||||
|
-webkit-background-clip: text !important;
|
||||||
|
-webkit-text-fill-color: transparent !important;
|
||||||
|
background-clip: text !important;
|
||||||
|
line-height: 1.4 !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-title span {
|
||||||
|
display: block !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 9px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
|
background: none !important;
|
||||||
|
-webkit-text-fill-color: var(--text-dim) !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
margin-top: 1px !important;
|
||||||
|
letter-spacing: 0.1em !important;
|
||||||
|
text-transform: uppercase !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-back {
|
||||||
|
display: inline-flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
padding: 5px 12px !important;
|
||||||
|
border: 1px solid var(--border2) !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
transition: all 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-back:hover {
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-color: var(--purple) !important;
|
||||||
|
background: var(--purple-dim) !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
text-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Sub nav ── */
|
||||||
|
.subNav {
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
height: var(--subnav-h) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 14px !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
gap: 12px !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search first */
|
||||||
|
.subNav > ul.navListSearch {
|
||||||
|
order: -1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subNav ul,
|
||||||
|
.subNav ul.navList,
|
||||||
|
.subNav ul.subNavList,
|
||||||
|
.subNav ul.navListSearch {
|
||||||
|
list-style: none !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
gap: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subNav li {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
padding: 0 6px !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
border: none !important;
|
||||||
|
height: auto !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subNav a {
|
||||||
|
color: var(--blue) !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
transition: color 0.15s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subNav a:hover { color: var(--purple) !important; text-shadow: none !important; }
|
||||||
|
|
||||||
|
.subNav label {
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
margin-right: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
CONTENT
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
main {
|
||||||
|
background: var(--bg) !important;
|
||||||
|
padding: 28px !important;
|
||||||
|
flex: 1 0 auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.contentContainer, div.contentContainer {
|
||||||
|
background: var(--bg) !important;
|
||||||
|
padding: 0 28px 0px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
padding: 0 28px 0 !important;
|
||||||
|
margin-bottom: 20px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subtitle under h1 on help/overview pages */
|
||||||
|
.header .subTitle,
|
||||||
|
div.subTitle {
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
line-height: 1.7 !important;
|
||||||
|
margin-top: 8px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.packageLabelInType {
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Headings ── */
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
letter-spacing: -0.01em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Page title — gradient accent bar */
|
||||||
|
h1.title, h2.title {
|
||||||
|
font-size: 22px !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
padding-bottom: 16px !important;
|
||||||
|
padding-left: 16px !important;
|
||||||
|
margin-bottom: 24px !important;
|
||||||
|
margin-top: 0 !important;
|
||||||
|
border-left: 4px solid transparent !important;
|
||||||
|
border-image: linear-gradient(180deg, var(--blue), var(--purple)) 1 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Section h2 — colored panel */
|
||||||
|
section > h2,
|
||||||
|
li.blockList > section > h2 {
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: var(--green) !important;
|
||||||
|
border-left: 3px solid var(--green) !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
background: var(--green-dim) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generic h2 (table section headers like "Method Summary") */
|
||||||
|
h2 {
|
||||||
|
font-size: 14px !important;
|
||||||
|
color: var(--amber) !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
border-left: 3px solid var(--amber) !important;
|
||||||
|
padding: 8px 12px !important;
|
||||||
|
margin-top: 28px !important;
|
||||||
|
margin-bottom: 12px !important;
|
||||||
|
background: var(--amber-dim) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* h3 — table section headers inside blockList */
|
||||||
|
h3 {
|
||||||
|
font-size: 12px !important;
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* h4 — method detail names */
|
||||||
|
h4 {
|
||||||
|
font-size: 13px !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
color: var(--cyan) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
border-left: 3px solid var(--cyan) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── blockList sections — card-like containers ── */
|
||||||
|
ul.blockList > li.blockList,
|
||||||
|
ul.blockListLast > li.blockList {
|
||||||
|
border: 1px solid var(--border) !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
margin-bottom: 14px !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Help page: section cards with padding around their content */
|
||||||
|
ul.blockList > li.blockList > section {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.blockList > li.blockList > section > p,
|
||||||
|
ul.blockList > li.blockList > section > ul:not(.blockList):not(.blockListLast) {
|
||||||
|
padding: 14px 18px !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
line-height: 1.7 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Nested lists inside section content */
|
||||||
|
ul.blockList > li.blockList > section > ul:not(.blockList):not(.blockListLast) > li {
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
padding: 3px 0 !important;
|
||||||
|
list-style: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.blockList > li.blockList > section > ul:not(.blockList):not(.blockListLast) > li::before {
|
||||||
|
content: '\203A' !important;
|
||||||
|
color: var(--purple) !important;
|
||||||
|
margin-right: 8px !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Inherited methods block ── */
|
||||||
|
ul.blockList > li.blockList > h3,
|
||||||
|
ul.blockList > li.blockList > ul.blockList > li.blockList > h3 {
|
||||||
|
font-size: 11px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
padding: 8px 14px !important;
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The comma-separated code block of inherited method names */
|
||||||
|
ul.blockList > li.blockList > code,
|
||||||
|
li.blockList > code {
|
||||||
|
display: block !important;
|
||||||
|
padding: 10px 16px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
background: var(--bg) !important;
|
||||||
|
border: none !important;
|
||||||
|
line-height: 1.8 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Inheritance chain ── */
|
||||||
|
ul.inheritance {
|
||||||
|
list-style: none !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
margin: 0 0 16px !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
}
|
||||||
|
ul.inheritance li { padding-left: 16px !important; }
|
||||||
|
ul.inheritance li:first-child { padding-left: 0 !important; }
|
||||||
|
|
||||||
|
/* ── General content lists (help page) ── */
|
||||||
|
main ul:not(.blockList):not(.blockListLast):not(.navList):not(.subNavList):not(.navListSearch):not(.inheritance) {
|
||||||
|
padding-left: 0 !important;
|
||||||
|
margin: 4px 0 4px 12px !important;
|
||||||
|
list-style: none !important;
|
||||||
|
}
|
||||||
|
main ul:not(.blockList):not(.blockListLast):not(.navList):not(.subNavList):not(.navListSearch):not(.inheritance) > li {
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
padding: 3px 0 !important;
|
||||||
|
line-height: 1.7 !important;
|
||||||
|
}
|
||||||
|
main ul:not(.blockList):not(.blockListLast):not(.navList):not(.subNavList):not(.navListSearch):not(.inheritance) > li::before {
|
||||||
|
content: '\203A' !important;
|
||||||
|
color: var(--purple) !important;
|
||||||
|
margin-right: 8px !important;
|
||||||
|
font-weight: 700 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* General paragraphs in content */
|
||||||
|
main > div p, .contentContainer p {
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
line-height: 1.7 !important;
|
||||||
|
margin: 8px 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Emphasized phrase */
|
||||||
|
.emphasizedPhrase {
|
||||||
|
display: block !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-style: italic !important;
|
||||||
|
border-left: 2px solid var(--purple) !important;
|
||||||
|
padding: 8px 14px !important;
|
||||||
|
margin-top: 16px !important;
|
||||||
|
background: var(--purple-dim) !important;
|
||||||
|
border-radius: 0 4px 4px 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bottom footer subNav */
|
||||||
|
footer {
|
||||||
|
/*margin-top: auto;*/
|
||||||
|
}
|
||||||
|
footer .subNav {
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border-top: 1px solid var(--border) !important;
|
||||||
|
border-bottom: none !important;
|
||||||
|
height: var(--subnav-h) !important;
|
||||||
|
padding: 0 14px !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
gap: 12px !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
TABLES
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100% !important;
|
||||||
|
border-collapse: collapse !important;
|
||||||
|
border: 1px solid var(--border) !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
margin: 16px 0 !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
caption {
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
padding: 8px 14px !important;
|
||||||
|
text-align: left !important;
|
||||||
|
border-bottom: 1px solid var(--border2) !important;
|
||||||
|
caption-side: top !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Table tabs — pill style */
|
||||||
|
.activeTableTab, .tableTab {
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
padding: 4px 12px !important;
|
||||||
|
border: 1px solid var(--border2) !important;
|
||||||
|
border-radius: 20px !important;
|
||||||
|
display: inline-block !important;
|
||||||
|
margin-right: 6px !important;
|
||||||
|
cursor: pointer !important;
|
||||||
|
transition: all 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activeTableTab {
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-color: var(--blue) !important;
|
||||||
|
background: var(--blue-dim) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tableTab { color: var(--text-dim) !important; background: var(--bg3) !important; }
|
||||||
|
.tableTab a { color: var(--text-dim) !important; text-decoration: none !important; }
|
||||||
|
.tableTab a:hover { color: var(--text) !important; text-shadow: none !important; }
|
||||||
|
|
||||||
|
/* Column headers */
|
||||||
|
th[scope="col"] {
|
||||||
|
background: var(--bg-elevated) !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 10px !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
letter-spacing: 0.06em !important;
|
||||||
|
text-transform: uppercase !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
border-bottom: 2px solid var(--border2) !important;
|
||||||
|
text-align: left !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Data cells */
|
||||||
|
th[scope="row"], td {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
vertical-align: top !important;
|
||||||
|
text-align: left !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-weight: 400 !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
letter-spacing: 0 !important;
|
||||||
|
transition: background 0.15s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Stronger alternating row contrast */
|
||||||
|
tr.altColor > td, tr.altColor > th[scope="row"] { background: var(--bg) !important; }
|
||||||
|
tr.rowColor > td, tr.rowColor > th[scope="row"] { background: var(--bg2) !important; }
|
||||||
|
|
||||||
|
tr:hover > td, tr:hover > th[scope="row"] {
|
||||||
|
background: var(--purple-dim) !important;
|
||||||
|
border-bottom-color: rgba(187, 154, 247, 0.25) !important;
|
||||||
|
}
|
||||||
|
tr:hover > td a, tr:hover > th[scope="row"] a {
|
||||||
|
color: var(--purple) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Links ── */
|
||||||
|
a, a:visited { color: var(--blue) !important; text-decoration: none !important; transition: color 0.15s !important; }
|
||||||
|
a:hover { color: var(--purple) !important; text-decoration: none !important; }
|
||||||
|
.memberNameLink a { color: var(--cyan) !important; font-weight: 500 !important; }
|
||||||
|
.memberNameLink a:hover { color: var(--purple) !important; }
|
||||||
|
.externalLink { color: var(--blue) !important; }
|
||||||
|
|
||||||
|
/* ── Description blocks ── */
|
||||||
|
div.block {
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
line-height: 1.7 !important;
|
||||||
|
padding: 4px 0 !important;
|
||||||
|
}
|
||||||
|
ul.blockList > li.blockList > div.block{ padding: 12px 16px !important; margin: 0 !important; }
|
||||||
|
|
||||||
|
/* ── Method detail ── */
|
||||||
|
ul.blockList, ul.blockListLast { list-style: none !important; padding: 0 !important; margin: 0 !important; }
|
||||||
|
ul.blockList > li.blockList, ul.blockListLast > li.blockList {
|
||||||
|
border: 1px solid var(--border) !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
margin-bottom: 12px !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Method/type signatures — accent left bar */
|
||||||
|
pre.methodSignature, pre.typeSignature {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border: none !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
border-left: 3px solid var(--cyan) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 14px 18px !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
overflow-x: auto !important;
|
||||||
|
white-space: pre-wrap !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border: 1px solid var(--border) !important;
|
||||||
|
border-left: 3px solid var(--blue) !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
padding: 14px 18px !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
overflow-x: auto !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
white-space: pre-wrap !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
color: var(--cyan) !important;
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
padding: 2px 6px !important;
|
||||||
|
border-radius: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl { padding: 12px 16px !important; margin: 0 !important; }
|
||||||
|
dt { margin-bottom: 4px !important; }
|
||||||
|
dd { margin: 0 0 8px 16px !important; color: var(--text-mid) !important; font-size: 12px !important; }
|
||||||
|
|
||||||
|
.paramLabel, .returnLabel, .throwsLabel, .seeLabel, .simpleTagLabel {
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 10px !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
color: var(--purple) !important;
|
||||||
|
text-transform: uppercase !important;
|
||||||
|
letter-spacing: 0.06em !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.typeNameLabel { color: var(--cyan) !important; }
|
||||||
|
|
||||||
|
.deprecationBlock {
|
||||||
|
background: var(--amber-dim) !important;
|
||||||
|
border-left: 3px solid var(--amber) !important;
|
||||||
|
border-radius: 0 6px 6px 0 !important;
|
||||||
|
padding: 10px 14px !important;
|
||||||
|
color: var(--amber) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Inputs ── */
|
||||||
|
input[type="text"] {
|
||||||
|
background: var(--bg) !important;
|
||||||
|
border: 1px solid var(--border2) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
padding: 5px 12px !important;
|
||||||
|
outline: none !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
transition: border-color 0.2s, box-shadow 0.2s !important;
|
||||||
|
}
|
||||||
|
input[type="text"]:focus {
|
||||||
|
border-color: var(--blue) !important;
|
||||||
|
box-shadow: 0 0 0 2px var(--blue-dim) !important;
|
||||||
|
}
|
||||||
|
input[type="reset"] {
|
||||||
|
background: var(--bg3) !important;
|
||||||
|
border: 1px solid var(--border2) !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
padding: 5px 12px !important;
|
||||||
|
cursor: pointer !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
transition: all 0.2s !important;
|
||||||
|
}
|
||||||
|
input[type="reset"]:hover {
|
||||||
|
border-color: var(--text-dim) !important;
|
||||||
|
color: var(--text-mid) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
BOTTOM NAV
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
.bottomNav {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border-top: 1px solid var(--border) !important;
|
||||||
|
min-height: var(--nav-h) !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
margin-top: 32px !important;
|
||||||
|
overflow: hidden !important;
|
||||||
|
position: relative !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Gradient accent line on bottom nav too */
|
||||||
|
.bottomNav::after {
|
||||||
|
content: '' !important;
|
||||||
|
position: absolute !important;
|
||||||
|
bottom: 0 !important; left: 0 !important; right: 0 !important;
|
||||||
|
height: 2px !important;
|
||||||
|
background: linear-gradient(90deg, var(--blue), var(--purple), var(--cyan)) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav ul.navList[title="Navigation"] {
|
||||||
|
list-style: none !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 0 0 8px !important;
|
||||||
|
display: flex !important;
|
||||||
|
align-items: stretch !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav ul.navList[title="Navigation"] li {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
padding: 0 16px !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
white-space: nowrap !important;
|
||||||
|
text-transform: none !important;
|
||||||
|
letter-spacing: 0.01em !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
border-top: 2px solid transparent !important;
|
||||||
|
transition: color 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav ul.navList[title="Navigation"] li > a {
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
height: var(--nav-h) !important;
|
||||||
|
margin: 0 -16px !important;
|
||||||
|
padding: 0 16px !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
text-decoration: none !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
font-weight: 500 !important;
|
||||||
|
transition: color 0.2s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav ul.navList[title="Navigation"] li > a:hover {
|
||||||
|
color: var(--text) !important;
|
||||||
|
text-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav ul.navList[title="Navigation"] li.navBarCell1Rev {
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-image: linear-gradient(90deg, var(--blue), var(--purple)) 1 !important;
|
||||||
|
border-top-width: 2px !important;
|
||||||
|
border-top-style: solid !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bottomNav .aboutLanguage {
|
||||||
|
display: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legalCopy {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
padding: 14px 18px !important;
|
||||||
|
text-align: center !important;
|
||||||
|
border-top: 1px solid var(--border) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
SEARCH RESULTS DROPDOWN (jQuery UI Autocomplete)
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
.ui-autocomplete {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
border: 1px solid var(--border2) !important;
|
||||||
|
border-radius: 8px !important;
|
||||||
|
max-height: 400px !important;
|
||||||
|
overflow-y: auto !important;
|
||||||
|
overflow-x: hidden !important;
|
||||||
|
z-index: 9999 !important;
|
||||||
|
list-style: none !important;
|
||||||
|
padding: 4px 0 !important;
|
||||||
|
margin: 4px 0 0 !important;
|
||||||
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(122, 162, 247, 0.05) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Category headers */
|
||||||
|
.ui-autocomplete .ui-autocomplete-category {
|
||||||
|
background: var(--bg-elevated) !important;
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-family: var(--font-ui) !important;
|
||||||
|
font-size: 10px !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
text-transform: uppercase !important;
|
||||||
|
letter-spacing: 0.06em !important;
|
||||||
|
padding: 6px 14px !important;
|
||||||
|
border-bottom: 1px solid var(--border) !important;
|
||||||
|
border-top: 1px solid var(--border) !important;
|
||||||
|
cursor: default !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Individual result items */
|
||||||
|
.ui-autocomplete .ui-menu-item {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
list-style: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-autocomplete .ui-menu-item > div,
|
||||||
|
.ui-autocomplete .ui-menu-item-wrapper {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
font-size: 12px !important;
|
||||||
|
padding: 7px 14px !important;
|
||||||
|
border: none !important;
|
||||||
|
border-left: 2px solid transparent !important;
|
||||||
|
cursor: pointer !important;
|
||||||
|
line-height: 1.5 !important;
|
||||||
|
transition: all 0.1s !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hover / focus state */
|
||||||
|
.ui-autocomplete .ui-menu-item > div.ui-state-active,
|
||||||
|
.ui-autocomplete .ui-menu-item > div.ui-state-focus,
|
||||||
|
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active,
|
||||||
|
.ui-autocomplete .ui-menu-item-wrapper.ui-state-focus,
|
||||||
|
.ui-autocomplete .ui-state-active,
|
||||||
|
.ui-autocomplete .ui-state-focus {
|
||||||
|
background: var(--purple-dim) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
border: none !important;
|
||||||
|
border-left: 2px solid var(--purple) !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Highlighted matching text */
|
||||||
|
.resultHighlight {
|
||||||
|
color: var(--cyan) !important;
|
||||||
|
font-weight: 600 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search tag result extras */
|
||||||
|
.searchTagHolderResult {
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.searchTagDescResult {
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-size: 11px !important;
|
||||||
|
font-style: italic !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "No results found" */
|
||||||
|
.ui-autocomplete .ui-menu-item:only-child > div {
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
font-style: italic !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Override jQuery UI defaults */
|
||||||
|
.ui-widget {
|
||||||
|
font-family: var(--font-mono) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-widget-content {
|
||||||
|
background: var(--bg2) !important;
|
||||||
|
color: var(--text) !important;
|
||||||
|
border-color: var(--border2) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ui-menu .ui-menu-item {
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Watermark style for search input placeholder */
|
||||||
|
.watermark {
|
||||||
|
color: var(--text-dim) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ══════════════════════════════════════════════
|
||||||
|
MISC
|
||||||
|
══════════════════════════════════════════════ */
|
||||||
|
|
||||||
|
::-webkit-scrollbar { width: 8px; height: 8px; }
|
||||||
|
::-webkit-scrollbar-track { background: var(--bg); }
|
||||||
|
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
|
||||||
|
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
|
||||||
|
::selection { background: rgba(187, 154, 247, 0.25); color: var(--text); }
|
||||||
|
hr { border: none !important; border-top: 1px solid var(--border) !important; margin: 24px 0 !important; }
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Javadoc Index</title>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300;400;500;600&family=IBM+Plex+Sans:ital,wght@0,300;0,600;1,300&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "javadoc-index",
|
||||||
|
"private": true,
|
||||||
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^18.2.0",
|
||||||
|
"react-dom": "^18.2.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@vitejs/plugin-react": "^4.2.1",
|
||||||
|
"vite": "^7.3.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import styles from './App.module.css'
|
||||||
|
import { useDocs } from './useDocs'
|
||||||
|
import TerminalHeader from './components/TerminalHeader'
|
||||||
|
import Section from './components/Section'
|
||||||
|
import { ReleaseCard, ExperimentalCard } from './components/Card'
|
||||||
|
import { LoadingState, ErrorState, EmptyState } from './components/States'
|
||||||
|
import Footer from './components/Footer'
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
const { data, loading, error } = useDocs()
|
||||||
|
|
||||||
|
const releases = data?.releases || []
|
||||||
|
const experimental = data?.experimental || []
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.root}>
|
||||||
|
<TerminalHeader />
|
||||||
|
|
||||||
|
{/* ── Releases ── */}
|
||||||
|
<Section
|
||||||
|
label="Release"
|
||||||
|
variant="releases"
|
||||||
|
count={loading ? undefined : releases.length}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<LoadingState />
|
||||||
|
) : error ? (
|
||||||
|
<ErrorState message={error} />
|
||||||
|
) : releases.length === 0 ? (
|
||||||
|
<EmptyState label="releases" />
|
||||||
|
) : (
|
||||||
|
<div className={styles.grid}>
|
||||||
|
{releases.map((r, i) => (
|
||||||
|
<ReleaseCard key={r.id} release={r} index={i} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{/* ── Experimental ── */}
|
||||||
|
<Section
|
||||||
|
label="Experimental"
|
||||||
|
variant="experimental"
|
||||||
|
count={loading ? undefined : experimental.length}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<LoadingState />
|
||||||
|
) : error ? null : experimental.length === 0 ? (
|
||||||
|
<EmptyState label="experimental branches" />
|
||||||
|
) : (
|
||||||
|
<div className={styles.grid}>
|
||||||
|
{experimental.map((b, i) => (
|
||||||
|
<ExperimentalCard key={b.id} branch={b} index={i} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
|
||||||
|
{!loading && !error && (
|
||||||
|
<Footer source={data?.source} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
.root {
|
||||||
|
max-width: 1100px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 48px 32px 96px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.root { padding: 24px 16px 64px; }
|
||||||
|
.grid { grid-template-columns: 1fr; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import styles from './Card.module.css'
|
||||||
|
import { REPO_NAME } from '../config'
|
||||||
|
|
||||||
|
const BASE_PATH = `/${REPO_NAME}`
|
||||||
|
|
||||||
|
function formatDate(iso) {
|
||||||
|
if (!iso) return null
|
||||||
|
try {
|
||||||
|
return new Intl.DateTimeFormat('en-GB', {
|
||||||
|
day: '2-digit', month: 'short', year: 'numeric'
|
||||||
|
}).format(new Date(iso))
|
||||||
|
} catch (e) { return null }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReleaseCard({ release, index }) {
|
||||||
|
const isLatest = release.isLatest
|
||||||
|
const date = formatDate(release.date)
|
||||||
|
const cardClass = isLatest
|
||||||
|
? styles.card + ' ' + styles.latest
|
||||||
|
: styles.card + ' ' + styles.release
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={BASE_PATH + '/' + release.path + '/'}
|
||||||
|
className={cardClass}
|
||||||
|
style={{ animationDelay: (index * 50) + 'ms' }}
|
||||||
|
>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div className={styles.badges}>
|
||||||
|
{isLatest && (
|
||||||
|
<span className={styles.badge + ' ' + styles.badgeLatest}>● latest</span>
|
||||||
|
)}
|
||||||
|
<span className={styles.badge + ' ' + styles.badgeRelease}>release</span>
|
||||||
|
</div>
|
||||||
|
<span className={styles.arrow}>→</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.version}>
|
||||||
|
v{release.version}
|
||||||
|
</div>
|
||||||
|
<div className={styles.meta}>
|
||||||
|
{date && (
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaKey}>date</span>
|
||||||
|
<span className={styles.metaVal}>{date}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaKey}>path</span>
|
||||||
|
<span className={styles.metaVal}>{release.path}/</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ExperimentalCard({ branch, index }) {
|
||||||
|
const date = formatDate(branch.date)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={BASE_PATH + '/' + branch.path + '/'}
|
||||||
|
className={styles.card + ' ' + styles.experimental}
|
||||||
|
style={{ animationDelay: (index * 50) + 'ms' }}
|
||||||
|
>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<span className={styles.badge + ' ' + styles.badgeExperimental}>
|
||||||
|
experimental
|
||||||
|
</span>
|
||||||
|
<span className={styles.arrow}>→</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.version + ' ' + styles.versionBranch}>
|
||||||
|
{branch.branch}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.meta}>
|
||||||
|
{date && (
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaKey}>date</span>
|
||||||
|
<span className={styles.metaVal}>{date}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{branch.hash && (
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaKey}>sha</span>
|
||||||
|
<span className={styles.metaVal + ' ' + styles.hash}>{branch.hash}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaKey}>path</span>
|
||||||
|
<span className={styles.metaVal}>{branch.path}/</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
.card {
|
||||||
|
display: block;
|
||||||
|
text-decoration: none;
|
||||||
|
background: var(--bg2);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 20px 22px;
|
||||||
|
transition: border-color 0.15s, background 0.15s, transform 0.15s;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
animation: fadeUp 0.35s ease both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0; left: 0; right: 0;
|
||||||
|
height: 2px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.release::before { background: var(--green); }
|
||||||
|
.latest::before { background: linear-gradient(90deg, var(--green), var(--blue)); }
|
||||||
|
.experimental::before { background: var(--amber); }
|
||||||
|
|
||||||
|
.card:hover {
|
||||||
|
border-color: var(--border2);
|
||||||
|
background: var(--bg3);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.card:hover::before { opacity: 1; }
|
||||||
|
|
||||||
|
/* ── Header ── */
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badges {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
font-size: 9px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.12em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 2px;
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badgeLatest {
|
||||||
|
color: var(--green);
|
||||||
|
border-color: var(--green-dim);
|
||||||
|
background: rgba(57, 211, 83, 0.08);
|
||||||
|
animation: pulseBorder 2s ease infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badgeRelease {
|
||||||
|
color: var(--text-dim);
|
||||||
|
border-color: var(--border2);
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badgeExperimental {
|
||||||
|
color: var(--amber);
|
||||||
|
border-color: var(--amber-dim);
|
||||||
|
background: rgba(240, 160, 48, 0.08);
|
||||||
|
}
|
||||||
|
|
||||||
|
.arrow {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--border2);
|
||||||
|
transition: color 0.15s, transform 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card:hover .arrow {
|
||||||
|
color: var(--text-mid);
|
||||||
|
transform: translateX(3px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Version ── */
|
||||||
|
.version {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text);
|
||||||
|
margin-bottom: 4px;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.latest .version { color: var(--green); }
|
||||||
|
.versionBranch { font-size: 16px; color: var(--amber); }
|
||||||
|
|
||||||
|
/* ── Meta ── */
|
||||||
|
.meta {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 3px;
|
||||||
|
margin-top: 12px;
|
||||||
|
padding-top: 12px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaKey {
|
||||||
|
min-width: 36px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaVal {
|
||||||
|
color: var(--text-mid);
|
||||||
|
font-family: 'IBM Plex Mono', monospace;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hash { color: var(--blue); }
|
||||||
|
|
||||||
|
/* ── Animations ── */
|
||||||
|
@keyframes fadeUp {
|
||||||
|
from { opacity: 0; transform: translateY(10px); }
|
||||||
|
to { opacity: 1; transform: translateY(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulseBorder {
|
||||||
|
0%, 100% { border-color: var(--green-dim); }
|
||||||
|
50% { border-color: var(--green); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import styles from './Footer.module.css'
|
||||||
|
import { REPO_OWNER, REPO_NAME } from '../useDocs'
|
||||||
|
|
||||||
|
export default function Footer({ source }) {
|
||||||
|
const now = new Intl.DateTimeFormat('en-GB', {
|
||||||
|
day: '2-digit', month: 'short', year: 'numeric',
|
||||||
|
hour: '2-digit', minute: '2-digit', timeZoneName: 'short'
|
||||||
|
}).format(new Date())
|
||||||
|
|
||||||
|
return (
|
||||||
|
<footer className={styles.footer}>
|
||||||
|
<span>
|
||||||
|
<span className={styles.dot} />
|
||||||
|
Auto-generated · {source === 'manifest' ? 'manifest.json' : 'GitHub API'}
|
||||||
|
</span>
|
||||||
|
<span>{now}</span>
|
||||||
|
<span>Template by:
|
||||||
|
<a
|
||||||
|
href={`https://github.com/somehussar/`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className={styles.link}
|
||||||
|
>
|
||||||
|
github.com/somehussar
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
</footer>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
.footer {
|
||||||
|
margin-top: 64px;
|
||||||
|
padding-top: 20px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 8px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
display: inline-block;
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--green);
|
||||||
|
margin-right: 6px;
|
||||||
|
animation: blink 2s ease infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: var(--blue);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes blink {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0.3; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import styles from './Section.module.css'
|
||||||
|
|
||||||
|
export default function Section({ label, count, variant, children }) {
|
||||||
|
return (
|
||||||
|
<section className={styles.section}>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<span className={`${styles.tag} ${styles[variant]}`}>{label}</span>
|
||||||
|
<div className={styles.line} />
|
||||||
|
{count !== undefined && (
|
||||||
|
<span className={styles.count}>
|
||||||
|
{count} {label.toLowerCase()}{count !== 1 ? 's' : ''}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{children}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
.section {
|
||||||
|
margin-top: 40px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tag {
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.15em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
padding: 3px 10px;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.releases {
|
||||||
|
color: var(--green);
|
||||||
|
border-color: var(--green-dim);
|
||||||
|
background: rgba(57, 211, 83, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.experimental {
|
||||||
|
color: var(--amber);
|
||||||
|
border-color: var(--amber-dim);
|
||||||
|
background: rgba(240, 160, 48, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
flex: 1;
|
||||||
|
height: 1px;
|
||||||
|
background: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.count {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import styles from './States.module.css'
|
||||||
|
|
||||||
|
export function LoadingState() {
|
||||||
|
return (
|
||||||
|
<div className={styles.box}>
|
||||||
|
<div className={styles.spinner} />
|
||||||
|
<p className={styles.label}>Fetching documentation index...</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ErrorState({ message }) {
|
||||||
|
return (
|
||||||
|
<div className={styles.box}>
|
||||||
|
<div className={styles.errorIcon}>⚠</div>
|
||||||
|
<p className={styles.errorMsg}>{message}</p>
|
||||||
|
<p className={styles.errorSub}>
|
||||||
|
Check that the gh-pages branch exists and is publicly accessible.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function EmptyState({ label }) {
|
||||||
|
return (
|
||||||
|
<div className={`${styles.box} ${styles.empty}`}>
|
||||||
|
<p className={styles.label}>No {label} found.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
.box {
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 48px;
|
||||||
|
text-align: center;
|
||||||
|
background: var(--bg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 22px;
|
||||||
|
height: 22px;
|
||||||
|
border: 2px solid var(--border2);
|
||||||
|
border-top-color: var(--green);
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.75s linear infinite;
|
||||||
|
margin: 0 auto 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorIcon {
|
||||||
|
font-size: 22px;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
color: var(--red);
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorMsg {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--red);
|
||||||
|
margin-bottom: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.errorSub {
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import styles from './TerminalHeader.module.css'
|
||||||
|
import { PROJECT_NAME, REPO_NAME, LINKS, AUTHORS } from '../config'
|
||||||
|
|
||||||
|
function useGitHubProfile(username) {
|
||||||
|
const [profile, setProfile] = useState(null)
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const cacheKey = 'gh-profile-' + username
|
||||||
|
|
||||||
|
// Check sessionStorage first — avoids hammering the API on every render
|
||||||
|
try {
|
||||||
|
const cached = sessionStorage.getItem(cacheKey)
|
||||||
|
if (cached) {
|
||||||
|
setProfile(JSON.parse(cached))
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
fetch('https://api.github.com/users/' + username)
|
||||||
|
.then(r => {
|
||||||
|
if (!r.ok) throw new Error('HTTP ' + r.status)
|
||||||
|
return r.json()
|
||||||
|
})
|
||||||
|
.then(d => {
|
||||||
|
// Don't cache error responses like rate limit messages
|
||||||
|
if (!d.message) {
|
||||||
|
try { sessionStorage.setItem(cacheKey, JSON.stringify(d)) } catch (e) {}
|
||||||
|
}
|
||||||
|
setProfile(d)
|
||||||
|
setLoading(false)
|
||||||
|
})
|
||||||
|
.catch(() => setLoading(false))
|
||||||
|
}, [username])
|
||||||
|
|
||||||
|
return { profile, loading }
|
||||||
|
}
|
||||||
|
|
||||||
|
function AuthorTile({ username, active }) {
|
||||||
|
const { profile, loading } = useGitHubProfile(username)
|
||||||
|
const tileClass = styles.authorTile + (active ? ' ' + styles.authorTileActive : '')
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div className={tileClass}>
|
||||||
|
<div className={styles.authorAvatarSkeleton} />
|
||||||
|
<div className={styles.authorInfo}>
|
||||||
|
<div className={styles.authorSkeleton} style={{ width: '60px' }} />
|
||||||
|
<div className={styles.authorSkeleton} style={{ width: '80px', marginTop: '4px' }} />
|
||||||
|
<div className={styles.authorBioPlaceholder} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!profile || profile.message) {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={'https://github.com/' + username}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className={tileClass}
|
||||||
|
>
|
||||||
|
<div className={styles.authorAvatarSkeleton} />
|
||||||
|
<div className={styles.authorInfo}>
|
||||||
|
<span className={styles.authorName}>{username}</span>
|
||||||
|
<span className={styles.authorLogin}>@{username}</span>
|
||||||
|
<div className={styles.authorBioPlaceholder} />
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={profile.html_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className={tileClass}
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src={profile.avatar_url}
|
||||||
|
alt={profile.login}
|
||||||
|
className={styles.authorAvatar}
|
||||||
|
/>
|
||||||
|
<div className={styles.authorInfo}>
|
||||||
|
<span className={styles.authorName}>{profile.name || profile.login}</span>
|
||||||
|
<span className={styles.authorLogin}>@{profile.login}</span>
|
||||||
|
{profile.bio
|
||||||
|
? <span className={styles.authorBio}>{profile.bio}</span>
|
||||||
|
: <div className={styles.authorBioPlaceholder} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function AuthorsTiles() {
|
||||||
|
const [active, setActive] = useState(0)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (AUTHORS.length <= 1) return
|
||||||
|
const t = setInterval(() => {
|
||||||
|
setActive(i => (i + 1) % AUTHORS.length)
|
||||||
|
}, 4000)
|
||||||
|
return () => clearInterval(t)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.authors}>
|
||||||
|
<div className={styles.outputLine}>
|
||||||
|
<span className={styles.chevron}>›</span> Authors:
|
||||||
|
</div>
|
||||||
|
<div className={styles.authorRow}>
|
||||||
|
{AUTHORS.map((username, i) => (
|
||||||
|
<AuthorTile
|
||||||
|
key={username}
|
||||||
|
username={username}
|
||||||
|
active={i === active}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TerminalHeader() {
|
||||||
|
return (
|
||||||
|
<div className={styles.wrap}>
|
||||||
|
<div className={styles.bar}>
|
||||||
|
<div className={styles.dot + ' ' + styles.red} />
|
||||||
|
<div className={styles.dot + ' ' + styles.amber} />
|
||||||
|
<div className={styles.dot + ' ' + styles.green} />
|
||||||
|
<span className={styles.title}>javadoc-index — bash</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.body}>
|
||||||
|
<h1 className={styles.heading}>
|
||||||
|
{PROJECT_NAME}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<div className={styles.promptLine}>
|
||||||
|
<span className={styles.prompt}>$</span>
|
||||||
|
<span className={styles.cmd}>browse-docs</span>
|
||||||
|
<span className={styles.arg}>{REPO_NAME}</span>
|
||||||
|
<span className={styles.flag}>--all-versions</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.outputLine}>
|
||||||
|
<span className={styles.chevron}>›</span> Fetching available documentation builds...
|
||||||
|
</div>
|
||||||
|
<div className={styles.outputLine}>
|
||||||
|
<span className={styles.chevron}>›</span> Found project links:
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.links}>
|
||||||
|
{LINKS.map(function(l) {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={l.tag}
|
||||||
|
href={l.href}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className={styles.link}
|
||||||
|
>
|
||||||
|
<span className={styles.linkTag} style={{ color: l.color, borderColor: l.color }}>
|
||||||
|
{l.tag}
|
||||||
|
</span>
|
||||||
|
<span className={styles.linkLabel}>{l.label}</span>
|
||||||
|
<span className={styles.linkArrow} style={{ color: l.color }}>↗</span>
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AuthorsTiles />
|
||||||
|
|
||||||
|
<div className={styles.promptLine} style={{ marginTop: '16px' }}>
|
||||||
|
<span className={styles.prompt}>$</span>
|
||||||
|
<span className={styles.cursor} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
.wrap {
|
||||||
|
margin-bottom: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
background: var(--bg3);
|
||||||
|
border: 1px solid var(--border2);
|
||||||
|
border-bottom: none;
|
||||||
|
border-radius: 8px 8px 0 0;
|
||||||
|
padding: 10px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
.red { background: #ff5f57; }
|
||||||
|
.amber { background: #febc2e; }
|
||||||
|
.green { background: #28c840; }
|
||||||
|
|
||||||
|
.title {
|
||||||
|
margin-left: 8px;
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
background: var(--bg2);
|
||||||
|
border: 1px solid var(--border2);
|
||||||
|
border-radius: 0 0 8px 8px;
|
||||||
|
padding: 16px 36px 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Heading ── */
|
||||||
|
.heading {
|
||||||
|
font-family: 'IBM Plex Sans', sans-serif;
|
||||||
|
font-size: clamp(28px, 5vw, 52px);
|
||||||
|
font-weight: 300;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
color: var(--text);
|
||||||
|
line-height: 1.05;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.heading strong {
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--green);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Prompt ── */
|
||||||
|
.promptLine {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 10px;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.prompt { color: var(--green); font-weight: 600; }
|
||||||
|
.cmd { color: var(--text); }
|
||||||
|
.arg { color: var(--blue); }
|
||||||
|
.flag { color: var(--amber); }
|
||||||
|
|
||||||
|
/* ── Output lines ── */
|
||||||
|
.outputLine {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
line-height: 1.8;
|
||||||
|
padding-left: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chevron {
|
||||||
|
color: var(--text-mid);
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Links ── */
|
||||||
|
.links {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
padding-left: 36px;
|
||||||
|
margin-top: 4px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
text-decoration: none;
|
||||||
|
padding: 3px 0;
|
||||||
|
width: fit-content;
|
||||||
|
transition: opacity 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover { opacity: 0.8; }
|
||||||
|
|
||||||
|
.link:hover .linkLabel {
|
||||||
|
text-decoration: underline;
|
||||||
|
text-underline-offset: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkTag {
|
||||||
|
font-size: 9px;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
border: 1px solid;
|
||||||
|
border-radius: 2px;
|
||||||
|
padding: 1px 5px;
|
||||||
|
min-width: 28px;
|
||||||
|
text-align: center;
|
||||||
|
opacity: 0.9;
|
||||||
|
font-family: 'IBM Plex Mono', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkLabel {
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--text-mid);
|
||||||
|
font-family: 'IBM Plex Mono', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.linkArrow {
|
||||||
|
font-size: 11px;
|
||||||
|
opacity: 0.6;
|
||||||
|
transition: opacity 0.15s, transform 0.15s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover .linkArrow {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translate(2px, -2px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Authors ── */
|
||||||
|
.authors {
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorRow {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 8px;
|
||||||
|
padding-left: 36px;
|
||||||
|
margin-top: 6px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Author tile ── */
|
||||||
|
.authorTile {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
background: var(--bg3);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
/* width is dynamic — grows with content */
|
||||||
|
width: max-content;
|
||||||
|
min-width: 140px;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
transition: border-color 0.2s, background 0.2s, transform 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorTile::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0; left: 0; right: 0;
|
||||||
|
height: 2px;
|
||||||
|
background: var(--green);
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorTileActive::before,
|
||||||
|
.authorTile:hover::before {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorTileActive {
|
||||||
|
border-color: var(--green-dim);
|
||||||
|
background: rgba(57, 211, 83, 0.04);
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorTile:hover {
|
||||||
|
border-color: var(--border2);
|
||||||
|
background: #161b22;
|
||||||
|
transform: translateY(-1px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Author content ── */
|
||||||
|
.authorAvatar {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid var(--border2);
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorAvatarSkeleton {
|
||||||
|
width: 32px;
|
||||||
|
height: 32px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--border2);
|
||||||
|
flex-shrink: 0;
|
||||||
|
animation: shimmer 1.5s ease infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorInfo {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorName {
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--text);
|
||||||
|
font-family: 'IBM Plex Sans', sans-serif;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorLogin {
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--blue);
|
||||||
|
font-family: 'IBM Plex Mono', monospace;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bio — always reserves vertical height, width animates open */
|
||||||
|
.authorBio {
|
||||||
|
display: block;
|
||||||
|
font-size: 10px;
|
||||||
|
color: var(--text-dim);
|
||||||
|
font-family: 'IBM Plex Sans', sans-serif;
|
||||||
|
margin-top: 2px;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
/* always reserve vertical space */
|
||||||
|
height: 14px;
|
||||||
|
/* collapsed horizontally */
|
||||||
|
width: 0;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.25s ease, width 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorTileActive .authorBio,
|
||||||
|
.authorTile:hover .authorBio {
|
||||||
|
width: 200px;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Placeholder for loading/no-profile/no-bio states */
|
||||||
|
.authorBioPlaceholder {
|
||||||
|
height: 14px;
|
||||||
|
margin-top: 2px;
|
||||||
|
width: 0; /* never takes horizontal space, never expands */
|
||||||
|
}
|
||||||
|
|
||||||
|
.authorSkeleton {
|
||||||
|
height: 9px;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: var(--border2);
|
||||||
|
animation: shimmer 1.5s ease infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Cursor ── */
|
||||||
|
.cursor {
|
||||||
|
display: inline-block;
|
||||||
|
width: 8px;
|
||||||
|
height: 13px;
|
||||||
|
background: var(--green);
|
||||||
|
margin-left: 2px;
|
||||||
|
vertical-align: text-bottom;
|
||||||
|
animation: blink 1s step-end infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ── Animations ── */
|
||||||
|
@keyframes blink {
|
||||||
|
0%, 100% { opacity: 1; }
|
||||||
|
50% { opacity: 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes shimmer {
|
||||||
|
0%, 100% { opacity: 0.4; }
|
||||||
|
50% { opacity: 0.8; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.body { padding: 20px; }
|
||||||
|
.links { padding-left: 20px; }
|
||||||
|
.authorRow { padding-left: 20px; }
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// ─── Project Configuration ───────────────────────────────────
|
||||||
|
// This is the ONLY file that should differ between projects.
|
||||||
|
// Everything else in the pages app is generic.
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const PROJECT_NAME = 'CustomNPC+'
|
||||||
|
export const REPO_OWNER = 'KAMKEEL'
|
||||||
|
export const REPO_NAME = 'CustomNPC-Plus'
|
||||||
|
|
||||||
|
export const LINKS = [
|
||||||
|
{
|
||||||
|
tag: 'GH',
|
||||||
|
label: 'github.com/KAMKEEL/CustomNPC-Plus',
|
||||||
|
href: 'https://github.com/KAMKEEL/CustomNPC-Plus',
|
||||||
|
color: '#e6edf3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'DC',
|
||||||
|
label: 'discord.gg/94qmjEDxkp',
|
||||||
|
href: 'https://discord.gg/94qmjEDxkp',
|
||||||
|
color: '#5865f2',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'CF',
|
||||||
|
label: 'curseforge.com/minecraft/mc-mods/customnpc-plus',
|
||||||
|
href: 'https://www.curseforge.com/minecraft/mc-mods/customnpc-plus',
|
||||||
|
color: '#f16436',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: 'MR',
|
||||||
|
label: 'modrinth.com/mod/customnpc-plus',
|
||||||
|
href: 'https://modrinth.com/mod/customnpc-plus/',
|
||||||
|
color: '#1bd96a',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
// GitHub usernames — profiles are fetched at runtime
|
||||||
|
export const AUTHORS = ['kamkeel', 'c0508383', 'bigguy345', 'somehussar']
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: #080b0f;
|
||||||
|
--bg2: #0d1117;
|
||||||
|
--bg3: #131920;
|
||||||
|
--border: #1e2936;
|
||||||
|
--border2: #253040;
|
||||||
|
--green: #39d353;
|
||||||
|
--green-dim: #1a6b2a;
|
||||||
|
--amber: #f0a030;
|
||||||
|
--amber-dim: #7a4e10;
|
||||||
|
--blue: #58a6ff;
|
||||||
|
--blue-dim: #1a3a6b;
|
||||||
|
--text: #cdd9e5;
|
||||||
|
--text-dim: #636e7b;
|
||||||
|
--text-mid: #8b949e;
|
||||||
|
--red: #f85149;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
height: 100%;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: 'IBM Plex Mono', monospace;
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Scanlines */
|
||||||
|
body::after {
|
||||||
|
content: '';
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
background: repeating-linear-gradient(
|
||||||
|
0deg,
|
||||||
|
transparent,
|
||||||
|
transparent 2px,
|
||||||
|
rgba(0,0,0,0.025) 2px,
|
||||||
|
rgba(0,0,0,0.025) 4px
|
||||||
|
);
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
a { color: inherit; text-decoration: none; }
|
||||||
|
|
||||||
|
::-webkit-scrollbar { width: 6px; }
|
||||||
|
::-webkit-scrollbar-track { background: var(--bg2); }
|
||||||
|
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
|
||||||
|
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom/client'
|
||||||
|
import App from './App'
|
||||||
|
import { PROJECT_NAME } from './config'
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
document.title = `${PROJECT_NAME} — Javadoc Index`
|
||||||
|
|
||||||
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>
|
||||||
|
)
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { REPO_OWNER, REPO_NAME } from './config'
|
||||||
|
|
||||||
|
const BASE_PATH = `/${REPO_NAME}`
|
||||||
|
const API_BASE = `https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}`
|
||||||
|
|
||||||
|
// Cache bust on every page load — appends current timestamp to manifest URL
|
||||||
|
// so the browser never serves a stale manifest.json
|
||||||
|
async function fetchFromManifest() {
|
||||||
|
const bust = `?t=${Date.now()}`
|
||||||
|
const res = await fetch(`${BASE_PATH}/manifest.json${bust}`, {
|
||||||
|
cache: 'no-store', // tells browser not to cache this request at all
|
||||||
|
})
|
||||||
|
if (!res.ok) throw new Error('No manifest')
|
||||||
|
return res.json()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchFromGitHubAPI() {
|
||||||
|
const refRes = await fetch(`${API_BASE}/git/ref/heads/gh-pages`)
|
||||||
|
if (!refRes.ok) throw new Error('gh-pages branch not found')
|
||||||
|
const refData = await refRes.json()
|
||||||
|
const sha = refData.object.sha
|
||||||
|
|
||||||
|
const treeRes = await fetch(`${API_BASE}/git/trees/${sha}?recursive=1`)
|
||||||
|
if (!treeRes.ok) throw new Error('Could not fetch tree')
|
||||||
|
const treeData = await treeRes.json()
|
||||||
|
|
||||||
|
const commitsRes = await fetch(`${API_BASE}/commits?sha=gh-pages&per_page=100`)
|
||||||
|
const commits = commitsRes.ok ? await commitsRes.json() : []
|
||||||
|
|
||||||
|
const commitMap = {}
|
||||||
|
commits.forEach(c => {
|
||||||
|
const date = c.commit?.committer?.date || c.commit?.author?.date || ''
|
||||||
|
const hash = c.sha?.slice(0, 7) || ''
|
||||||
|
const msg = c.commit?.message || ''
|
||||||
|
const vMatch = msg.match(/releases\/([\d.]+)/)
|
||||||
|
if (vMatch) commitMap[`releases/${vMatch[1]}`] = { date, hash }
|
||||||
|
const eMatch = msg.match(/experimental\/([\w-]+)/)
|
||||||
|
if (eMatch) commitMap[`experimental/${eMatch[1]}`] = { date, hash }
|
||||||
|
})
|
||||||
|
|
||||||
|
const releaseDirs = new Set()
|
||||||
|
const experimentalDirs = new Set()
|
||||||
|
|
||||||
|
treeData.tree.forEach(item => {
|
||||||
|
if (item.type !== 'tree') return
|
||||||
|
const parts = item.path.split('/')
|
||||||
|
if (parts[0] === 'releases' && parts.length === 2) releaseDirs.add(parts[1])
|
||||||
|
if (parts[0] === 'experimental' && parts.length === 2) experimentalDirs.add(parts[1])
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sort releases newest first, mark first as latest
|
||||||
|
const sortedReleases = [...releaseDirs]
|
||||||
|
.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))
|
||||||
|
|
||||||
|
const releases = sortedReleases.map((v, i) => {
|
||||||
|
const c = commitMap[`releases/${v}`] || {}
|
||||||
|
return {
|
||||||
|
id: v,
|
||||||
|
version: v,
|
||||||
|
path: `releases/${v}`,
|
||||||
|
date: c.date,
|
||||||
|
hash: c.hash,
|
||||||
|
isLatest: i === 0, // newest version is always latest
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const experimental = [...experimentalDirs].sort().map(b => {
|
||||||
|
const c = commitMap[`experimental/${b}`] || {}
|
||||||
|
return { id: b, branch: b, path: `experimental/${b}`, date: c.date, hash: c.hash }
|
||||||
|
})
|
||||||
|
|
||||||
|
return { releases, experimental, source: 'api' }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDocs() {
|
||||||
|
const [data, setData] = useState(null)
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchFromManifest()
|
||||||
|
.then(d => { setData(d); setLoading(false) })
|
||||||
|
.catch(() =>
|
||||||
|
fetchFromGitHubAPI()
|
||||||
|
.then(d => { setData(d); setLoading(false) })
|
||||||
|
.catch(e => { setError(e.message); setLoading(false) })
|
||||||
|
)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return { data, loading, error }
|
||||||
|
}
|
||||||
|
|
||||||
|
export { BASE_PATH, REPO_OWNER, REPO_NAME }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react'
|
||||||
|
import { REPO_NAME } from './src/config.js'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
base: `/${REPO_NAME}/`,
|
||||||
|
build: {
|
||||||
|
outDir: '../../.github/pages-dist',
|
||||||
|
emptyOutDir: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# -----------------------------------------------
|
||||||
|
# doc-config.sh — shared config for javadoc deploy
|
||||||
|
#
|
||||||
|
# Sourced by:
|
||||||
|
# - resolve-doc-path.sh
|
||||||
|
# - javadoc.yml (via sanity-check job)
|
||||||
|
#
|
||||||
|
# ADD WHITELISTED BRANCHES HERE AND NOWHERE ELSE.
|
||||||
|
# main is always handled automatically.
|
||||||
|
# -----------------------------------------------
|
||||||
|
|
||||||
|
MAIN_BRANCH_NAME="master"
|
||||||
|
|
||||||
|
EXPERIMENTAL_WHITELIST=(
|
||||||
|
"dev"
|
||||||
|
# "new-branch"
|
||||||
|
)
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
RELEASES=()
|
||||||
|
EXPERIMENTAL=()
|
||||||
|
|
||||||
|
# Collect releases
|
||||||
|
if [ -d "./releases" ]; then
|
||||||
|
for dir in ./releases/*/; do
|
||||||
|
[ -d "$dir" ] || continue
|
||||||
|
name=$(basename "$dir")
|
||||||
|
RELEASES+=("$name")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect experimental branches
|
||||||
|
if [ -d "./experimental" ]; then
|
||||||
|
for dir in ./experimental/*/; do
|
||||||
|
[ -d "$dir" ] || continue
|
||||||
|
name=$(basename "$dir")
|
||||||
|
EXPERIMENTAL+=("$name")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sort releases in reverse semver order (newest first)
|
||||||
|
if [ ${#RELEASES[@]} -gt 0 ]; then
|
||||||
|
IFS=$'\n' RELEASES=($(sort -rV <<< "${RELEASES[*]}")); unset IFS
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── Store source commit metadata for this deploy ───────────────
|
||||||
|
# DEPLOY_PATH, SOURCE_HASH, SOURCE_DATE are passed in as env vars from the workflow
|
||||||
|
if [ -n "$DEPLOY_PATH" ] && [ -n "$SOURCE_HASH" ]; then
|
||||||
|
mkdir -p ".doc-meta"
|
||||||
|
META_KEY="${DEPLOY_PATH//\//_}"
|
||||||
|
cat > ".doc-meta/${META_KEY}.json" << JSON
|
||||||
|
{"hash":"${SOURCE_HASH}","date":"${SOURCE_DATE}"}
|
||||||
|
JSON
|
||||||
|
echo "Stored source metadata for $DEPLOY_PATH → $SOURCE_HASH @ $SOURCE_DATE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── Helper: get source commit hash + date for a path ──────────
|
||||||
|
get_commit_info() {
|
||||||
|
local path="$1"
|
||||||
|
|
||||||
|
# If this is the path we just deployed, use the injected source commit
|
||||||
|
if [ "$path" = "$DEPLOY_PATH" ] && [ -n "$SOURCE_HASH" ]; then
|
||||||
|
echo "${SOURCE_HASH} ${SOURCE_DATE}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try reading from stored metadata file (set by previous deploys)
|
||||||
|
local meta=".doc-meta/${path//\//_}.json"
|
||||||
|
if [ -f "$meta" ]; then
|
||||||
|
local hash date
|
||||||
|
hash=$(python3 -c "import json,sys; d=json.load(open('$meta')); print(d.get('hash',''))" 2>/dev/null || grep -o '"hash":"[^"]*"' "$meta" | cut -d'"' -f4)
|
||||||
|
date=$(python3 -c "import json,sys; d=json.load(open('$meta')); print(d.get('date',''))" 2>/dev/null || grep -o '"date":"[^"]*"' "$meta" | cut -d'"' -f4)
|
||||||
|
echo "${hash:-} ${date:-}"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Last resort: gh-pages git log (hash will be wrong but better than empty)
|
||||||
|
local hash date
|
||||||
|
hash=$(git log --oneline -1 -- "$path" 2>/dev/null | awk '{print $1}')
|
||||||
|
date=$(git log --format="%cI" -1 -- "$path" 2>/dev/null)
|
||||||
|
echo "${hash:-} ${date:-}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ── Build releases JSON ────────────────────────────────────────
|
||||||
|
RELEASES_JSON="["
|
||||||
|
|
||||||
|
for i in "${!RELEASES[@]}"; do
|
||||||
|
version="${RELEASES[$i]}"
|
||||||
|
read -r HASH DATE <<< "$(get_commit_info "releases/$version")"
|
||||||
|
if [ "$i" -eq 0 ]; then
|
||||||
|
IS_LATEST="true"
|
||||||
|
else
|
||||||
|
IS_LATEST="false"
|
||||||
|
fi
|
||||||
|
RELEASES_JSON+="{\"id\":\"${version}\",\"version\":\"${version}\",\"path\":\"releases/${version}\",\"date\":\"${DATE}\",\"isLatest\":${IS_LATEST}},"
|
||||||
|
done
|
||||||
|
|
||||||
|
RELEASES_JSON="${RELEASES_JSON%,}]"
|
||||||
|
|
||||||
|
# ── Build experimental JSON ────────────────────────────────────
|
||||||
|
EXPERIMENTAL_JSON="["
|
||||||
|
|
||||||
|
for branch in "${EXPERIMENTAL[@]}"; do
|
||||||
|
read -r HASH DATE <<< "$(get_commit_info "experimental/$branch")"
|
||||||
|
EXPERIMENTAL_JSON+="{\"id\":\"${branch}\",\"branch\":\"${branch}\",\"path\":\"experimental/${branch}\",\"hash\":\"${HASH}\",\"date\":\"${DATE}\"},"
|
||||||
|
done
|
||||||
|
|
||||||
|
EXPERIMENTAL_JSON="${EXPERIMENTAL_JSON%,}]"
|
||||||
|
|
||||||
|
# ── Write manifest.json ────────────────────────────────────────
|
||||||
|
cat > manifest.json << JSON
|
||||||
|
{
|
||||||
|
"releases": ${RELEASES_JSON},
|
||||||
|
"experimental": ${EXPERIMENTAL_JSON},
|
||||||
|
"generated": "$(date -u '+%Y-%m-%dT%H:%M:%SZ')",
|
||||||
|
"source": "manifest"
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
|
||||||
|
echo "manifest.json generated:"
|
||||||
|
cat manifest.json
|
||||||
|
echo ""
|
||||||
|
echo "Done."
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
source "$SCRIPT_DIR/doc-config.sh"
|
||||||
|
|
||||||
|
BRANCH="${GITHUB_REF#refs/heads/}"
|
||||||
|
SAFE_BRANCH="${BRANCH//\//-}"
|
||||||
|
|
||||||
|
if [ "$BRANCH" = "$MAIN_BRANCH_NAME" ]; then
|
||||||
|
# Version resolution order:
|
||||||
|
# -> check if gradle.properties has a `modVersion` tag. If it does, just grab it.
|
||||||
|
# -> check if it has the `version` tag. Grab it if it does
|
||||||
|
# -> check build.gradle for the version tag.
|
||||||
|
if [ -f "gradle.properties" ] && grep -q "^modVersion=" gradle.properties; then
|
||||||
|
VERSION=$(grep "^modVersion=" gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
|
||||||
|
elif [ -f "gradle.properties" ] && grep -q "^version=" gradle.properties; then
|
||||||
|
VERSION=$(grep "^version=" gradle.properties | cut -d'=' -f2 | tr -d '[:space:]')
|
||||||
|
elif [ -f "build.gradle" ]; then
|
||||||
|
VERSION=$(grep "^version" build.gradle | head -1 | sed "s/version\s*=\s*['\"]//;s/['\"].*//;s/\s//g")
|
||||||
|
elif [ -f "build.gradle.kts" ]; then
|
||||||
|
VERSION=$(grep "^version" build.gradle.kts | head -1 | sed "s/version\s*=\s*\"//;s/\".*//;s/\s//g")
|
||||||
|
else
|
||||||
|
echo "Could not find version. Defaulting to 'unknown'."
|
||||||
|
VERSION="unknown"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Resolved version: $VERSION"
|
||||||
|
|
||||||
|
# Only deploy to releases/<version> — isLatest is handled by generate-index.sh
|
||||||
|
echo "path=releases/$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "extra_path=" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
else
|
||||||
|
MATCHED=false
|
||||||
|
for ALLOWED in "${EXPERIMENTAL_WHITELIST[@]}"; do
|
||||||
|
if [ "$BRANCH" = "$ALLOWED" ]; then
|
||||||
|
MATCHED=true
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$MATCHED" = true ]; then
|
||||||
|
echo "path=experimental/$SAFE_BRANCH" >> $GITHUB_OUTPUT
|
||||||
|
echo "extra_path=" >> $GITHUB_OUTPUT
|
||||||
|
echo "Branch '$BRANCH' is whitelisted, deploying to experimental/$SAFE_BRANCH"
|
||||||
|
else
|
||||||
|
echo "path=" >> $GITHUB_OUTPUT
|
||||||
|
echo "extra_path=" >> $GITHUB_OUTPUT
|
||||||
|
echo "Branch '$BRANCH' is not whitelisted. Skipping deploy."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
@@ -24,8 +24,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Initialize CNPC+ API submodule
|
- name: Initialize submodules
|
||||||
run: git submodule update --init --recursive src/api
|
run: git submodule update --init --recursive
|
||||||
|
|
||||||
- name: Checkout workflows repo
|
- name: Checkout workflows repo
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
name: Generate and Deploy Javadoc
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- '**'
|
||||||
|
delete:
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
force_deploy:
|
||||||
|
description: 'Force redeploy Javadocs without a new commit'
|
||||||
|
required: false
|
||||||
|
default: 'true'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
sanity-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
should_deploy: ${{ steps.deploy_check.outputs.should_deploy }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Check for deploy tag
|
||||||
|
id: deploy_check
|
||||||
|
run: |
|
||||||
|
source .github/scripts/doc-config.sh
|
||||||
|
|
||||||
|
BRANCH="${GITHUB_REF#refs/heads/}"
|
||||||
|
|
||||||
|
# Always deploy on manual trigger
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "should_deploy=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Reason: workflow_dispatch"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Main branch: only deploy if commit message contains [deploy-docs]
|
||||||
|
if [ "$BRANCH" = "$MAIN_BRANCH_NAME" ]; then
|
||||||
|
if echo "${{ github.event.head_commit.message }}" | grep -q "\[deploy-docs\]"; then
|
||||||
|
echo "should_deploy=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Reason: master branch with [deploy-docs] tag"
|
||||||
|
else
|
||||||
|
echo "should_deploy=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "Reason: master branch without [deploy-docs] tag, skipping"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Experimental branches: only deploy if whitelisted
|
||||||
|
for ALLOWED in "${EXPERIMENTAL_WHITELIST[@]}"; do
|
||||||
|
if [ "$BRANCH" = "$ALLOWED" ]; then
|
||||||
|
echo "should_deploy=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "Reason: branch '$BRANCH' is whitelisted"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "should_deploy=false" >> $GITHUB_OUTPUT
|
||||||
|
echo "Reason: branch '$BRANCH' is not whitelisted, skipping"
|
||||||
|
|
||||||
|
build-and-deploy-javadoc:
|
||||||
|
needs: sanity-check
|
||||||
|
if: needs.sanity-check.outputs.should_deploy == 'true'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout source branch
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Initialize submodules
|
||||||
|
run: git submodule update --init --recursive
|
||||||
|
|
||||||
|
- name: Setup JDK 8 (compile)
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '8'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Set up JDK 8 (Zulu)
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '8'
|
||||||
|
distribution: 'zulu'
|
||||||
|
- name: Setup JDK 11 (javadoc)
|
||||||
|
uses: actions/setup-java@v4
|
||||||
|
with:
|
||||||
|
java-version: '11'
|
||||||
|
distribution: 'temurin'
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Extract convention plugin version
|
||||||
|
id: convention
|
||||||
|
run: |
|
||||||
|
VERSION=$(grep "id 'com.gtnewhorizons.gtnhsettingsconvention'" settings.gradle settings.gradle.kts 2>/dev/null | grep -o "version '[0-9]\+\.[0-9]\+\.[0-9]\+'" | grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+')
|
||||||
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
|
echo "Detected convention version: $VERSION"
|
||||||
|
|
||||||
|
- name: Get source commit info
|
||||||
|
id: source_commit
|
||||||
|
run: |
|
||||||
|
echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
||||||
|
echo "date=$(git log -1 --format='%cI')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Cache Gradle wrapper
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.gradle/wrapper
|
||||||
|
key: gradle-wrapper-${{ hashFiles('**/gradle-wrapper.properties') }}
|
||||||
|
|
||||||
|
- name: Cache Gradle dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.gradle/caches
|
||||||
|
~/.gradle/caches/modules-*
|
||||||
|
~/.gradle/caches/jars-*
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', '**/gradle.properties') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
|
||||||
|
- name: Cache RFG
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
build/rfg
|
||||||
|
build/tmp/.cache/expanded
|
||||||
|
build/tmp/deobfuscateMergedJarToSrg
|
||||||
|
key: ${{ runner.os }}-rfg-convention${{ steps.convention.outputs.version }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-rfg-
|
||||||
|
|
||||||
|
- name: Cache Node modules
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: .github/pages/node_modules
|
||||||
|
key: ${{ runner.os }}-node-${{ hashFiles('.github/pages/package-lock.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-node-
|
||||||
|
|
||||||
|
- name: Generate Javadoc
|
||||||
|
run: ./gradlew javadoc
|
||||||
|
|
||||||
|
- name: Get deploy path
|
||||||
|
id: deploy_path
|
||||||
|
run: bash .github/scripts/resolve-doc-path.sh
|
||||||
|
|
||||||
|
- name: Deploy to gh-pages
|
||||||
|
if: steps.deploy_path.outputs.path != ''
|
||||||
|
uses: peaceiris/actions-gh-pages@v4
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: ./build/docs/javadoc
|
||||||
|
destination_dir: ${{ steps.deploy_path.outputs.path }}
|
||||||
|
keep_files: true
|
||||||
|
|
||||||
|
# Give GitHub a moment to settle after the peaceiris push
|
||||||
|
- name: Wait for gh-pages to settle
|
||||||
|
run: sleep 10
|
||||||
|
|
||||||
|
- name: Checkout gh-pages
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: gh-pages
|
||||||
|
path: gh-pages-index
|
||||||
|
|
||||||
|
- name: Generate manifest
|
||||||
|
run: |
|
||||||
|
cd gh-pages-index
|
||||||
|
SOURCE_HASH="${{ steps.source_commit.outputs.hash }}" \
|
||||||
|
SOURCE_DATE="${{ steps.source_commit.outputs.date }}" \
|
||||||
|
DEPLOY_PATH="${{ steps.deploy_path.outputs.path }}" \
|
||||||
|
bash ../.github/scripts/generate-index.sh
|
||||||
|
|
||||||
|
- name: Install page dependencies
|
||||||
|
run: npm ci --prefix .github/pages
|
||||||
|
|
||||||
|
- name: Build index page
|
||||||
|
run: |
|
||||||
|
mkdir -p .github/pages/public
|
||||||
|
cp gh-pages-index/manifest.json .github/pages/public/manifest.json
|
||||||
|
npm run build --prefix .github/pages
|
||||||
|
|
||||||
|
- name: Deploy index to gh-pages
|
||||||
|
run: |
|
||||||
|
cp -r .github/pages-dist/* gh-pages-index/
|
||||||
|
cd gh-pages-index
|
||||||
|
git config user.name "github-actions"
|
||||||
|
git config user.email "[email protected]"
|
||||||
|
git add -A
|
||||||
|
git commit -m "Regenerate index and manifest [skip ci]" || echo "Unchanged"
|
||||||
|
git push
|
||||||
|
|
||||||
|
cleanup-on-delete:
|
||||||
|
if: github.event_name == 'delete' && github.event.ref_type == 'branch'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout gh-pages
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
ref: 'gh-pages'
|
||||||
|
|
||||||
|
- name: Remove deleted branch docs
|
||||||
|
run: |
|
||||||
|
BRANCH="${{ github.event.ref }}"
|
||||||
|
SAFE="experimental/${BRANCH//\//-}"
|
||||||
|
if [ -d "./$SAFE" ]; then
|
||||||
|
rm -rf "./$SAFE"
|
||||||
|
META_KEY="${SAFE//\//_}"
|
||||||
|
rm -f ".doc-meta/${META_KEY}.json"
|
||||||
|
git config user.name "github-actions"
|
||||||
|
git config user.email "[email protected]"
|
||||||
|
git add -A
|
||||||
|
git commit -m "Remove docs for deleted branch: $BRANCH"
|
||||||
|
git push
|
||||||
|
else
|
||||||
|
echo "No docs found for $SAFE, skipping."
|
||||||
|
fi
|
||||||
@@ -45,4 +45,6 @@ src/main/resources/assets/customnpcs/api
|
|||||||
df/
|
df/
|
||||||
tmp/
|
tmp/
|
||||||
src/test
|
src/test
|
||||||
|
node_modules
|
||||||
|
.github/pages-dist
|
||||||
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
# CNPC+ 1.11 Beta - The Scripting Update
|
|
||||||
|
|
||||||
🟡 **In Testing**
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Features: ⚒️
|
|
||||||
|
|
||||||
- **Syntax Highlighting:**
|
|
||||||
|
|
||||||
> Full color-coded script editor. Keywords, types, variables, methods, strings, and comments are all distinct. Scope-aware coloring distinguishes local fields from globals and chained method calls.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Autocomplete:**
|
|
||||||
|
|
||||||
> Smart suggestions as you type. Context-aware for static vs instance access, shows method parameters, resolves chained calls, and suggests auto imports for classes. Frequently used members prioritized.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Error Detection:**
|
|
||||||
|
|
||||||
> Catch mistakes before running. Type mismatches, wrong arguments, missing methods, unused imports, duplicate definitions, and more -- all underlined with hover messages explaining the issue.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Hover Information:**
|
|
||||||
|
|
||||||
> Hover any symbol to see its type, documentation, and declaration. Works on methods, fields, classes, and even generics. Click to pin tooltips in place.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Script Editor Overhaul:**
|
|
||||||
|
|
||||||
> - **Line Numbers** - Gutter with current line highlighting.
|
|
||||||
> - **Go To Line** - CTRL+G to jump to any line.
|
|
||||||
> - **Search & Replace** - CTRL+F / CTRL+H with real-time highlighting.
|
|
||||||
> - **Go To Definition** - CTRL+Click to jump to any symbol.
|
|
||||||
> - **Smart Undo/Redo** - Word-level instead of character-level.
|
|
||||||
> - **Line Operations** - Duplicate, delete, move up/down.
|
|
||||||
> - **Comment Toggle** - CTRL+/ for selected lines.
|
|
||||||
> - **Rename** - Rename a symbol across all occurrences.
|
|
||||||
> - **Smooth Scrolling** - Eased scroll animation.
|
|
||||||
> - **Indent Guides** - Scope-highlighted vertical indent lines.
|
|
||||||
> - **Brace Matching** - Highlighted pairs, red for unclosed.
|
|
||||||
> - **Smart Brackets** - Auto-pairing for `{}`, `()`, `[]`, `""`, `''`.
|
|
||||||
> - **Fullscreen Mode** - Expand editor to fill the game window.
|
|
||||||
> - **Shortcut Overlay** - View all keyboard shortcuts at a glance.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Java Scripting (Janino):**
|
|
||||||
|
|
||||||
> Write scripts in real Java compiled at runtime. Name methods after hooks for automatic wiring. Language selector per tab to switch between Java and JavaScript. External `.java` file support.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Client-Side Scripting:**
|
|
||||||
|
|
||||||
> Run scripts on the client for responsive experiences. Server-controlled -- off by default, must be explicitly enabled. Script files sync automatically on login and reload.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Cloner Tab Overhaul:**
|
|
||||||
|
|
||||||
> Folder-based organization for saved NPCs, items, and entries. Full-width directory browser for large collections. Improved tab navigation.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Addon API Support:**
|
|
||||||
|
|
||||||
> Addons can ship type definitions that load into the script editor automatically. Full autocomplete, hover info, and documentation for addon APIs. Addons can extend existing CNPC+ types with new methods.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Animation Improvements:**
|
|
||||||
|
|
||||||
> Data store for passing data across animation events and frames. New consumer-based task system for animation lifecycle. Expanded scripting API for animation control.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Extras**
|
|
||||||
|
|
||||||
- Player Dialog Events now work like NPC Dialog Events.
|
|
||||||
- Attack speed configuration for linked items.
|
|
||||||
- Client-side balance prediction during Trader interactions.
|
|
||||||
- Right-click cycling on multi-option NPC buttons (Hair, Eyes, Fur, etc.).
|
|
||||||
- Fixed quest cooldown for MC Custom and RL Custom timer types.
|
|
||||||
- Fixed Bard music restarting when opening dialogs.
|
|
||||||
- Fixed NPC biome spawn settings not saving after editing.
|
|
||||||
- Fixed block waypoint issues.
|
|
||||||
- Fixed script config syncing between server and client.
|
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
# ✏️ CustomNPC+ 1.11 - The Scripting Update ✏️
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
The **Scripting Update** completely transforms how you write scripts in CNPC+! A brand new **Script Editor** with **syntax highlighting**, **autocomplete**, and **error detection** makes scripting feel like a real IDE. Write scripts in **Java** with the new Janino engine, enable **client-side scripting** for responsive experiences, and organize your Cloner with **folders**!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Script Editor 📝
|
|
||||||
|
|
||||||
The script editor has been rebuilt from the ground up into a **full-featured code editor** right inside Minecraft.
|
|
||||||
|
|
||||||
### Writing Code
|
|
||||||
|
|
||||||
- **Syntax Highlighting** - Keywords, types, variables, methods, strings, and comments are all color-coded automatically. The editor understands your code -- local variables, global fields, and chained method calls each get their own color
|
|
||||||
- **Autocomplete** - Start typing and get smart suggestions for methods, fields, and classes. Suggestions know whether you're in a static or instance context, and frequently used members appear first
|
|
||||||
- **Auto Imports** - Type a class name and the editor suggests the correct import for you
|
|
||||||
- **Error Detection** - Catch mistakes before you even run your script! Wrong argument types, missing methods, type mismatches, unused imports, and more are all underlined with detailed error messages on hover
|
|
||||||
|
|
||||||
> Hover over any symbol to see its **full type information**, documentation, and declaration -- just like a desktop IDE.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Navigation
|
|
||||||
|
|
||||||
- **Go To Line** - `CTRL+G` jumps to any line instantly
|
|
||||||
- **Search & Replace** - `CTRL+F` to search, `CTRL+H` to replace. All matches highlight in real-time
|
|
||||||
- **Go To Definition** - `CTRL+Click` any method, field, or type to jump straight to its definition
|
|
||||||
- **Fullscreen Mode** - Expand the editor to fill your entire game window for maximum workspace
|
|
||||||
|
|
||||||
### Editing
|
|
||||||
|
|
||||||
- **Undo/Redo** - Smart undo that works on whole words at a time, not individual characters
|
|
||||||
- **Line Operations** - Duplicate lines with `CTRL+D`, delete lines, and move lines up or down with shortcuts
|
|
||||||
- **Comment Toggle** - `CTRL+/` to comment or uncomment selected lines
|
|
||||||
- **Rename** - Rename a variable or method and every occurrence updates at once
|
|
||||||
- **Copy Whole Line** - Copy with nothing selected grabs the entire line
|
|
||||||
- **Triple Click** - Select an entire line instantly
|
|
||||||
|
|
||||||
### Visual Polish
|
|
||||||
|
|
||||||
- **Line Numbers** - A clean gutter with line numbers and current line highlighting
|
|
||||||
- **Smooth Scrolling** - Eased scroll animations for a polished feel
|
|
||||||
- **Indent Guides** - Vertical lines show your code's nesting depth, with the current scope highlighted in green
|
|
||||||
- **Brace Matching** - Matching `{}` braces light up, and unclosed braces turn red
|
|
||||||
- **Smart Brackets** - Typing `{` automatically creates the closing `}` with correct indentation. Same for `()`, `[]`, `""`, and `''`
|
|
||||||
- **Keyboard Shortcut Overlay** - Press a button to see all available shortcuts at a glance
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Java Scripting ☕
|
|
||||||
|
|
||||||
Write scripts in **real Java** instead of JavaScript! Powered by the **Janino** compiler, your Java code is compiled and runs natively.
|
|
||||||
|
|
||||||
- **Full Java Language** - Use classes, interfaces, enums, generics, lambdas, and everything you know from Java
|
|
||||||
- **Automatic Hook Resolution** - Just name your methods after the hook you want (e.g., `init`, `tick`, `interact`) and they're wired up automatically
|
|
||||||
- **Language Selector** - Each script tab has a dropdown to choose between JavaScript and Java. Mix and match across tabs
|
|
||||||
- **External Files** - Write `.java` scripts in an external editor and they're loaded automatically
|
|
||||||
|
|
||||||
> Java and JavaScript scripts coexist side by side. Pick whichever language fits your workflow!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Client-Side Scripting 🖥️
|
|
||||||
|
|
||||||
Scripts can now run **on the client** for responsive, visual experiences!
|
|
||||||
|
|
||||||
- **Server Controlled** - Server owners decide whether client scripting is allowed. Players can't enable it on their own
|
|
||||||
- **Automatic Sync** - Script files are sent from the server to all connected clients on login, and re-synced whenever scripts are reloaded
|
|
||||||
- **Safe by Default** - Client scripting is off by default and must be explicitly enabled in the server config
|
|
||||||
|
|
||||||
> Client-side scripts open the door to custom UI effects, visual feedback, and client-only hooks -- all while the server stays in full control.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Cloner Tab Overhaul 📂
|
|
||||||
|
|
||||||
The Cloner now supports **folders** for organizing your saved NPCs, items, and entries!
|
|
||||||
|
|
||||||
- **Folder System** - Create folders and subfolders to keep your cloner organized however you like
|
|
||||||
- **Full Screen Browser** - A new full-width directory view makes browsing large collections much easier
|
|
||||||
- **Improved Tabs** - Better tab navigation for switching between cloner categories
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Addon API Support 📘
|
|
||||||
|
|
||||||
Addon developers can now ship **type definitions** alongside their mods, giving scripters full autocomplete and documentation for addon APIs!
|
|
||||||
|
|
||||||
- **Automatic Loading** - Any mod can include API definitions and they'll appear in the script editor automatically
|
|
||||||
- **Patch Support** - Addons can extend existing CNPC+ types with new methods (e.g., a DBC addon adding `getDBCPlayer()` to the Player type)
|
|
||||||
- **Full Documentation** - Parameter names, return types, and descriptions all show up in autocomplete and hover info
|
|
||||||
|
|
||||||
> If you're a scripter using addons, you get autocomplete for their APIs with zero setup. If you're an addon developer, just include your definitions and everything works.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Animation Improvements 🎬
|
|
||||||
|
|
||||||
- **Data Store** - Animations can now store and pass data across events and frames for more complex animation logic
|
|
||||||
- **Task System** - A new consumer-based system for reacting to animation lifecycle events, replacing the old approach
|
|
||||||
- **Expanded API** - More animation control exposed to the scripting API
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Additional Changes 🔧
|
|
||||||
|
|
||||||
- **Player Dialog Events** - Now work the same way as NPC Dialog Events for consistency
|
|
||||||
- **Linked Item Attack Speed** - Added attack speed configuration to linked items
|
|
||||||
- **Trader Balance Preview** - Client-side balance prediction shows your expected balance during trades
|
|
||||||
- **Right-Click Cycling** - Multi-option NPC buttons (Hair, Eyes, Fur, etc.) can now be right-clicked to cycle backwards
|
|
||||||
- **Quest Cooldown Fix** - Fixed cooldown not working for MC Custom and RL Custom timer types
|
|
||||||
- **Bard Music Fix** - Fixed music restarting or duplicating when opening dialogs
|
|
||||||
- **Biome Spawn Fix** - Fixed NPC biome spawn settings not saving after editing
|
|
||||||
- **Block Waypoint Fix** - Fixed issues with block waypoints
|
|
||||||
- **Script Config Fix** - Fixed script configuration not syncing properly between server and client
|
|
||||||
|
|
||||||
---
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
# Agent Guidelines
|
||||||
|
|
||||||
|
This repo keeps “fresh memory” notes under `.$state/`. These docs are the primary mental model for the script editor + interpreter stack.
|
||||||
|
|
||||||
|
Default todo list: `.$state/TODO.md`
|
||||||
|
|
||||||
|
## Compilation and Building
|
||||||
|
|
||||||
|
To compile the project, run the gradlew.bat compileJava task on ONLY the root project (CustomNPC-DBC-Addon). This applies for CustomNPC-Plus as well.
|
||||||
|
And WAIT!!! Waiting is essential, as the task can usually take up to 3 minutes. As long as the compileJava task is running, DO NOT close the terminal or interrupt the process.
|
||||||
|
|
||||||
|
## How to use state docs
|
||||||
|
|
||||||
|
Before exploring source code or making edits, scan the user prompt for subsystem keywords and open the relevant `.$state/*.md` doc(s) first. If multiple subsystems are involved, read all relevant docs (usually 1–3).
|
||||||
|
|
||||||
|
Recommended read order (when multiple apply):
|
||||||
|
1. `.$state/SYNTAX_HIGHLIGHTER.md`
|
||||||
|
2. `.$state/AUTOCOMPLETE.md`
|
||||||
|
3. `.$state/DTS_ECOSYSTEM.md`
|
||||||
|
4. `.$state/SCRIPT_EDITOR.md`
|
||||||
|
5. `.$state/SCRIPT_HANDLING.md`
|
||||||
|
|
||||||
|
The goal is not to treat the docs as perfectly authoritative; it’s to refresh terminology, invariants, and the intended architecture before verifying details in source.
|
||||||
|
|
||||||
|
## State docs (what to read when)
|
||||||
|
|
||||||
|
- `.$state/SYNTAX_HIGHLIGHTER.md`
|
||||||
|
- Read when the prompt involves: `ScriptDocument`, parsing/marking/token building, `TokenType` priority, `FieldChainMarker`, validation errors, hover/underlines, synthetic built-ins, JSDoc, or type-resolution questions involving `TypeResolver`, `resolveType` or `resolveExpressionType`.
|
||||||
|
|
||||||
|
- `.$state/AUTOCOMPLETE.md`
|
||||||
|
- Read when the prompt involves: autocomplete UI/behavior, prefix/receiver detection, insertion behavior, providers (`JavaAutocompleteProvider`, `JSAutocompleteProvider`), suggestion ranking, usage tracking, import insertion, or missing/wrong suggestions.
|
||||||
|
|
||||||
|
- `.$state/DTS_ECOSYSTEM.md`
|
||||||
|
- Read when the prompt involves: `.d.ts` generation (Gradle plugin in `gradle-plugins/`), `hooks.d.ts` / `index.d.ts`, runtime parsing (`TypeScriptDefinitionParser`), registry behavior (`JSTypeRegistry`), `JSTypeInfo`/`JSMethodInfo`/`JSFieldInfo`, or TypeScript generic bound handling.
|
||||||
|
|
||||||
|
- `.$state/SCRIPT_EDITOR.md`
|
||||||
|
- Read when the prompt involves: `GuiScriptTextArea`, editor UX (scroll/selection/search/go-to-line/rename), hover UI wiring, or the client editor model (`ScriptTextContainer`).
|
||||||
|
|
||||||
|
- `.$state/SCRIPT_HANDLING.md`
|
||||||
|
- Read when the prompt involves: (`JaninoScript`, `janino`, `GuiScriptInterface` ), runtime script storage/execution (`ScriptContainer`), script-related NBT serialization, hook dispatch, script engine selection, or script controller/handler wiring.
|
||||||
|
|
||||||
|
## Cross-subsystem quick picks
|
||||||
|
|
||||||
|
- Autocomplete issues that smell like “wrong receiver type / missing members / cannot resolve symbol”:
|
||||||
|
- Read `.$state/AUTOCOMPLETE.md` + `.$state/SYNTAX_HIGHLIGHTER.md` (+ `.$state/DTS_ECOSYSTEM.md` if JS/.d.ts types involved).
|
||||||
|
- JS autocomplete issues specifically:
|
||||||
|
- Read `.$state/AUTOCOMPLETE.md` + `.$state/DTS_ECOSYSTEM.md` + the relevant `.$state/SYNTAX_HIGHLIGHTER.md` sections.
|
||||||
|
- Hover tooltip / red underline / error text mismatches:
|
||||||
|
- Read `.$state/SYNTAX_HIGHLIGHTER.md`.
|
||||||
|
|
||||||
|
## Workflow expectation
|
||||||
|
|
||||||
|
1. Identify subsystem keywords in the user request.
|
||||||
|
2. Read the relevant `.$state/*.md` doc(s) first (before open-ended repo exploration).
|
||||||
|
3. Use the docs to decide which source files to inspect next.
|
||||||
|
4. Verify critical details against source before making edits (the docs can drift).
|
||||||
|
5. If edits change behavior/architecture described in a state doc, ask the user whether they want the doc updated as part of the change.
|
||||||
|
|
||||||
|
|
||||||
|
## Planning
|
||||||
|
|
||||||
|
When I prompt you to plan something, I want you to always follow these steps:
|
||||||
|
1. Analyze the user request carefully to understand their needs and objectives.
|
||||||
|
2. Break down the request into smaller, manageable tasks or components.
|
||||||
|
3. Prioritize the tasks based on their importance and dependencies.
|
||||||
|
4. Create a detailed plan or outline that addresses each task systematically.
|
||||||
|
5. Review the plan to ensure it aligns with the user's goals and is feasible to implement.
|
||||||
|
6. Present the plan to the user for feedback and approval before proceeding with implementation.
|
||||||
|
7. Once approved, execute the plan step by step, keeping the user informed of progress and any adjustments needed along the way.
|
||||||
|
8. After completing the tasks, review the outcomes with the user to ensure satisfaction and address any further needs.
|
||||||
|
9. Document the process and results for future reference and learning.
|
||||||
|
|
||||||
|
This plan must always be created and stored at .sisyphus/plans as a .md file with a unique name related to the task.
|
||||||
|
That document must be your main source of truth for the plan, you must always refer to it before and after taking any action.
|
||||||
|
|
||||||
|
## Expert-Scripter Conventions
|
||||||
|
|
||||||
|
For CustomNPC+ scripting conventions and quality standards, see `.github/agents/AGENTS.md`.
|
||||||
|
|
||||||
|
That file documents:
|
||||||
|
- Mandatory review gates and triggers
|
||||||
|
- API verification requirements (zero-tolerance policy)
|
||||||
|
- Storage decision tree (getNbt vs getStoredData vs getTempData)
|
||||||
|
- Subagent usage rules
|
||||||
|
- Production quality checklist
|
||||||
|
- Code-Review conventions
|
||||||
|
- Training scripts policy
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
# CNPC+ 1.11 Ability System Beta
|
|
||||||
|
|
||||||
🟡 **In Testing**
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Features: ⚒️
|
|
||||||
|
|
||||||
- **Phase-Based Execution:**
|
|
||||||
|
|
||||||
> All abilities follow a Wind-up → Active → Completion flow. Wind-up lets players react, Active deals the effect.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Melee Abilities:**
|
|
||||||
|
|
||||||
> - **Slam** - Leap and AOE on impact.
|
|
||||||
> - **Heavy Hit** - Single powerful strike with bonus knockback.
|
|
||||||
> - **Cutter** - Slashing cone arc attack.
|
|
||||||
> - **Shockwave** - AOE burst radiating from the caster.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Orbs:**
|
|
||||||
|
|
||||||
> - **Orb** - Homing energy sphere.
|
|
||||||
> - **Dual Orb** - Two simultaneous homing orbs.
|
|
||||||
> - **Orb Barrage** - Rapid volley of orbs in sequence.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Discs:**
|
|
||||||
|
|
||||||
> - **Disc** - Spinning flat projectile with optional boomerang.
|
|
||||||
> - **Dual Disc** - Two simultaneous discs.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Beams:**
|
|
||||||
|
|
||||||
> - **Beam** - Sustained homing beam from caster to target.
|
|
||||||
> - **Dual Beam** - Two simultaneous beams.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Laser Shot:**
|
|
||||||
|
|
||||||
> Instant-fire projectile with no homing. Pure aim.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Projectile:**
|
|
||||||
|
|
||||||
> Standard projectile using classic Minecraft physics.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Movement Abilities:**
|
|
||||||
|
|
||||||
> - **Charge** - Rush forward in a line, damaging everything in path.
|
|
||||||
> - **Dash** - Quick directional movement without damage.
|
|
||||||
> - **Teleport** - Instant relocation to the target.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **AOE Abilities:**
|
|
||||||
|
|
||||||
> - **Sweeper** - Wide rotational sweep around the caster.
|
|
||||||
> - **Vortex** - Pulls entities inward while dealing damage.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Telegraph System:**
|
|
||||||
|
|
||||||
> Visual ground indicators during wind-up. Supports Circle, Ring, Line, Cone, and Point shapes with color customization and warning phase transitions.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Projectile Customization:**
|
|
||||||
|
|
||||||
> Modular data system for all energy projectiles: Anchor Point, Display Colors, Homing, Combat Stats, and Lifespan.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Effects:**
|
|
||||||
|
|
||||||
> Abilities can apply potion effects on hit: Slowness, Weakness, Poison, Wither, Blindness, Nausea, Hunger, Mining Fatigue.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Conditions:**
|
|
||||||
|
|
||||||
> Condition system controlling when abilities can execute based on target state and custom predicates.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Interruptible Wind-ups:**
|
|
||||||
|
|
||||||
> Abilities can be interrupted by damage during wind-up, forcing a configurable Dazed recovery state.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Movement & Rotation Locking:**
|
|
||||||
|
|
||||||
> Lock caster movement, rotation, or both during Wind-up, Active, or both phases.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Animation & Sound Integration:**
|
|
||||||
|
|
||||||
> Wind-up and Active animations with optional duration sync. Custom sound events per phase.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Player Abilities:**
|
|
||||||
|
|
||||||
> Players can unlock abilities, select one at a time, and share a universal cooldown.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Preview:**
|
|
||||||
|
|
||||||
> Live preview in the ability editor GUI. Test telegraphs, animations, and projectiles on a dummy NPC.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Scripting API:**
|
|
||||||
|
|
||||||
> Full event support: Start, Execute, Interrupt, Complete, Hit (modifiable damage/knockback), and Tick events. Start, Execute, and Hit are cancelable.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Commands:**
|
|
||||||
|
|
||||||
> `/kam ability list`, `types`, `info`, `delete`, `reload` for managing custom abilities.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Extras**
|
|
||||||
|
|
||||||
- Global ability presets that update everywhere when edited.
|
|
||||||
- Weighted ability selection for NPC random usage.
|
|
||||||
- Configurable min/max range per ability.
|
|
||||||
- Reusable telegraph presets shared across abilities.
|
|
||||||
@@ -1,199 +0,0 @@
|
|||||||
# ⚔️ CustomNPC+ 1.11 - Abilities ⚔️
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
The **Ability Update** introduces a full combat ability system to CNPC+! Give your NPCs powerful attacks with **visual telegraphs**, launch **energy projectiles** that home in on targets, and let players unlock abilities of their own!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## How Abilities Work 🎯
|
|
||||||
|
|
||||||
Every ability follows a **phase-based execution flow** that gives combat a readable, strategic feel.
|
|
||||||
|
|
||||||
**Phases:**
|
|
||||||
- **Wind-up** - The ability charges. Telegraphs appear, animations play, and observant players can react
|
|
||||||
- **Active** - The ability fires. Damage is dealt, projectiles launch, effects apply
|
|
||||||
- **Dazed** - Optional recovery state if the ability is interrupted during wind-up
|
|
||||||
|
|
||||||
**Core Configuration:**
|
|
||||||
- **Cooldown** - Time before the ability can be used again
|
|
||||||
- **Targeting Mode** - Aggro Target, Self, AOE on Self, or AOE on Target
|
|
||||||
- **Range** - Configurable min and max range for activation
|
|
||||||
- **Lock Movement** - Lock the caster's movement, rotation, or both during any phase
|
|
||||||
- **Interruptible** - Allow damage to interrupt wind-up and force a dazed state
|
|
||||||
- **Weight** - Priority weighting for NPC random ability selection
|
|
||||||
|
|
||||||
> Abilities support both **inline configuration** on individual NPCs and **global presets** that update everywhere when edited.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Melee Abilities 🗡️
|
|
||||||
|
|
||||||
Close-range attacks that hit hard and punish positioning.
|
|
||||||
|
|
||||||
- **Slam** - Leap toward the target in an arc, dealing AOE damage on impact. Configurable radius, knockback, and leap height
|
|
||||||
- **Heavy Hit** - A single powerful melee strike with bonus knockback
|
|
||||||
- **Cutter** - A slashing arc attack in a cone. Configurable angle and reach
|
|
||||||
- **Shockwave** - An AOE burst radiating outward from the caster
|
|
||||||
|
|
||||||
> All melee abilities support configurable **damage**, **knockback**, and **potion effects** on hit.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Energy Projectiles ✨
|
|
||||||
|
|
||||||
A brand new projectile system built from the ground up with full visual customization.
|
|
||||||
|
|
||||||
### Orbs
|
|
||||||
|
|
||||||
Homing energy spheres that track their target through the air.
|
|
||||||
|
|
||||||
- **Orb** - A single homing projectile
|
|
||||||
- **Dual Orb** - Fires two orbs simultaneously
|
|
||||||
- **Orb Barrage** - Fires a volley of orbs in rapid sequence
|
|
||||||
|
|
||||||
### Discs
|
|
||||||
|
|
||||||
Flat spinning projectiles with optional **boomerang** behavior.
|
|
||||||
|
|
||||||
- **Disc** - A single spinning disc with configurable radius and thickness
|
|
||||||
- **Dual Disc** - Fires two discs simultaneously
|
|
||||||
|
|
||||||
### Beams
|
|
||||||
|
|
||||||
Sustained energy beams that connect the caster to their target.
|
|
||||||
|
|
||||||
- **Beam** - A homing beam with configurable width and head size. Locks the caster in place during channeling
|
|
||||||
- **Dual Beam** - Fires two beams simultaneously
|
|
||||||
|
|
||||||
### Laser Shot
|
|
||||||
|
|
||||||
An **instant-fire** projectile with configurable width and speed. No homing — pure aim.
|
|
||||||
|
|
||||||
### Projectile
|
|
||||||
|
|
||||||
A standard projectile using classic Minecraft physics for a more traditional ranged attack.
|
|
||||||
|
|
||||||
### Energy Configuration
|
|
||||||
|
|
||||||
Every energy projectile shares a **modular data system** for deep customization:
|
|
||||||
|
|
||||||
- **Anchor Point** - Choose where the projectile spawns: Right Hand, Left Hand, Front, Center, Chest, or Above Head
|
|
||||||
- **Display** - Set core color, edge color, glow effect, transparency, and size
|
|
||||||
- **Homing** - Toggle homing, adjust turn rate and max tracking range
|
|
||||||
- **Combat** - Damage, knockback, vertical knockback, hit cooldown, and optional AOE splash
|
|
||||||
- **Lifespan** - Projectile speed, max age, and max travel distance
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Movement Abilities 💨
|
|
||||||
|
|
||||||
Abilities that reposition the caster in combat.
|
|
||||||
|
|
||||||
- **Charge** - Rush forward in a line, damaging all entities in the path. Configurable speed, hit width, and knockback
|
|
||||||
- **Dash** - A quick directional movement without dealing damage
|
|
||||||
- **Teleport** - Instantly relocate to the target's position
|
|
||||||
|
|
||||||
> **Charge** locks direction during wind-up, so the telegraph accurately shows the attack path.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## AOE Abilities 🌀
|
|
||||||
|
|
||||||
Area control abilities that dominate space.
|
|
||||||
|
|
||||||
- **Sweeper** - A wide rotational sweep attack around the caster with configurable radius and rotation speed
|
|
||||||
- **Vortex** - Creates a pulling force that drags nearby entities toward the center while dealing damage
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Telegraph System 📍
|
|
||||||
|
|
||||||
**Telegraphs** are visual ground indicators that warn players before an ability lands. They appear during the wind-up phase and disappear when the ability fires.
|
|
||||||
|
|
||||||
**Shapes:**
|
|
||||||
- **Circle** - Filled circle with configurable radius
|
|
||||||
- **Ring** - Donut shape with inner and outer radius
|
|
||||||
- **Line** - Rectangle along the attack direction
|
|
||||||
- **Cone** - Fan/wedge shape with configurable angle
|
|
||||||
- **Point** - Single point indicator
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- **Color Customization** - Set ARGB colors for both the telegraph and its warning phase
|
|
||||||
- **Warning Phase** - Color shifts in the final ticks before the ability fires
|
|
||||||
- **Entity Tracking** - Telegraphs can follow a moving entity or stay at a fixed position
|
|
||||||
- **Smooth Interpolation** - Position updates are interpolated for clean visuals
|
|
||||||
|
|
||||||
> Telegraphs are saved as **reusable presets** and can be shared across multiple abilities.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Animations & Sound 🎬
|
|
||||||
|
|
||||||
Abilities integrate directly with the animation and sound systems.
|
|
||||||
|
|
||||||
- **Wind-up Animation** - Plays during the charging phase
|
|
||||||
- **Active Animation** - Plays when the ability fires
|
|
||||||
- **Animation Sync** - Optionally sync wind-up duration to match animation length exactly
|
|
||||||
- **Sound Events** - Assign custom sounds to both wind-up and active phases
|
|
||||||
- **Phase Colors** - Visual color feedback on the caster during wind-up and active
|
|
||||||
|
|
||||||
> Many ability types include **built-in animation names** that work automatically when matching animations exist.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Effects & Conditions ⚡
|
|
||||||
|
|
||||||
### Potion Effects
|
|
||||||
|
|
||||||
Abilities can apply **potion effects** to any entity they hit. Each effect has configurable type, duration, and amplifier.
|
|
||||||
|
|
||||||
**Available Effects:**
|
|
||||||
Slowness, Weakness, Poison, Wither, Blindness, Nausea, Hunger, Mining Fatigue
|
|
||||||
|
|
||||||
### Conditions
|
|
||||||
|
|
||||||
Abilities support a **condition system** that controls when they can be used. Conditions are evaluated before execution and can require specific target states, ranges, or custom predicates.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Player Abilities 🧑
|
|
||||||
|
|
||||||
Players can unlock and use abilities too!
|
|
||||||
|
|
||||||
- **Unlock System** - Players receive abilities via scripting or commands
|
|
||||||
- **Ability Selection** - Choose one ability at a time from your unlocked list
|
|
||||||
- **Universal Cooldown** - Shared cooldown across all player abilities
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Scripting API 📜
|
|
||||||
|
|
||||||
Full scripting support for ability lifecycle events:
|
|
||||||
|
|
||||||
- **StartEvent** *(Cancelable)* - Fired when wind-up begins
|
|
||||||
- **ExecuteEvent** *(Cancelable)* - Fired when the ability activates
|
|
||||||
- **InterruptEvent** - Fired when wind-up is interrupted by damage
|
|
||||||
- **CompleteEvent** - Fired when the ability finishes
|
|
||||||
- **HitEvent** *(Cancelable)* - Fired on each entity hit. Damage and knockback values can be modified
|
|
||||||
- **TickEvent** - Fired every tick with current phase and tick count
|
|
||||||
|
|
||||||
> Scripts can cancel, modify damage, and react to every phase of ability execution.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Ability Preview 🔎
|
|
||||||
|
|
||||||
The ability editor includes a **live preview system**. Test your telegraph shapes, animations, and projectile visuals directly in the GUI on a dummy NPC — no world effects applied.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Ability Commands 💬
|
|
||||||
|
|
||||||
- `/kam ability list` - List all custom abilities
|
|
||||||
- `/kam ability types` - List all registered ability types
|
|
||||||
- `/kam ability info <name|uuid>` - View ability details
|
|
||||||
- `/kam ability delete <uuid>` - Delete a custom ability
|
|
||||||
- `/kam ability reload` - Reload abilities from disk
|
|
||||||
|
|
||||||
---
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
# CNPC+ 1.11 Beta - Market Update
|
|
||||||
|
|
||||||
🟡 **In Testing**
|
|
||||||
|
|
||||||
## Features: ⚒️
|
|
||||||
|
|
||||||
- **Built-in Currency System:**
|
|
||||||
> Fully configurable economy currency used across all Market features. Profile persistent across character slots with Vault support for Bukkit-compatible plugins.
|
|
||||||
|
|
||||||
- **Auction House:**
|
|
||||||
> Global player marketplace for listing items, bidding, and instant buyouts. Auctions last 24 hours by default.
|
|
||||||
|
|
||||||
- **Auction Bidding & Snipe Protection:**
|
|
||||||
> Competitive bidding with a 5% minimum bid increment. Snipe Protection extends auctions on last-second bids. Outbid players are automatically refunded.
|
|
||||||
|
|
||||||
- **Buyout System:**
|
|
||||||
> Instant purchase at the seller's Buyout Price. Highest bidder only pays the difference between their bid and the buyout.
|
|
||||||
|
|
||||||
- **My Trades:**
|
|
||||||
> Single screen for managing Active Listings, Active Bids, and Pending Claims. Players can cancel listings with a 10% penalty if bids exist.
|
|
||||||
|
|
||||||
- **Auction Notifications:**
|
|
||||||
> Real-time notifications for sales, outbids, and wins. Offline players receive a claim summary on login.
|
|
||||||
|
|
||||||
- **Trade Slots:**
|
|
||||||
> Limited slots (default 8, max 45) shared across listings, bids, and claims. Configurable via permissions.
|
|
||||||
|
|
||||||
- **Claim Expiration:**
|
|
||||||
> Uncollected claims expire after 20 days.
|
|
||||||
|
|
||||||
- **Item Blacklist:**
|
|
||||||
> Block items by registry name, wildcard pattern, mod, or NBT tag. Soulbound and Profile-Slotbound items are always blocked automatically.
|
|
||||||
|
|
||||||
- **Listing Fee & Sales Tax:**
|
|
||||||
> Configurable listing fee charged on creation and sales tax taken from successful sales.
|
|
||||||
|
|
||||||
- **Search & Sorting:**
|
|
||||||
> Search by item name or seller. Sort by newest, ending soon, price, or most bids.
|
|
||||||
|
|
||||||
- **Trader Stock System:**
|
|
||||||
> Limited stock with Global or Per-Player modes. Restock timers for MC Daily/Weekly, RL Daily/Weekly, or Custom intervals.
|
|
||||||
|
|
||||||
- **Trader Currency Trades:**
|
|
||||||
> Trades can require currency on top of item costs.
|
|
||||||
|
|
||||||
- **Auctioneer NPC Role:**
|
|
||||||
> New role that opens the Auction House on interaction. No configuration needed.
|
|
||||||
|
|
||||||
- **Auction Commands:**
|
|
||||||
> `/kam auction open` for players. Admin commands for listing view and player activity inspection.
|
|
||||||
|
|
||||||
**Extras**
|
|
||||||
|
|
||||||
- Auction logging for server admins (tracks creates, bids, buyouts, sales, expirations, cancellations, claims).
|
|
||||||
- Lifetime currency tracking per player (total earned and spent).
|
|
||||||
- Configurable starting balance and max balance cap.
|
|
||||||
- Blacklist bypass permission for admins.
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
# 🏪 CustomNPC+ 1.11 - Market Update 🏪
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
The **Market Update** brings a complete economy system to CNPC+! Create bustling marketplaces with **Traders** that have limited stock, or let players trade with each other through the brand new **Auction House**!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Currency System 💰
|
|
||||||
|
|
||||||
CNPC+ now has a **built-in currency** used across all Market features!
|
|
||||||
|
|
||||||
- **Fully Configurable** - Name it Coins, Gold, Credits, whatever fits your world. Set a starting balance and max balance cap to shape your economy
|
|
||||||
- **Profile Persistent** - Currency carries across all your character slots
|
|
||||||
- **Vault Support** - Integrates seamlessly with Bukkit-compatible economy plugins if Vault is installed. Falls back to built-in currency otherwise
|
|
||||||
- **Lifetime Tracking** - Tracks total earned and spent per player
|
|
||||||
|
|
||||||
> Full Scripting API support for currency operations on players.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Auction House 🏛️
|
|
||||||
|
|
||||||
A **global player marketplace** where players can list items, bid against each other, and purchase instantly! Search for items by name or seller, and sort by newest, ending soon, price, or most bids.
|
|
||||||
|
|
||||||
### Selling
|
|
||||||
|
|
||||||
List any item with a **Starting Price** for competitive bidding. Set an optional **Buyout Price** for players who want to skip the wait and buy immediately. Auctions last **24 hours** by default.
|
|
||||||
|
|
||||||
> A configurable **Listing Fee** is charged when creating auctions, and a **Sales Tax** is taken from successful sales.
|
|
||||||
|
|
||||||
### Bidding
|
|
||||||
|
|
||||||
Compete for items by placing bids! Each bid must be at least **5%** higher than the current bid. **Snipe Protection** extends auctions when last-second bids come in, giving everyone a fair shot. If you get outbid, your currency is **automatically refunded**.
|
|
||||||
|
|
||||||
### Buyout
|
|
||||||
|
|
||||||
See something you need right now? Hit **Buy Now** to purchase instantly at the seller's Buyout Price. If you're currently the highest bidder on an item, you only pay the **difference** between your bid and the buyout.
|
|
||||||
|
|
||||||
### My Trades
|
|
||||||
|
|
||||||
One screen to manage all your auction activity:
|
|
||||||
|
|
||||||
- **Active Listings** - Items you're currently selling
|
|
||||||
- **Active Bids** - Auctions you're competing in
|
|
||||||
- **Ready to Claim** - Won items and currency waiting for pickup
|
|
||||||
|
|
||||||
Players can **cancel** their own listings -- items are returned as a claim. If there are active bids on the listing, a **10% cancellation penalty** is charged.
|
|
||||||
|
|
||||||
> Claims expire after **20 days**. Make sure to collect your items and currency before they're gone!
|
|
||||||
|
|
||||||
### Notifications
|
|
||||||
|
|
||||||
Get notified immediately when your item sells, when you're outbid, or when you win an auction. Offline? You'll get a full **claim summary** when you log back in showing exactly what's waiting for you.
|
|
||||||
|
|
||||||
### Trade Slots
|
|
||||||
|
|
||||||
Every player gets a limited number of **Trade Slots** (default 8). Slots are shared across Active Listings, Active Bids, **and** Pending Claims -- so uncollected claims take up space. Pick up your claims to free slots for new listings and bids!
|
|
||||||
|
|
||||||
> Server owners can grant players more slots via permissions up to a maximum of 45.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Item Blacklist 🚫
|
|
||||||
|
|
||||||
Server owners have full control over what items can be listed on the Auction House.
|
|
||||||
|
|
||||||
**Block by:**
|
|
||||||
- **Item** - Specific registry names like `minecraft:diamond_sword`
|
|
||||||
- **Wildcard** - Patterns like `minecraft:diamond*` to block all diamond items
|
|
||||||
- **Mod** - Block all items from a specific mod
|
|
||||||
- **NBT Tag** - Block items containing certain NBT data
|
|
||||||
|
|
||||||
> **Soulbound** and **Profile-Slotbound** items are always blocked automatically, regardless of blacklist settings. Bound items cannot be traded!
|
|
||||||
|
|
||||||
Manage the blacklist in-game with `/kam auction blacklist` commands, or configure it directly in the config file.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Trader Enhancements 🛒
|
|
||||||
|
|
||||||
### Stock System
|
|
||||||
|
|
||||||
Traders now support **limited stock** with automatic restocking!
|
|
||||||
|
|
||||||
**Stock Modes:**
|
|
||||||
- **Global** - All players share the same stock pool
|
|
||||||
- **Per-Player** - Each player has their own purchase limits
|
|
||||||
|
|
||||||
**Restock Timers:**
|
|
||||||
- **MC Daily / Weekly** - Restock based on Minecraft time
|
|
||||||
- **RL Daily / Weekly** - Restock based on real-life time
|
|
||||||
- **Custom** - Set your own interval in MC ticks or real-time
|
|
||||||
|
|
||||||
Stock counts, out-of-stock status, and restock timers are all visible directly in the trade interface.
|
|
||||||
|
|
||||||
> Admins can manually reset stock or cooldowns via the Trader GUI.
|
|
||||||
|
|
||||||
### Currency Trades
|
|
||||||
|
|
||||||
Trades can now require **currency on top of items**. Combine material costs with coin costs for balanced economy progression!
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Auctioneer Role 🧑💼
|
|
||||||
|
|
||||||
New NPC role for the Auction House! Set the role on any NPC and players can access the full Auction House by interacting with them -- no extra configuration needed. The role respects the global Auction Enabled setting.
|
|
||||||
|
|
||||||
### Auction Commands
|
|
||||||
|
|
||||||
Players can also access the Auction House via command:
|
|
||||||
|
|
||||||
- `/kam auction open` - Opens the Auction House GUI
|
|
||||||
|
|
||||||
**Admin Commands:**
|
|
||||||
- `/kam auction list [page]` - View active auctions in chat
|
|
||||||
- `/kam auction view <player>` - View a player's auction activity
|
|
||||||
|
|
||||||
> Server owners can enable **auction logging** to track all auction activity (creates, bids, buyouts, sales, expirations, cancellations, and claims).
|
|
||||||
|
|
||||||
---
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
# CustomNPC+ 1.11 Changelog
|
||||||
|
|
||||||
|
## Ability System
|
||||||
|
- Phase-based abilities (Wind-up, Active, Dazed) with configurable cooldowns, targeting, range, interrupts, invulnerability, and magic damage
|
||||||
|
- **Melee:** Slam, Heavy Hit, Cutter
|
||||||
|
- **Energy Projectiles:** Orb, Disc, Beam, Laser Shot with variant system, homing, hit types (Single/Pierce/Multi), size interpolation, explosions
|
||||||
|
- **Barriers:** Dome, Wall, Shield with HP, reflection, damage absorption
|
||||||
|
- **Defensive:** Guard, Counter, Dodge
|
||||||
|
- **Movement:** Charge, Dash, Teleport
|
||||||
|
- **AOE:** Shockwave, Sweeper, Vortex
|
||||||
|
- **Hazards & Traps:** Persistent zones and proximity triggers with visual presets
|
||||||
|
- **Effect:** Healing, buffs, debuffs with target filtering (Allies/Enemies/All)
|
||||||
|
- **Custom Ability:** Blank-slate type with full script hooks and toggle modes
|
||||||
|
- Burst system, chained ability combos with concurrency, telegraph system (6 shapes)
|
||||||
|
- Per-phase animations and sound events
|
||||||
|
- Ability conditions: HP Threshold, Hit Count, Has Item, Quest Completed, Has Effect
|
||||||
|
- 12-slot player ability hotbar with HUD editor
|
||||||
|
- Full scripting API for ability and energy projectile lifecycle events
|
||||||
|
- Ability Extender system for custom hooks
|
||||||
|
- Live preview in editor
|
||||||
|
- Commands: `/kam ability list|types|prebuilts|info|delete|reload|give|remove|giveChain|removeChain|player`
|
||||||
|
|
||||||
|
## Auction House
|
||||||
|
- Global marketplace with bidding, buyout, and snipe protection
|
||||||
|
- Built-in currency system (configurable, profile-persistent, Vault support)
|
||||||
|
- Listing fees, sales tax, minimum prices
|
||||||
|
- My Trades panel with claim management (20-day expiry)
|
||||||
|
- Search/sort, notifications (online + offline summary)
|
||||||
|
- Trade slots (default 8, expandable via permissions)
|
||||||
|
- Item blacklist (by item, wildcard, mod, NBT; soulbound always blocked)
|
||||||
|
- Auctioneer NPC role
|
||||||
|
- Admin GUI and logging
|
||||||
|
- Cancelable scripting events: Create, Bid, Buyout, Cancel, Claim
|
||||||
|
|
||||||
|
## Script Editor
|
||||||
|
- Full code editor with syntax highlighting, autocomplete, error detection, and hover tooltips
|
||||||
|
- Go to Line, Search/Replace, Go to Definition, Fullscreen
|
||||||
|
- Undo/Redo, Duplicate Line, Comment Toggle, Rename, Move Lines
|
||||||
|
- Line numbers, smooth scrolling, indent guides, brace matching, smart brackets
|
||||||
|
|
||||||
|
## Java Scripting
|
||||||
|
- Write scripts in Java via Janino compiler with automatic hook resolution
|
||||||
|
- Per-tab language selector (mix Java and JavaScript)
|
||||||
|
- External `.java` file support
|
||||||
|
|
||||||
|
## Client-Side Scripting
|
||||||
|
- Server-controlled client script execution with auto-sync (off by default)
|
||||||
|
|
||||||
|
## Addon API Support
|
||||||
|
- Ship `.d.ts` type definitions for automatic script editor autocomplete
|
||||||
|
- Patch support for extending CNPC+ types, hot reload
|
||||||
|
|
||||||
|
## Traders
|
||||||
|
- Stock system: Global or Per-Player modes with configurable restock timers
|
||||||
|
- Currency trades (items + coins)
|
||||||
|
- Client-side balance preview
|
||||||
|
|
||||||
|
## Cloner
|
||||||
|
- Folder and subfolder organization for all categories
|
||||||
|
- Full-width directory browser, improved tabs, tag-based filtering
|
||||||
|
|
||||||
|
## Animations
|
||||||
|
- Data store for passing data across events/frames
|
||||||
|
- Consumer-based task system
|
||||||
|
- Expanded scripting API
|
||||||
|
|
||||||
|
## Animated Textures
|
||||||
|
- Frame-based animation for items, effect icons, ability hotbar, scripted GUIs
|
||||||
|
|
||||||
|
## NPC API
|
||||||
|
- `IHitboxData` (width/height scaling), `ITintData` (hurt tint, persistent tints)
|
||||||
|
- Scriptable behavior: sprint, swim, doors, fire reactions, tactical chance, walking range
|
||||||
|
- `ISound` (volume, pitch, repeat, position)
|
||||||
|
- Skin overlay `getColor()`/`setColor()`, knockback API
|
||||||
|
- Six overlays in singleplayer, script error reporting to console
|
||||||
|
|
||||||
|
## NPC Combat & Behavior
|
||||||
|
- Attack speed enforcement, passive faction protection
|
||||||
|
- Improved track speed, invalid texture fallback
|
||||||
|
|
||||||
|
## Other Changes
|
||||||
|
- Player Dialog Events match NPC Dialog Events
|
||||||
|
- Linked Item attack speed and scripting API
|
||||||
|
- Right-click cycling on multi-option buttons
|
||||||
|
- Legacy quest import (1.6.4), fullscreen/pannable GUIs, unified menu background
|
||||||
|
- Textfield CTRL shortcuts, `java.lang.reflect` banned in scripts
|
||||||
|
- Entity packet loss fix (invisible NPCs)
|
||||||
|
- Natural spawn GUI, runtime control, and despawn improvements
|
||||||
|
|
||||||
|
## Bug Fixes
|
||||||
|
- Script config sync, Bukkit integration
|
||||||
|
- Quest cooldown for MC/RL Custom timers, quest/dialog saving and categories
|
||||||
|
- Bard music restart on dialog open
|
||||||
|
- Spawner yaw, biome spawn persistence, NPC invisibility
|
||||||
|
- Track speed, set speed edge cases, spawn data, block waypoints, job spawner
|
||||||
|
- Hitbox scaling and collision
|
||||||
|
- Animation offsets, lookup failures, syncing, resync on teleport, registration names, double loading
|
||||||
|
- Mount movement jitter, dismount edge cases
|
||||||
@@ -1,95 +1,432 @@
|
|||||||
|

|
||||||
|
|
||||||
## 👋 Welcome to the CustomNPC+ Repository.
|
# CustomNPC+
|
||||||

|
|
||||||
|
|
||||||
> CustomNPC+ is a [Minecraft](https://minecraft.net/) mod that allows you to add custom NPCs to your world. It is developed for creative and storytelling players who want to make their Minecraft worlds more in-depth and unique. CustomNPC+ is only a branch version of the **1.7.10** Forge version of the original (down below) and has no plans to add or update any other version. This is not an official version of CustomNPC.
|
**CustomNPC+** is a Minecraft 1.7.10 Forge mod that lets you create fully customizable NPCs with advanced AI, combat abilities, quests, dialogs, scripting, an economy system, and much more. Built for creative and storytelling players who want to transform their worlds into living RPG experiences.
|
||||||
|
|
||||||
----------------
|
> CustomNPC+ is a branch version of the original [CustomNPC](https://www.curseforge.com/minecraft/mc-mods/custom-npcs) by [Noppes](https://github.com/Noppes), developed with permission. This is not an official version of CustomNPC.
|
||||||
|
|
||||||
<a href="https://discord.gg/pQqRTvFeJ5"> <img src="https://img.shields.io/badge/KAMKEEL_Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" width="400" height="60"> </a>
|
---
|
||||||
<a href="https://ko-fi.com/kamkeel"> <img src="https://img.shields.io/badge/Support_Me_|_Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white" alt="Support Me" width="400" height="60"> </a>
|
|
||||||
|
<a href="https://discord.gg/pQqRTvFeJ5"> <img src="images/Discord.png" width="400" height="60"> </a>
|
||||||
|
|
||||||
[](https://modrinth.com/mod/customnpc-plus)
|
[](https://modrinth.com/mod/customnpc-plus)
|
||||||
[](https://www.curseforge.com/minecraft/mc-mods/moreplayermodels-plus)
|
[](https://www.curseforge.com/minecraft/mc-mods/moreplayermodels-plus)
|
||||||
[](https://github.com/KAMKEEL/Plugin-Mod)
|
[](https://github.com/KAMKEEL/Plugin-Mod)
|
||||||
|
|
||||||
----------------
|
---
|
||||||
|
|
||||||
### ❗ Notice
|
## Installation
|
||||||
I am not the original creator of CustomNPC. The original creator is @[Noppes](https://github.com/Noppes). I have been permitted to update and develop my own branch version for 1.7.10. The original mod that is updated to the latest versions of Minecraft can be found on these links: [CurseForge](https://www.curseforge.com/minecraft/mc-mods/custom-npcs), [kodevelopment](http://www.kodevelopment.nl/minecraft/customnpcs)
|
|
||||||
|
|
||||||
### ⬇️ Downloads
|
CustomNPC+ is a **replacement** for the original CustomNPC — not an add-on. Do not install both together. Simply drop CustomNPC+ into your client or server mods folder. All original CustomNPC features are preserved and expanded upon.
|
||||||
|
|
||||||
|
> Please **backup your world** before installing. Report any bugs on the [issue tracker](https://github.com/KAMKEEL/CustomNPC-Plus/issues).
|
||||||
|
|
||||||
|
### Downloads
|
||||||
|
|
||||||
- **Modrinth**: [Download](https://modrinth.com/mod/customnpc-plus)
|
- **Modrinth**: [Download](https://modrinth.com/mod/customnpc-plus)
|
||||||
- **CurseForge**: [Download](https://www.curseforge.com/minecraft/mc-mods/customnpc-plus)
|
- **CurseForge**: [Download](https://www.curseforge.com/minecraft/mc-mods/customnpc-plus)
|
||||||
|
|
||||||
### 🔹 Installation
|
---
|
||||||
This mod is an ***update*** to CustomNPC and not an add-on. Do not install CustomNPC with CustomNPC-Plus. CustomNPC-Plus does not remove any functional features from the original mod. It expands upon CustomNPC with original features and backported features from newer versions. Simply drag CustomNPC-Plus into any client/server mods folder to utilize. Please **backup** before using as this could still have unforeseen errors. Report any bugs if found, thank you and enjoy.
|
|
||||||
|
|
||||||
### ❓ Features:
|
<a href="https://ko-fi.com/kamkeel"> <img src="images/Kofi.png" width="400" height="60"> </a>
|
||||||
- Flying NPC (Smart Pathfinding)
|
|
||||||
- 1.8 Skin Support (64x64) (Alex/Steve64)
|
|
||||||
- Full URL64 Selector (Downloads FULL Size Images for Custom Mob Skins)
|
|
||||||
- Additional Parts: [Wings, Fins, Capes, Horns, Tail]
|
|
||||||
- Hide Body Parts [Arms, Legs, Head, Body]
|
|
||||||
- Custom Overlays
|
|
||||||
- Animation Maker
|
|
||||||
- Enhanced Cloner GUI (More Tabs, Filters, Tags)
|
|
||||||
- Markov Name Generator
|
|
||||||
- Dark Mode GUI (Link Below)
|
|
||||||
- 1.12 Scripting Features (Details below)
|
|
||||||
- Profile System (Multiple Character Slots)
|
|
||||||
- Quest Party System
|
|
||||||
- Item and Armor Attributes
|
|
||||||
- Magic System with Elemental Cycles
|
|
||||||
- Custom Effect Engine
|
|
||||||
- Scripted Blocks & Particles
|
|
||||||
- Compass Marks for Waypoints
|
|
||||||
- Custom Model Support
|
|
||||||
- Gecko & Dragon Block C Addons
|
|
||||||
|
|
||||||
#### Scripting:
|
> More betas with new features will continue to be released to supporters for **Early Access** to new content!
|
||||||
- CustomNPC+ Api: [API](https://github.com/KAMKEEL/CustomNPC-Plus-API)
|
|
||||||
- Java Doc: [kamkeel.github.io/CustomNPC-Plus](https://kamkeel.github.io/CustomNPC-Plus/)
|
|
||||||
- Scripted Items
|
|
||||||
- Player Overlays
|
|
||||||
- Script Timers
|
|
||||||
- Global Scripts
|
|
||||||
- Script Logging
|
|
||||||
- GUI Overlays
|
|
||||||
- Event Scripting
|
|
||||||
(We never remove script functionality, only add on existing functions)
|
|
||||||
|
|
||||||
## 🔰 Skin Model Feature:
|
---
|
||||||
###### **Majority of these cape designs are taken from the internet with fair-usage.*
|
|
||||||
##### ❔ Please note all *local* skins in this version of CustomNPC, must match the model selected.
|
## Feature Overview
|
||||||
<img src="images/skinAnimation.gif" width="474" height="260"/>
|
|
||||||
|
### NPC Creation & Customization
|
||||||
|
|
||||||
|
Create NPCs with deep visual customization and lifelike behavior.
|
||||||
|
|
||||||
|
<img src="images/NPCEditor.gif" width="474" height="260"/>
|
||||||
|
|
||||||
|
- **Skin System** - 1.8 skin support (64x64), Alex & Steve64 models, full URL64 selector that downloads full-size images for custom skins
|
||||||
|
- **Body Parts** - Wings, fins, capes, horns, tails. Hide individual body parts (arms, legs, head, body)
|
||||||
|
- **Skin Overlays** - Layer additional textures on top of the base skin with color tinting and alpha control
|
||||||
|
- **Custom Models** - Support for custom model formats, plus Gecko and DBC addon model integration
|
||||||
|
- **Hitbox Scaling** - Independently scale NPC hitbox width and height
|
||||||
|
- **Tint System** - Control hurt flash color and apply persistent color tints
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### NPC AI & Behavior
|
||||||
|
|
||||||
|
NPCs have a full AI system for combat, pathing, and interaction.
|
||||||
|
|
||||||
|
- **Flying NPCs** - Smart pathfinding in 3D space for flying entities
|
||||||
|
- **Combat AI** - Multiple tactical behaviors: attack, ranged attack, ambush, pounce, dodge-shoot, zigzag, stalk, orbit, sprint-to-target, and leap attacks
|
||||||
|
- **Movement Types** - Standing, wandering, and moving path modes
|
||||||
|
- **Pathfinding** - Ground, flying, and water navigation
|
||||||
|
- **Door Interaction** - NPCs can break, open, or ignore doors
|
||||||
|
- **Behavior Controls** - Configurable sprinting, swimming, fire reactions, tactical chance, and walking range
|
||||||
|
- **Attack Speed** - NPCs respect attack speed timing when dealing damage
|
||||||
|
- **Faction Awareness** - NPCs respond to faction standings. Passive faction NPCs are protected from damage
|
||||||
|
|
||||||
#### Flying NPCs:
|
|
||||||
<img src="images/FlyingNPC.gif" width="474" height="260"/>
|
<img src="images/FlyingNPC.gif" width="474" height="260"/>
|
||||||
|
|
||||||
#### Url64:
|
---
|
||||||
<img src="images/Url64Example.gif" width="474" height="260"/>
|
|
||||||
|
|
||||||
#### DarkMode + Cloner GUI:
|
### NPC Roles & Jobs
|
||||||
<img src="images/ClonerGUI-DarkMode.png" width="474" height="260"/>
|
|
||||||
|
|
||||||
## 🔗 Want to check out my other projects?
|
**Roles** give NPCs interactive functions — Trader, Follower, Bank, Transporter, Postman, Companion, Mount, and Auctioneer. **Jobs** give NPCs background tasks — Bard, Healer, Guard, Item Giver, Follower, Spawner, Conversation, and Chunk Loader.
|
||||||
[Plugin Mod](https://github.com/KAMKEEL/Plugin-Mod) is a mod designed to add more aesthetic items for RPG and storytelling. It is compatible with CustomNPC+ and has many items intended to be used and wielded by created NPCs.
|
|
||||||
|
|
||||||
[RPG Messenger](https://github.com/KAMKEEL/RPGMessenger) is a bukkit plugin designed to allow operators to create messagable NPCs for RPG Servers. Allows a 'RPG Controller' to reply quickly as NPCs, form groupchats, and messagable parties.
|
---
|
||||||
|
|
||||||
[CustomNPC+ Dark Mode](https://github.com/KAMKEEL/CustomNPC-Plus-Dark-Mode) is a resource pack for CustomNPC+ that alters all GUIs within the mod to a dark variant that is both clean and pleasing to look at.
|
### Dialog System
|
||||||
|
|
||||||
## Cloning / Compiling / Building
|
Create branching dialog trees for storytelling and player interaction.
|
||||||
|
|
||||||
git clone call `git submodule update --init --recursive`
|
<img src="images/Dialog.png" width="474" height="260"/>
|
||||||
|
|
||||||
Using IntelliJ, take the following steps:
|
- **Dialog Trees** - Multi-level branching conversations with unlimited depth
|
||||||
1. Run `setupDecompWorkspace` under the `forgegradle` tab.
|
- **Dialog Options** - Player choices that affect outcomes, trigger quests, or change faction standings
|
||||||
2. Refresh Gradle.
|
- **Dialog Images** - Display images alongside dialog text
|
||||||
3. Run `genIntellijRuns` under the `other` tab to set up your Minecraft runs.
|
- **Dialog Colors** - Customizable text and background colors
|
||||||
|
- **Categories** - Organize dialogs into categories for large projects
|
||||||
|
- **Availability Conditions** - Show or hide dialogs based on quests, factions, items, or custom conditions
|
||||||
|
- **Script Hooks** - Full scripting support for dialog open, close, and option events
|
||||||
|
|
||||||
or for Eclipse, run `gradlew setupDecompWorkspace eclipse` then import the project.
|
---
|
||||||
|
|
||||||
Mixin code will not work if you do not add `--tweakClass org.spongepowered.asm.launch.MixinTweaker --mixin customnpcs.mixins.json` to your program arguments.
|
### Quest System
|
||||||
|
|
||||||
|
A complete quest framework for RPG progression.
|
||||||
|
|
||||||
|
<img src="images/QuestMarks.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
- **Quest Types** - Item collection, dialog completion, kill targets, reach locations, area kills, and fully manual (script-driven) quests
|
||||||
|
- **Quest Tracking** - On-screen HUD overlay showing active quest objectives
|
||||||
|
- **Categories** - Organize quests into categories
|
||||||
|
- **Rewards** - Configure item, XP, and currency rewards
|
||||||
|
- **Cooldowns** - Repeatable quests with MC time, real-time, or custom cooldown intervals
|
||||||
|
- **Party Quests** - Share quest objectives across party members with configurable sharing modes
|
||||||
|
- **Availability** - Control quest visibility based on completed quests, faction standing, dialogs, and more
|
||||||
|
- **Script Hooks** - Events for quest start, completion, turn-in, and custom quest objectives
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Ability System
|
||||||
|
|
||||||
|
A full combat ability system for both NPCs and players.
|
||||||
|
|
||||||
|
<img src="images/NPCAbilities.gif" width="474" height="260"/>
|
||||||
|
<img src="images/PlayerAbilities.gif" width="474" height="260"/>
|
||||||
|
|
||||||
|
**Melee Abilities** - Slam, Heavy Hit, Cutter
|
||||||
|
**Energy Projectiles** - Orbs, Discs, Beams, Laser Shots with full visual customization, homing, and hit types
|
||||||
|
**Energy Barriers** - Domes, Walls, Shields with HP, reflection, and damage absorption
|
||||||
|
**Defensive** - Guard, Counter, Dodge with configurable damage reduction and counter-attacks
|
||||||
|
**Movement** - Charge, Dash, Teleport
|
||||||
|
**AOE** - Shockwave, Sweeper, Vortex
|
||||||
|
**Hazards & Traps** - Persistent damage zones and proximity-triggered traps with visual presets
|
||||||
|
**Support** - Ability Effect for healing, buffs, and debuffs
|
||||||
|
|
||||||
|
**Key Features:**
|
||||||
|
- Phase-based execution (Wind-up, Active, Dazed) with visual telegraphs
|
||||||
|
- Burst system for rapid multi-fire
|
||||||
|
- Chained abilities for sequential combos
|
||||||
|
- Player ability hotbar (12 slots) with unlock system
|
||||||
|
- Full scripting API for every lifecycle event
|
||||||
|
- Live preview in the ability editor
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Auction House & Economy
|
||||||
|
|
||||||
|
A complete marketplace and economy system.
|
||||||
|
|
||||||
|
<img src="images/Auction.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
- **Built-in Currency** - Configurable currency with starting balance, max cap, and Vault plugin integration
|
||||||
|
- **Auction House** - Global player marketplace with bidding, buyout, snipe protection, and notifications
|
||||||
|
- **Trade Slots** - Configurable per-player slot limits via permissions
|
||||||
|
- **Item Blacklist** - Block items by name, wildcard, mod, or NBT tag from being listed
|
||||||
|
- **Admin Tools** - Dedicated admin GUI for managing listings and creating server auctions
|
||||||
|
- **Scripting API** - Cancelable events for creates, bids, buyouts, cancels, and claims
|
||||||
|
|
||||||
|
**Trader Enhancements:**
|
||||||
|
- Limited stock with automatic restocking (MC time, real-time, or custom intervals)
|
||||||
|
- Global or per-player stock modes
|
||||||
|
- Currency costs on top of item trades
|
||||||
|
- Client-side balance preview
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Script Editor
|
||||||
|
|
||||||
|
A full-featured code editor built right into Minecraft.
|
||||||
|
|
||||||
|
<img src="images/ScriptEditor.gif" width="474" height="260"/>
|
||||||
|
|
||||||
|
- **Syntax Highlighting** - Color-coded keywords, types, variables, methods, strings, and comments
|
||||||
|
- **Autocomplete** - Smart suggestions with type awareness, static vs instance context, and auto-imports
|
||||||
|
- **Error Detection** - Real-time underlining of wrong argument types, missing methods, type mismatches, and unused imports
|
||||||
|
- **Hover Info** - Full type information, documentation, and JSDoc rendering on hover
|
||||||
|
- **Navigation** - Go to line, search & replace, go to definition, and fullscreen mode
|
||||||
|
- **Editing** - Smart undo/redo, duplicate lines, comment toggle, rename refactoring, smart bracket pairing
|
||||||
|
- **Visual** - Line numbers, smooth scrolling, indent guides, brace matching, resizable panels
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Scripting
|
||||||
|
|
||||||
|
Write scripts in **JavaScript** or **Java** to control every aspect of the mod.
|
||||||
|
|
||||||
|
- **Java Scripting** - Write real Java code compiled by the Janino engine. Full support for classes, generics, lambdas, and method references
|
||||||
|
- **JavaScript** - Full Nashorn-based JavaScript with ECMAScript 5.1 globals (Math, JSON, Date, Number)
|
||||||
|
- **Client-Side Scripting** - Run scripts on the client for responsive visual experiences (server-controlled)
|
||||||
|
- **154+ Script Hooks** - Events for NPCs, players, blocks, items, quests, dialogs, factions, abilities, auction, animations, and more
|
||||||
|
- **Script Types** - NPC, Player, Global, Block, Item, Linked Item, Effect, Ability, Recipe, and Forge Event scripts
|
||||||
|
- **Scripted Blocks** - Blocks with full script hooks for click, redstone, neighbor changes, and more
|
||||||
|
- **Scripted Items** - Items with use, attack, toss, pickup, and durability hooks
|
||||||
|
- **Custom GUIs** - Build custom interfaces with buttons, text fields, scroll panels, and slots via scripting
|
||||||
|
- **GUI Overlays** - Persistent on-screen overlays with labels, lines, and textured rectangles
|
||||||
|
- **Addon API** - Mods can ship `.d.ts` type definitions for full autocomplete in the editor
|
||||||
|
|
||||||
|
**Resources:**
|
||||||
|
- API Repository: [CustomNPC+ API](https://github.com/KAMKEEL/CustomNPC-Plus-API)
|
||||||
|
- Java Docs: [kamkeel.github.io/CustomNPC-Plus](https://kamkeel.github.io/CustomNPC-Plus/)
|
||||||
|
|
||||||
|
<img src="images/ScriptedBlock.png" width="474" height="260"/>
|
||||||
|
<img src="images/ScriptedParticle.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Animation System
|
||||||
|
|
||||||
|
Create custom animations for NPCs directly in-game.
|
||||||
|
|
||||||
|
- **Animation Maker** - Visual editor for creating frame-based animations
|
||||||
|
- **Animation Parts** - Animate individual body parts with rotation, position, and scaling
|
||||||
|
- **Frame Events** - Script hooks for animation start, end, frame enter, and frame exit
|
||||||
|
- **Data Store** - Animations can store and pass data across events and frames
|
||||||
|
- **Task System** - Consumer-based callbacks for animation lifecycle
|
||||||
|
- **Built-in Animations** - Pre-made animations for abilities that work automatically
|
||||||
|
- **Multiple Registrations** - Register multiple animations under one common name
|
||||||
|
- **Animated Textures** - Frame-based animated textures for items, effects, and ability icons
|
||||||
|
|
||||||
|
<img src="images/AnimationMaker.gif" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Custom Effects
|
||||||
|
|
||||||
|
Create custom status effects beyond vanilla potions.
|
||||||
|
|
||||||
|
- **Custom Icons** - Each effect gets its own texture, with support for animated icons
|
||||||
|
- **Script Hooks** - Events for effect apply, tick, and removal
|
||||||
|
- **Ability Integration** - Abilities can apply custom effects to targets
|
||||||
|
- **Condition System** - Check if entities have specific effects for ability or availability conditions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Profile System
|
||||||
|
|
||||||
|
Multiple character slots on a single account.
|
||||||
|
|
||||||
|
- **Profile Slots** - Each slot stores separate quest progress, dialogs, factions, currency, abilities, and effects
|
||||||
|
- **Region Locking** - Lock profiles to specific areas
|
||||||
|
- **Soulbound Items** - Bind items to a specific player by UUID
|
||||||
|
- **Profile-Slotbound Items** - Bind items to a specific profile slot
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Party System
|
||||||
|
|
||||||
|
Group up with other players for cooperative gameplay.
|
||||||
|
|
||||||
|
- **Party Management** - Invite, kick, leave, disband, and transfer leadership
|
||||||
|
- **Quest Sharing** - Share quest objectives across party members
|
||||||
|
- **Ability Integration** - Party members are treated as allies for AOE ability targeting
|
||||||
|
- **Script Hooks** - Events for invites, kicks, leaves, disbands, and quest completion
|
||||||
|
|
||||||
|
<img src="images/PartySystem.png" width="474" height="260"/>
|
||||||
|
<img src="images/QuestParty.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Faction System
|
||||||
|
|
||||||
|
Create factions to control NPC relationships and player reputation.
|
||||||
|
|
||||||
|
- **Faction Points** - Players earn or lose standing with factions through quests, combat, and scripting
|
||||||
|
- **Availability Conditions** - Gate dialogs, quests, and content behind faction thresholds
|
||||||
|
- **NPC Behavior** - NPCs react to players based on faction standing (friendly, neutral, hostile)
|
||||||
|
- **Passive Factions** - Passive faction NPCs are protected from damage
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### HUD System
|
||||||
|
|
||||||
|
Customizable on-screen elements.
|
||||||
|
|
||||||
|
- **HUD Editor** - Drag and position HUD components to fit your screen
|
||||||
|
- **Ability Hotbar** - 12-slot bar with horizontal/vertical layout and configurable visible slots
|
||||||
|
- **Quest Tracking** - On-screen quest objective tracker
|
||||||
|
- **Compass** - Directional compass with quest and waypoint markers
|
||||||
|
- **Effect Bar** - Display active custom effects
|
||||||
|
|
||||||
|
<img src="images/HudSystem.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Cloner & Organization
|
||||||
|
|
||||||
|
Save, organize, and reuse NPCs and content.
|
||||||
|
|
||||||
|
- **Cloner Tabs** - Save and load NPCs, items, and other content
|
||||||
|
- **Folder System** - Organize with folders and subfolders for animations, abilities, forms, auras, outlines, effects, and linked items
|
||||||
|
- **Quick Tags** - Tag-based filtering for fast searching
|
||||||
|
- **Full Screen Browser** - Wide directory view for large collections
|
||||||
|
|
||||||
|
<img src="images/ClonerTabs.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Items & Blocks
|
||||||
|
|
||||||
|
A large library of custom items and decorative blocks.
|
||||||
|
|
||||||
|
**Weapons:** Battle Axe, Broadsword, Claw, Crossbow, Dagger, Staff, Glaive, Gun, Kunai, Scythe, Spear, Wand, Warhammer, Musket, and more
|
||||||
|
|
||||||
|
**Linked Items:** Create custom items with configurable attack speed, scripted behavior, animated textures, and item versioning
|
||||||
|
|
||||||
|
**Blocks:** Banners, barrels, beams, signs, campfires, candles, chairs, couches, crates, crystals, lanterns, mailboxes, pedestals, redstone blocks, and scripted blocks
|
||||||
|
|
||||||
|
**Crafting:** Carpentry Bench and Anvil with custom recipe support
|
||||||
|
|
||||||
|
<img src="images/VariousWeapons.png" width="474" height="260"/>
|
||||||
|
<img src="images/JappaTextures.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Custom Models
|
||||||
|
|
||||||
|
Support for custom NPC models beyond the default humanoid. Import Blockbench models using the **Gecko Addon** (GeckoLib integration) or use **Armorer's Workshop** skins with the AW Addon.
|
||||||
|
|
||||||
|
<img src="images/GeckoAddon1.png" width="474" height="260"/>
|
||||||
|
<img src="images/GeckoAddon2.png" width="474" height="260"/>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Addon Compatibility
|
||||||
|
|
||||||
|
CustomNPC+ has official addons that extend its functionality with other mods. Vault and Pixelmon are also supported natively for economy and scripting integration.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Official CNPC+ Addons
|
||||||
|
|
||||||
|
### DBC Addon
|
||||||
|
|
||||||
|
Adds full compatibility between [Dragon Block C](https://www.curseforge.com/minecraft/mc-mods/dragon-block-c) and CustomNPC+. Extends abilities with ki-based attacks, adds DBC stat integration to conditions, and enables DBC model/animation support on NPCs.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/cnpc-dbc-addon)
|
||||||
|
[](https://modrinth.com/mod/customnpc-plus-dbc-addon)
|
||||||
|
[](https://github.com/KAMKEEL/CustomNPC-DBC-Addon)
|
||||||
|
|
||||||
|
### Gecko Addon
|
||||||
|
|
||||||
|
Adds [GeckoLib](https://www.curseforge.com/minecraft/mc-mods/geckolib) support to CustomNPC+. Import Blockbench models directly into the mod and use them as custom NPC models with full animation support.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/cnpc-custom-model-addon)
|
||||||
|
[](https://modrinth.com/mod/customnpc-plus-gecko-addon)
|
||||||
|
[](https://github.com/KAMKEEL/CustomNPC-Gecko-Addon)
|
||||||
|
|
||||||
|
### Armorer's Workshop Addon
|
||||||
|
|
||||||
|
Adds compatibility between [Armorer's Workshop](https://www.curseforge.com/minecraft/mc-mods/armorers-workshop) and CustomNPC+. Use Armorer's Workshop skins and equipment on NPCs with custom rotation, scaling, and animation support. Requires UniMixins.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/cnpc-armorers-workshop-addon)
|
||||||
|
[](https://modrinth.com/mod/customnpc-plus-aw-addon)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Other Projects
|
||||||
|
|
||||||
|
### MorePlayerModels+
|
||||||
|
|
||||||
|
An updated continuation of MorePlayerModels for 1.7.10 with backported GUIs, original parts and customizations, and permission support. Works alongside CustomNPC+. This is a replacement — do not install alongside the original MorePlayerModels.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/moreplayermodels-plus)
|
||||||
|
[](https://modrinth.com/mod/moreplayermodels+)
|
||||||
|
[](https://github.com/KAMKEEL/MorePlayerModels-Plus)
|
||||||
|
|
||||||
|
### The Plugin Mod
|
||||||
|
|
||||||
|
Adds aesthetic weapons, artifacts, blocks, and apples for RPG and storytelling servers. Designed to pair with CustomNPC+ — use the included swords, spears, axes, medpacks, and decorative blocks to make your NPCs and worlds more diverse.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/the-plugin-mod)
|
||||||
|
[](https://modrinth.com/mod/the-plugin-mod)
|
||||||
|
[](https://github.com/KAMKEEL/Plugin-Mod)
|
||||||
|
|
||||||
|
### HexText
|
||||||
|
|
||||||
|
Upgrades Minecraft's font renderer with full RGB hex color support, nested color spans, and animated text effects (glow, shake, wave). Works in signs, anvils, and chat. Requires UniMixins.
|
||||||
|
|
||||||
|
[](https://www.curseforge.com/minecraft/mc-mods/hex-text)
|
||||||
|
[](https://modrinth.com/mod/hex-text)
|
||||||
|
[](https://github.com/KAMKEEL/HexText)
|
||||||
|
|
||||||
|
### RPG Messenger
|
||||||
|
|
||||||
|
A Bukkit plugin for messageable NPCs, group chats, and RPG controller tools. Allows operators to create NPCs that players can message, and lets RPG controllers reply as NPCs in real-time.
|
||||||
|
|
||||||
|
[](https://github.com/KAMKEEL/RPGMessenger)
|
||||||
|
|
||||||
|
### CustomNPC+ Dark Mode
|
||||||
|
|
||||||
|
A resource pack that applies a clean dark theme to all CustomNPC+ GUIs.
|
||||||
|
|
||||||
|
[](https://github.com/KAMKEEL/CustomNPC-Plus-Dark-Mode)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
CustomNPC+ has a modular configuration system:
|
||||||
|
|
||||||
|
| Config | Purpose |
|
||||||
|
|--------|---------|
|
||||||
|
| **Main** | Core mod settings |
|
||||||
|
| **Client** | Client-side display and UI preferences |
|
||||||
|
| **Script** | Scripting engine settings and client script toggle |
|
||||||
|
| **Market** | Currency, auction house, trader, and economy settings |
|
||||||
|
| **Energy** | Energy projectile settings (explosion block damage, dome item blacklist) |
|
||||||
|
| **Item** | Item and gun configuration |
|
||||||
|
| **Debug** | Debug logging and diagnostics |
|
||||||
|
| **Experimental** | Experimental features toggle |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Building from Source
|
||||||
|
|
||||||
|
This project uses the [GTNH Gradle Convention](https://github.com/GTNewHorizons/ExampleMod1.7.10) build system with [RetroFuturaGradle](https://github.com/GTNewHorizons/RetroFuturaGradle).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone <repo-url>
|
||||||
|
git submodule update --init --recursive
|
||||||
|
./gradlew build
|
||||||
|
```
|
||||||
|
|
||||||
|
That's it. Submodules pull in the API sources, and `build` handles decompilation, compilation, and mixin embedding automatically.
|
||||||
|
|
||||||
|
**Run the game:**
|
||||||
|
```bash
|
||||||
|
./gradlew runClient # Launch client
|
||||||
|
./gradlew runServer # Launch server
|
||||||
|
```
|
||||||
|
|
||||||
|
**IDE Setup (IntelliJ):**
|
||||||
|
1. Import the project as a Gradle project
|
||||||
|
2. Run `./gradlew genIntellijRuns`
|
||||||
|
3. Add program arguments: `--tweakClass org.spongepowered.asm.launch.MixinTweaker --mixin customnpcs.mixins.json`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Notice
|
||||||
|
|
||||||
|
I am not the original creator of CustomNPC. The original creator is [Noppes](https://github.com/Noppes). I have been permitted to update and develop my own branch version for 1.7.10. The original mod updated to the latest Minecraft versions can be found on [CurseForge](https://www.curseforge.com/minecraft/mc-mods/custom-npcs) and [kodevelopment](http://www.kodevelopment.nl/minecraft/customnpcs).
|
||||||
@@ -6,7 +6,7 @@ plugins {
|
|||||||
id "dts.typescript-generator"
|
id "dts.typescript-generator"
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "1.11-beta1"
|
version = "1.11"
|
||||||
group= "kamkeel.customnpc-plus"
|
group= "kamkeel.customnpc-plus"
|
||||||
archivesBaseName = "CustomNPC-Plus"
|
archivesBaseName = "CustomNPC-Plus"
|
||||||
|
|
||||||
@@ -64,11 +64,50 @@ sourceSets.main.java {
|
|||||||
// TypeScript plugin is applied above in the main plugins block
|
// TypeScript plugin is applied above in the main plugins block
|
||||||
|
|
||||||
tasks.named("generateTypeScriptDefinitions").configure {
|
tasks.named("generateTypeScriptDefinitions").configure {
|
||||||
sourceDirectories = ['src/api/java']
|
sourceDirectories = ['src/api/java', 'src/main/java']
|
||||||
outputDirectory = "src/main/resources/assets/${project.property("modId")}/api"
|
outputDirectory = "src/main/resources/assets/${project.property("modId")}/api"
|
||||||
apiPackages = ['noppes.npcs.api', 'net.minecraft'] as Set
|
apiPackages = ['noppes.npcs.api', 'net.minecraft'] as Set
|
||||||
cleanOutputFirst = true // Clean old generated files before regenerating
|
cleanOutputFirst = true // Clean old generated files before regenerating
|
||||||
|
patchesDirectory = "dts-patches"
|
||||||
|
implementationPackages = [
|
||||||
|
'noppes.npcs.scripted',
|
||||||
|
'noppes.npcs.controllers.data',
|
||||||
|
'noppes.npcs.entity.data',
|
||||||
|
'noppes.npcs.quests',
|
||||||
|
'kamkeel.npcs.controllers.data'
|
||||||
|
] as Set
|
||||||
}
|
}
|
||||||
processResources.dependsOn generateTypeScriptDefinitions
|
processResources.dependsOn generateTypeScriptDefinitions
|
||||||
sourcesJar.dependsOn generateTypeScriptDefinitions
|
sourcesJar.dependsOn generateTypeScriptDefinitions
|
||||||
|
|
||||||
|
|
||||||
|
// Javadoc configuration
|
||||||
|
javadoc {
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
options.charSet = 'UTF-8'
|
||||||
|
options.docEncoding = 'UTF-8'
|
||||||
|
|
||||||
|
options.tags = [
|
||||||
|
'hookName:a:Hook Name:'
|
||||||
|
]
|
||||||
|
|
||||||
|
options.stylesheetFile = file('.github/javadoc/javadoc-theme.css')
|
||||||
|
options.header = file('.github/javadoc/javadoc-header.html').text.replaceAll('\\s+', ' ').trim()
|
||||||
|
|
||||||
|
options.addBooleanOption('-allow-script-in-comments', true)
|
||||||
|
options.footer = file('.github/javadoc/javadoc-footer.html').text.replaceAll('\\s+', ' ').trim()
|
||||||
|
|
||||||
|
// Only document the public API, not net.minecraft stubs
|
||||||
|
include 'noppes/npcs/api/**'
|
||||||
|
|
||||||
|
options.links(
|
||||||
|
'https://docs.oracle.com/en/java/javase/11/docs/api/'
|
||||||
|
)
|
||||||
|
|
||||||
|
javadocTool = javaToolchains.javadocToolFor {
|
||||||
|
languageVersion = JavaLanguageVersion.of(11)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modify the existing 'build' task to depend on 'updateAPI'
|
||||||
|
//tasks.apiClasses.dependsOn 'updateAPI'
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
*/
|
*/
|
||||||
def embedMixin = !project.hasProperty("nomixin");
|
def embedMixin = !project.hasProperty("nomixin");
|
||||||
dependencies {
|
dependencies {
|
||||||
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
|
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.8.44-GTNH:dev")
|
||||||
if (!project.hasProperty("noNashorn")) {
|
if (!project.hasProperty("noNashorn")) {
|
||||||
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
||||||
}
|
}
|
||||||
@@ -43,8 +43,10 @@ dependencies {
|
|||||||
// compileOnly(files("./tools/bukkit-api/spigot-api-ONLY.jar"))
|
// compileOnly(files("./tools/bukkit-api/spigot-api-ONLY.jar"))
|
||||||
// compileOnly(files("./tools/bukkit-api/Vault-1.4.1.jar"))
|
// compileOnly(files("./tools/bukkit-api/Vault-1.4.1.jar"))
|
||||||
|
|
||||||
shadowImplementation(project.files("tools/standalone-JaninoLoader-1.0.1-ALPHA.jar"))
|
shadowImplementation(project.files("tools/standalone-JaninoLoader-1.0.2.jar"))
|
||||||
annotationProcessor(project.files("tools/standalone-JaninoLoader-1.0.1-ALPHA.jar"))
|
annotationProcessor(project.files("tools/standalone-JaninoLoader-1.0.2.jar"))
|
||||||
|
|
||||||
|
shadowImplementation(project.files("tools/tree-sitter-0.26.6-java-js.jar"))
|
||||||
|
|
||||||
testImplementation("junit:junit:4.13.2")
|
testImplementation("junit:junit:4.13.2")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Array type for working with ordered collections of elements.
|
||||||
|
* Supports static methods like Array.isArray() and instance methods like push(), map(), filter().
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Arrays
|
||||||
|
* ```js
|
||||||
|
* var empty = []; // Empty array
|
||||||
|
* var nums = [1, 2, 3]; // Array with values
|
||||||
|
* var mixed = ["hello", 42, true]; // Mixed types
|
||||||
|
* var nested = [[1, 2], [3, 4]]; // Nested arrays
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Static Methods
|
||||||
|
* ```js
|
||||||
|
* Array.isArray([1, 2, 3]); // true
|
||||||
|
* Array.isArray("hello"); // false
|
||||||
|
* Array.isArray({length: 3}); // false
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Adding & Removing Elements
|
||||||
|
* ```js
|
||||||
|
* var arr = [1, 2, 3];
|
||||||
|
* arr.push(4); // [1, 2, 3, 4] — add to end
|
||||||
|
* arr.pop(); // [1, 2, 3] — remove from end
|
||||||
|
* arr.unshift(0); // [0, 1, 2, 3] — add to start
|
||||||
|
* arr.shift(); // [1, 2, 3] — remove from start
|
||||||
|
* arr.splice(1, 1, 99); // [1, 99, 3] — replace at index 1
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Searching & Iterating
|
||||||
|
* ```js
|
||||||
|
* var arr = [10, 20, 30, 20];
|
||||||
|
* arr.indexOf(20); // 1 (first match)
|
||||||
|
* arr.lastIndexOf(20); // 3 (last match)
|
||||||
|
* arr.forEach(function(val) { log(val); });
|
||||||
|
* var doubled = arr.map(function(v) { return v * 2; }); // [20, 40, 60, 40]
|
||||||
|
* var big = arr.filter(function(v) { return v > 15; }); // [20, 30, 20]
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Reducing & Testing
|
||||||
|
* ```js
|
||||||
|
* var sum = [1, 2, 3].reduce(function(acc, v) { return acc + v; }, 0); // 6
|
||||||
|
* var allPositive = [1, 2, 3].every(function(v) { return v > 0; }); // true
|
||||||
|
* var hasNeg = [1, -2, 3].some(function(v) { return v < 0; }); // true
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* Array.push(1); // TypeError — push is an instance method
|
||||||
|
* var a = [3,1,2]; a.sort(); // Sorts as strings! Use compareFn for numbers
|
||||||
|
* a.sort(function(a, b) { return a - b; }); // Correct numeric sort: [1, 2, 3]
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Array<T> {
|
||||||
|
/** Returns true if the given object is an array, false otherwise */
|
||||||
|
static isArray(arg: any): boolean;
|
||||||
|
|
||||||
|
/** The number of elements in the array */
|
||||||
|
length: number;
|
||||||
|
|
||||||
|
/** Combines two or more arrays and returns a new array without modifying the original */
|
||||||
|
concat(...items: T[]): T[];
|
||||||
|
|
||||||
|
/** Tests whether all elements in the array pass the provided test function */
|
||||||
|
every(callback: Java.java.util.function.Function<T, boolean>): boolean;
|
||||||
|
|
||||||
|
/** Creates a new array with all elements that pass the test implemented by the provided function */
|
||||||
|
filter(callback: Java.java.util.function.Function<T, boolean>): T[];
|
||||||
|
|
||||||
|
/** Executes a provided function once for each array element. Returns undefined */
|
||||||
|
forEach(callback: Java.java.util.function.Consumer<T>): void;
|
||||||
|
|
||||||
|
/** Returns the first index at which an element is found, or -1 if not present */
|
||||||
|
indexOf(searchElement: T): number;
|
||||||
|
indexOf(searchElement: T, fromIndex: number): number;
|
||||||
|
|
||||||
|
/** Joins all elements of an array into a string separated by the given separator */
|
||||||
|
join(separator: string): string;
|
||||||
|
|
||||||
|
/** Returns the last index at which an element is found, or -1 if not present */
|
||||||
|
lastIndexOf(searchElement: T): number;
|
||||||
|
lastIndexOf(searchElement: T, fromIndex: number): number;
|
||||||
|
|
||||||
|
/** Creates a new array with the results of calling a function on every element */
|
||||||
|
map(callback: Java.java.util.function.Function<T, any>): any[];
|
||||||
|
|
||||||
|
/** Removes and returns the last element from the array, modifying the original array */
|
||||||
|
pop(): T;
|
||||||
|
|
||||||
|
/** Adds one or more elements to the end of an array and returns the new length */
|
||||||
|
push(...items: T[]): number;
|
||||||
|
|
||||||
|
/** Applies a function against an accumulator and each element to reduce the array to a single value */
|
||||||
|
reduce(callback: Java.java.util.function.BiFunction<any, T, any>): any;
|
||||||
|
reduce(callback: Java.java.util.function.BiFunction<any, T, any>, initialValue: any): any;
|
||||||
|
|
||||||
|
/** Same as reduce() but processes the array from right to left */
|
||||||
|
reduceRight(callback: Java.java.util.function.BiFunction<any, T, any>): any;
|
||||||
|
reduceRight(callback: Java.java.util.function.BiFunction<any, T, any>, initialValue: any): any;
|
||||||
|
|
||||||
|
/** Reverses an array in place. The first element becomes the last, and vice versa */
|
||||||
|
reverse(): T[];
|
||||||
|
|
||||||
|
/** Removes and returns the first element from the array, modifying the original array */
|
||||||
|
shift(): T;
|
||||||
|
|
||||||
|
/** Returns a shallow copy of a portion of an array as a new array object */
|
||||||
|
slice(start: number, end: number): T[];
|
||||||
|
|
||||||
|
/** Tests whether at least one element in the array passes the test implemented by the provided function */
|
||||||
|
some(callback: Java.java.util.function.Function<T, boolean>): boolean;
|
||||||
|
|
||||||
|
/** Sorts the elements of an array in place and returns the sorted array */
|
||||||
|
sort(compareFn: Java.java.util.function.BiFunction<T, T, number>): T[];
|
||||||
|
|
||||||
|
/** Changes the contents of an array by removing or replacing existing elements and/or adding new ones */
|
||||||
|
splice(start: number, deleteCount: number, ...items: T[]): T[];
|
||||||
|
|
||||||
|
/** Returns a string representation of the array */
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
|
/** Adds one or more elements to the beginning of an array and returns the new length */
|
||||||
|
unshift(...items: T[]): number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Boolean type for true/false values.
|
||||||
|
* Booleans are the result of comparison and logical operations.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Booleans
|
||||||
|
* ```js
|
||||||
|
* var yes = true; // Boolean literal
|
||||||
|
* var no = false; // Boolean literal
|
||||||
|
* var fromExpr = (5 > 3); // true (comparison result)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Boolean Methods
|
||||||
|
* ```js
|
||||||
|
* var b = true;
|
||||||
|
* b.toString(); // "true"
|
||||||
|
* b.valueOf(); // true (primitive value)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Truthy & Falsy Values
|
||||||
|
* ```js
|
||||||
|
* // These are FALSY (evaluate to false):
|
||||||
|
* // false, 0, "", null, undefined, NaN
|
||||||
|
*
|
||||||
|
* // These are TRUTHY (evaluate to true):
|
||||||
|
* // true, any non-zero number, any non-empty string, objects, arrays
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export interface Boolean {
|
||||||
|
/** Returns the string "true" or "false" */
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
|
/** Returns the primitive boolean value */
|
||||||
|
valueOf(): boolean;
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Date type for working with dates and times.
|
||||||
|
* Create with `new Date()` or use static methods like Date.now() to get current timestamp.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Dates
|
||||||
|
* ```js
|
||||||
|
* var now = new Date(); // Current date & time
|
||||||
|
* var epoch = new Date(0); // Jan 1, 1970
|
||||||
|
* var specific = new Date(2024, 0, 15); // Jan 15, 2024 (months are 0-based!)
|
||||||
|
* var full = new Date(2024, 5, 15, 10, 30, 0); // Jun 15, 2024 10:30:00
|
||||||
|
* var fromStr = new Date("2024-01-15"); // Parse from ISO string
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Static Methods (no `new` needed)
|
||||||
|
* ```js
|
||||||
|
* var timestamp = Date.now(); // Current time in milliseconds
|
||||||
|
* var parsed = Date.parse("2024-01-15"); // Parse string to timestamp
|
||||||
|
* var utc = Date.UTC(2024, 0, 15); // UTC timestamp for Jan 15, 2024
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* Date.now; // Returns the function, not the timestamp!
|
||||||
|
* Date.getMinutes(); // TypeError — instance method, not static
|
||||||
|
* new Date(2024, 1, 1); // Feb 1, not Jan 1 — months are 0-based!
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Date {
|
||||||
|
/** Returns the current time as the number of milliseconds since 1970-01-01 00:00:00 UTC */
|
||||||
|
static now(): number;
|
||||||
|
|
||||||
|
/** Parses a date string and returns the number of milliseconds since 1970-01-01 00:00:00 UTC */
|
||||||
|
static parse(s: string): number;
|
||||||
|
|
||||||
|
/** Returns the number of milliseconds since 1970-01-01 00:00:00 UTC for the given UTC date/time components */
|
||||||
|
static UTC(year: number, month: number, date: number, hours: number, minutes: number, seconds: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Returns the day of the month (1-31) in local time */
|
||||||
|
getDate(): number;
|
||||||
|
|
||||||
|
/** Returns the day of the week (0=Sunday, 6=Saturday) in local time */
|
||||||
|
getDay(): number;
|
||||||
|
|
||||||
|
/** Returns the year in local time */
|
||||||
|
getFullYear(): number;
|
||||||
|
|
||||||
|
/** Returns the hour (0-23) in local time */
|
||||||
|
getHours(): number;
|
||||||
|
|
||||||
|
/** Returns the milliseconds (0-999) in local time */
|
||||||
|
getMilliseconds(): number;
|
||||||
|
|
||||||
|
/** Returns the minutes (0-59) in local time */
|
||||||
|
getMinutes(): number;
|
||||||
|
|
||||||
|
/** Returns the month (0=January, 11=December) in local time */
|
||||||
|
getMonth(): number;
|
||||||
|
|
||||||
|
/** Returns the seconds (0-59) in local time */
|
||||||
|
getSeconds(): number;
|
||||||
|
|
||||||
|
/** Returns the number of milliseconds since 1970-01-01 00:00:00 UTC */
|
||||||
|
getTime(): number;
|
||||||
|
|
||||||
|
/** Returns the time zone offset in minutes between local time and UTC */
|
||||||
|
getTimezoneOffset(): number;
|
||||||
|
|
||||||
|
/** Returns the day of the month (1-31) in UTC */
|
||||||
|
getUTCDate(): number;
|
||||||
|
|
||||||
|
/** Returns the day of the week (0=Sunday, 6=Saturday) in UTC */
|
||||||
|
getUTCDay(): number;
|
||||||
|
|
||||||
|
/** Returns the year in UTC */
|
||||||
|
getUTCFullYear(): number;
|
||||||
|
|
||||||
|
/** Returns the hour (0-23) in UTC */
|
||||||
|
getUTCHours(): number;
|
||||||
|
|
||||||
|
/** Returns the milliseconds (0-999) in UTC */
|
||||||
|
getUTCMilliseconds(): number;
|
||||||
|
|
||||||
|
/** Returns the minutes (0-59) in UTC */
|
||||||
|
getUTCMinutes(): number;
|
||||||
|
|
||||||
|
/** Returns the month (0=January, 11=December) in UTC */
|
||||||
|
getUTCMonth(): number;
|
||||||
|
|
||||||
|
/** Returns the seconds (0-59) in UTC */
|
||||||
|
getUTCSeconds(): number;
|
||||||
|
|
||||||
|
/** Sets the day of the month and returns the new timestamp */
|
||||||
|
setDate(date: number): number;
|
||||||
|
|
||||||
|
/** Sets the year, and optionally month and date, then returns the new timestamp */
|
||||||
|
setFullYear(year: number, month: number, date: number): number;
|
||||||
|
|
||||||
|
/** Sets the hour, minutes, seconds, and milliseconds, then returns the new timestamp */
|
||||||
|
setHours(hour: number, min: number, sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the milliseconds and returns the new timestamp */
|
||||||
|
setMilliseconds(ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the minutes, seconds, and milliseconds, then returns the new timestamp */
|
||||||
|
setMinutes(min: number, sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the month, and optionally date, then returns the new timestamp */
|
||||||
|
setMonth(month: number, date: number): number;
|
||||||
|
|
||||||
|
/** Sets the seconds and milliseconds, then returns the new timestamp */
|
||||||
|
setSeconds(sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the timestamp (milliseconds since epoch) and returns it */
|
||||||
|
setTime(time: number): number;
|
||||||
|
|
||||||
|
/** Sets the day of the month (UTC) and returns the new timestamp */
|
||||||
|
setUTCDate(date: number): number;
|
||||||
|
|
||||||
|
/** Sets the year, month, and date (UTC), then returns the new timestamp */
|
||||||
|
setUTCFullYear(year: number, month: number, date: number): number;
|
||||||
|
|
||||||
|
/** Sets the hour, minutes, seconds, and milliseconds (UTC), then returns the new timestamp */
|
||||||
|
setUTCHours(hour: number, min: number, sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the milliseconds (UTC) and returns the new timestamp */
|
||||||
|
setUTCMilliseconds(ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the minutes, seconds, and milliseconds (UTC), then returns the new timestamp */
|
||||||
|
setUTCMinutes(min: number, sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Sets the month and date (UTC), then returns the new timestamp */
|
||||||
|
setUTCMonth(month: number, date: number): number;
|
||||||
|
|
||||||
|
/** Sets the seconds and milliseconds (UTC), then returns the new timestamp */
|
||||||
|
setUTCSeconds(sec: number, ms: number): number;
|
||||||
|
|
||||||
|
/** Returns a string representation of the date portion in local time (e.g., "Mon Jan 01 2024") */
|
||||||
|
toDateString(): string;
|
||||||
|
|
||||||
|
/** Returns the date as an ISO 8601 string (e.g., "2024-01-01T00:00:00.000Z") */
|
||||||
|
toISOString(): string;
|
||||||
|
|
||||||
|
/** Returns a JSON representation of the date (typically an ISO 8601 string) */
|
||||||
|
toJSON(key: any): string;
|
||||||
|
|
||||||
|
/** Returns a localized string for the date portion (format depends on locale) */
|
||||||
|
toLocaleDateString(): string;
|
||||||
|
|
||||||
|
/** Returns a localized string for the entire date and time (format depends on locale) */
|
||||||
|
toLocaleString(): string;
|
||||||
|
|
||||||
|
/** Returns a localized string for the time portion (format depends on locale) */
|
||||||
|
toLocaleTimeString(): string;
|
||||||
|
|
||||||
|
/** Returns a string representation of the date and time in local time */
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
|
/** Returns a string representation of the time portion in local time (e.g., "00:00:00 GMT+0000") */
|
||||||
|
toTimeString(): string;
|
||||||
|
|
||||||
|
/** Returns a string representation of the date and time in UTC (e.g., "Mon, 01 Jan 2024 00:00:00 GMT") */
|
||||||
|
toUTCString(): string;
|
||||||
|
|
||||||
|
/** Returns the primitive value of the date object (milliseconds since 1970-01-01 00:00:00 UTC) */
|
||||||
|
valueOf(): number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Error base type for runtime errors.
|
||||||
|
* Throw Error objects to indicate failure conditions in your code.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating & Throwing Errors
|
||||||
|
* ```js
|
||||||
|
* throw new Error("Something went wrong");
|
||||||
|
* throw new TypeError("Expected a string");
|
||||||
|
* throw new RangeError("Value out of range");
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Catching Errors
|
||||||
|
* ```js
|
||||||
|
* try {
|
||||||
|
* var result = riskyOperation();
|
||||||
|
* } catch (e) {
|
||||||
|
* log(e.name); // "Error", "TypeError", etc.
|
||||||
|
* log(e.message); // "Something went wrong"
|
||||||
|
* log(e.toString()); // "Error: Something went wrong"
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Custom Error Messages
|
||||||
|
* ```js
|
||||||
|
* function divide(a, b) {
|
||||||
|
* if (b === 0) {
|
||||||
|
* throw new Error("Cannot divide by zero");
|
||||||
|
* }
|
||||||
|
* return a / b;
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* throw "Something went wrong"; // Works but no .name or .message properties
|
||||||
|
* Error("oops"); // Creates error but doesn't throw it!
|
||||||
|
* throw Error("oops"); // ✅ Works (with or without `new`)
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Error {
|
||||||
|
/** The name of the error type (e.g., "Error", "TypeError", "RangeError") */
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/** A human-readable description of what went wrong */
|
||||||
|
message: string;
|
||||||
|
|
||||||
|
/** Returns a string representation of the error (typically "name: message") */
|
||||||
|
toString(): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EvalError - Thrown when eval() function is misused (rarely used in modern JavaScript)
|
||||||
|
*/
|
||||||
|
export interface EvalError extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RangeError - Thrown when a numeric value is out of the acceptable range (e.g., array length < 0)
|
||||||
|
*/
|
||||||
|
export interface RangeError extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ReferenceError - Thrown when trying to reference a variable that does not exist or is not in scope
|
||||||
|
*/
|
||||||
|
export interface ReferenceError extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SyntaxError - Thrown when parsing invalid syntax (usually caught during compile/parse, not runtime)
|
||||||
|
*/
|
||||||
|
export interface SyntaxError extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TypeError - Thrown when an operation is performed on a value of the wrong type (e.g., calling a non-function)
|
||||||
|
*/
|
||||||
|
export interface TypeError extends Error {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URIError - Thrown by URI encoding/decoding functions when given invalid characters or sequences
|
||||||
|
*/
|
||||||
|
export interface URIError extends Error {}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Global functions available in the global scope.
|
||||||
|
* These are not on any specific object - call them directly (e.g., parseInt("42")).
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Parsing Numbers
|
||||||
|
* ```js
|
||||||
|
* parseInt("42"); // 42
|
||||||
|
* parseInt("42px"); // 42 (stops at non-digit)
|
||||||
|
* parseInt("0xFF", 16); // 255 (hexadecimal)
|
||||||
|
* parseInt("111", 2); // 7 (binary)
|
||||||
|
* parseFloat("3.14"); // 3.14
|
||||||
|
* parseFloat("3.14abc"); // 3.14 (stops at invalid char)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Checking Special Values
|
||||||
|
* ```js
|
||||||
|
* isNaN(NaN); // true
|
||||||
|
* isNaN(42); // false
|
||||||
|
* isNaN("hello"); // true (cannot parse as number)
|
||||||
|
* isNaN("42"); // false (can parse as number)
|
||||||
|
* isFinite(42); // true
|
||||||
|
* isFinite(Infinity); // false
|
||||||
|
* isFinite(NaN); // false
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### URI Encoding/Decoding
|
||||||
|
* ```js
|
||||||
|
* encodeURI("hello world"); // "hello%20world"
|
||||||
|
* decodeURI("hello%20world"); // "hello world"
|
||||||
|
* encodeURIComponent("a=1&b=2"); // "a%3D1%26b%3D2" (encodes & and =)
|
||||||
|
* decodeURIComponent("a%3D1%26b%3D2"); // "a=1&b=2"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* parseInt("08"); // Some engines treat as octal! Always specify radix
|
||||||
|
* parseInt("08", 10); // 8 ✅ — explicitly base-10
|
||||||
|
* parseInt(""); // NaN — empty string returns NaN, not 0
|
||||||
|
* parseFloat(""); // NaN
|
||||||
|
* isNaN(undefined); // true — coerces to NaN first
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface GlobalFunctions {
|
||||||
|
/** Evaluates JavaScript code in a string (use with caution - slow and potential security issues) */
|
||||||
|
static eval(x: any): any;
|
||||||
|
|
||||||
|
/** Parses a string and returns an integer. Stops parsing at the first non-digit character */
|
||||||
|
static parseInt(string: string): number;
|
||||||
|
|
||||||
|
/** Parses a string and returns an integer using the specified radix (base). Stops parsing at the first non-digit character */
|
||||||
|
static parseInt(string: string, radix: number): number;
|
||||||
|
|
||||||
|
/** Parses a string and returns a floating-point number. Stops parsing at the first invalid character */
|
||||||
|
static parseFloat(string: string): number;
|
||||||
|
|
||||||
|
/** Determines whether a value is NaN (not-a-number). The value is first coerced to a number before testing */
|
||||||
|
static isNaN(value: any): boolean;
|
||||||
|
|
||||||
|
/** Determines whether a value is a finite number. The value is first coerced to a number. Returns false for Infinity, -Infinity, and NaN */
|
||||||
|
static isFinite(value: any): boolean;
|
||||||
|
|
||||||
|
/** Decodes a URI by replacing encoded sequences like %20 with their original characters */
|
||||||
|
static decodeURI(encodedURI: string): string;
|
||||||
|
|
||||||
|
/** Decodes URI component by replacing ALL encoded sequences including those for reserved URI characters */
|
||||||
|
static decodeURIComponent(encodedURIComponent: string): string;
|
||||||
|
|
||||||
|
/** Encodes a URI by replacing special characters with %HH sequences (but preserves reserved characters like / : ?) */
|
||||||
|
static encodeURI(uri: string): string;
|
||||||
|
|
||||||
|
/** Encodes URI component by replacing ALL special characters including reserved ones with %HH sequences */
|
||||||
|
static encodeURIComponent(uriComponent: string): string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - JSON built-in object for parsing and serializing JSON data.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* JSON is a **static object** — use its methods directly, never with `new`.
|
||||||
|
*
|
||||||
|
* ### Parsing JSON Strings to Objects
|
||||||
|
* ```js
|
||||||
|
* var obj = JSON.parse('{"name": "Steve", "level": 5}');
|
||||||
|
* log(obj.name); // "Steve"
|
||||||
|
* log(obj.level); // 5
|
||||||
|
*
|
||||||
|
* var arr = JSON.parse('[1, 2, 3]');
|
||||||
|
* log(arr[0]); // 1
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Converting Objects to JSON Strings
|
||||||
|
* ```js
|
||||||
|
* var data = { name: "Steve", hp: 100 };
|
||||||
|
* var json = JSON.stringify(data); // '{"name":"Steve","hp":100}'
|
||||||
|
*
|
||||||
|
* // Pretty-printed with 2-space indent:
|
||||||
|
* var pretty = JSON.stringify(data, null, 2);
|
||||||
|
* // '{
|
||||||
|
* // "name": "Steve",
|
||||||
|
* // "hp": 100
|
||||||
|
* // }'
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Storing & Loading Data
|
||||||
|
* ```js
|
||||||
|
* // Save to NPC stored data:
|
||||||
|
* var inventory = { sword: 1, potion: 5 };
|
||||||
|
* npc.getStoredData().put("inv", JSON.stringify(inventory));
|
||||||
|
*
|
||||||
|
* // Load from NPC stored data:
|
||||||
|
* var raw = npc.getStoredData().get("inv");
|
||||||
|
* var loaded = JSON.parse(raw);
|
||||||
|
* log(loaded.potion); // 5
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* new JSON(); // TypeError — JSON is not a constructor
|
||||||
|
* JSON.parse('{name: "Steve"}'); // SyntaxError — keys must be quoted
|
||||||
|
* JSON.parse("{'name': 'Steve'}"); // SyntaxError — must use double quotes
|
||||||
|
* JSON.parse('{"name": "Steve"}'); // ✅ Correct — double-quoted keys & values
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface JSON {
|
||||||
|
/**
|
||||||
|
* Parses a JSON string and returns the parsed value (object, array, string, number, boolean, or null).
|
||||||
|
* @param text - A valid JSON string to parse
|
||||||
|
* @returns The parsed JavaScript value
|
||||||
|
*/
|
||||||
|
static parse(text: string): any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a JSON string with a reviver function that transforms each parsed key-value pair.
|
||||||
|
* @param text - A valid JSON string to parse
|
||||||
|
* @param reviver - Function called for each key-value pair; receives the key and parsed value, returns the transformed value
|
||||||
|
* @returns The parsed JavaScript value after applying the reviver
|
||||||
|
*/
|
||||||
|
static parse(text: string, reviver: Java.java.util.function.BiFunction<string, any, any>): any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a JavaScript value to a JSON string.
|
||||||
|
* @param value - The value to serialize (object, array, string, number, boolean, or null)
|
||||||
|
* @returns A JSON-formatted string representation of the value
|
||||||
|
*/
|
||||||
|
static stringify(value: any): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a JavaScript value to a JSON string, using a replacer function to filter or transform properties.
|
||||||
|
* @param value - The value to serialize
|
||||||
|
* @param replacer - Function called for each key-value pair; receives the key and value, returns the value to include (or undefined to omit)
|
||||||
|
* @param space - Optional indentation: a number of spaces (up to 10), or a string prefix per level
|
||||||
|
* @returns A JSON-formatted string representation of the value
|
||||||
|
*/
|
||||||
|
static stringify(value: any, replacer: Java.java.util.function.BiFunction<string, any, any>, space?: any): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a JavaScript value to a JSON string, including only the specified properties.
|
||||||
|
* @param value - The value to serialize
|
||||||
|
* @param replacer - Array of property names to include in the output
|
||||||
|
* @param space - Optional indentation: a number of spaces (up to 10), or a string prefix per level
|
||||||
|
* @returns A JSON-formatted string representation of the value
|
||||||
|
*/
|
||||||
|
static stringify(value: any, replacer: string[], space?: any): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a JavaScript value to a JSON string with optional pretty-printing.
|
||||||
|
* @param value - The value to serialize
|
||||||
|
* @param replacer - Pass null to include all properties
|
||||||
|
* @param space - Indentation: a number of spaces (up to 10), or a string prefix per level
|
||||||
|
* @returns A JSON-formatted string representation of the value
|
||||||
|
*/
|
||||||
|
static stringify(value: any, replacer: null, space: any): string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Math built-in object providing mathematical constants and functions.
|
||||||
|
* All methods are static and called as Math.methodName(). No constructor.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* Math is a **static object** — use its methods directly, never with `new`.
|
||||||
|
*
|
||||||
|
* ### Basic Math Operations
|
||||||
|
* ```js
|
||||||
|
* var rounded = Math.floor(3.7); // 3
|
||||||
|
* var ceiling = Math.ceil(3.2); // 4
|
||||||
|
* var nearest = Math.round(3.5); // 4
|
||||||
|
* var absolute = Math.abs(-42); // 42
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Powers, Roots & Logarithms
|
||||||
|
* ```js
|
||||||
|
* var squared = Math.pow(2, 3); // 8
|
||||||
|
* var root = Math.sqrt(16); // 4
|
||||||
|
* var natural = Math.log(Math.E); // 1
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Random Numbers
|
||||||
|
* ```js
|
||||||
|
* var rand = Math.random(); // 0.0 to 0.999...
|
||||||
|
* // Random integer between 1 and 10:
|
||||||
|
* var dice = Math.floor(Math.random() * 10) + 1;
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Finding Min/Max
|
||||||
|
* ```js
|
||||||
|
* var biggest = Math.max(5, 10, 3); // 10
|
||||||
|
* var smallest = Math.min(5, 10, 3); // 3
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Trigonometry
|
||||||
|
* ```js
|
||||||
|
* var sine = Math.sin(Math.PI / 2); // 1
|
||||||
|
* var cosine = Math.cos(0); // 1
|
||||||
|
* var angle = Math.atan2(1, 1); // 0.785... (PI/4)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* new Math() // TypeError — Math is not a constructor
|
||||||
|
* Math() // TypeError — Math is not a function
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Math {
|
||||||
|
/** Euler's number (~2.718), the base of natural logarithms */
|
||||||
|
static readonly E: number;
|
||||||
|
|
||||||
|
/** Natural logarithm of 2 (~0.693) */
|
||||||
|
static readonly LN2: number;
|
||||||
|
|
||||||
|
/** Natural logarithm of 10 (~2.303) */
|
||||||
|
static readonly LN10: number;
|
||||||
|
|
||||||
|
/** Base-2 logarithm of e (~1.443) */
|
||||||
|
static readonly LOG2E: number;
|
||||||
|
|
||||||
|
/** Base-10 logarithm of e (~0.434) */
|
||||||
|
static readonly LOG10E: number;
|
||||||
|
|
||||||
|
/** Ratio of a circle's circumference to its diameter (~3.14159) */
|
||||||
|
static readonly PI: number;
|
||||||
|
|
||||||
|
/** Square root of 0.5 (~0.707) */
|
||||||
|
static readonly SQRT1_2: number;
|
||||||
|
|
||||||
|
/** Square root of 2 (~1.414) */
|
||||||
|
static readonly SQRT2: number;
|
||||||
|
|
||||||
|
/** Returns the absolute value of a number */
|
||||||
|
static abs(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the arccosine (in radians) of a number */
|
||||||
|
static acos(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the arcsine (in radians) of a number */
|
||||||
|
static asin(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the arctangent (in radians) of a number */
|
||||||
|
static atan(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the arctangent of two numbers (y/x), with proper quadrant handling */
|
||||||
|
static atan2(y: number, x: number): number;
|
||||||
|
|
||||||
|
/** Returns the smallest integer greater than or equal to a number */
|
||||||
|
static ceil(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the cosine (in radians) of a number */
|
||||||
|
static cos(x: number): number;
|
||||||
|
|
||||||
|
/** Returns e raised to the power of a number */
|
||||||
|
static exp(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the largest integer less than or equal to a number */
|
||||||
|
static floor(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the natural logarithm (base e) of a number */
|
||||||
|
static log(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the largest of zero or more numbers */
|
||||||
|
static max(...values: number[]): number;
|
||||||
|
|
||||||
|
/** Returns the smallest of zero or more numbers */
|
||||||
|
static min(...values: number[]): number;
|
||||||
|
|
||||||
|
/** Returns base raised to the power of exponent */
|
||||||
|
static pow(x: number, y: number): number;
|
||||||
|
|
||||||
|
/** Returns a random number between 0 (inclusive) and 1 (exclusive) */
|
||||||
|
static random(): number;
|
||||||
|
|
||||||
|
/** Returns the value of a number rounded to the nearest integer */
|
||||||
|
static round(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the sine (in radians) of a number */
|
||||||
|
static sin(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the square root of a number */
|
||||||
|
static sqrt(x: number): number;
|
||||||
|
|
||||||
|
/** Returns the tangent (in radians) of a number */
|
||||||
|
static tan(x: number): number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Number type for working with numeric values and constants.
|
||||||
|
* Access static constants like Number.MAX_VALUE or format numbers with instance methods.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Number Constants
|
||||||
|
* ```js
|
||||||
|
* Number.MAX_VALUE; // ~1.79e+308 (largest representable number)
|
||||||
|
* Number.MIN_VALUE; // ~5e-324 (smallest positive number)
|
||||||
|
* Number.NaN; // NaN
|
||||||
|
* Number.POSITIVE_INFINITY; // Infinity
|
||||||
|
* Number.NEGATIVE_INFINITY; // -Infinity
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Formatting Numbers
|
||||||
|
* ```js
|
||||||
|
* var n = 3.14159;
|
||||||
|
* n.toFixed(2); // "3.14" (fixed decimal places)
|
||||||
|
* n.toFixed(0); // "3"
|
||||||
|
* n.toPrecision(4); // "3.142" (significant digits)
|
||||||
|
* n.toExponential(2); // "3.14e+0" (scientific notation)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Converting to String
|
||||||
|
* ```js
|
||||||
|
* var n = 255;
|
||||||
|
* n.toString(); // "255" (base 10, default)
|
||||||
|
* n.toString(16); // "ff" (hexadecimal)
|
||||||
|
* n.toString(2); // "11111111" (binary)
|
||||||
|
* n.toString(8); // "377" (octal)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* Number.toFixed(2); // TypeError — instance method, not static
|
||||||
|
* (3).toFixed(2); // "3.00" ✅ — wrap literal in parentheses
|
||||||
|
* 3.toFixed(2); // SyntaxError — parser reads 3. as float
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Number {
|
||||||
|
/** The largest representable number (~1.79e+308) */
|
||||||
|
static readonly MAX_VALUE: number;
|
||||||
|
|
||||||
|
/** The smallest representable positive number (~5e-324) */
|
||||||
|
static readonly MIN_VALUE: number;
|
||||||
|
|
||||||
|
/** Represents "Not a Number" (NaN) - the result of undefined or invalid arithmetic operations */
|
||||||
|
static readonly NaN: number;
|
||||||
|
|
||||||
|
/** Represents negative infinity, the result of overflow or division by zero */
|
||||||
|
static readonly NEGATIVE_INFINITY: number;
|
||||||
|
|
||||||
|
/** Represents positive infinity, the result of overflow or division by zero */
|
||||||
|
static readonly POSITIVE_INFINITY: number;
|
||||||
|
|
||||||
|
/** Formats the number using exponential notation with optional fractional digits */
|
||||||
|
toExponential(fractionDigits: number): string;
|
||||||
|
|
||||||
|
/** Formats the number as a fixed-point string with the specified number of fractional digits (0-20) */
|
||||||
|
toFixed(fractionDigits: number): string;
|
||||||
|
|
||||||
|
/** Returns a localized string representation of the number (format depends on locale) */
|
||||||
|
toLocaleString(): string;
|
||||||
|
|
||||||
|
/** Formats the number as a string with the specified number of significant digits (1-21) */
|
||||||
|
toPrecision(precision: number): string;
|
||||||
|
|
||||||
|
/** Converts the number to a string in the specified radix (base 2-36, default 10) */
|
||||||
|
toString(radix: number): string;
|
||||||
|
|
||||||
|
/** Returns the primitive numeric value of this Number object */
|
||||||
|
valueOf(): number;
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - Object type, the base type for all JavaScript objects.
|
||||||
|
* Use static methods like Object.keys() and Object.create() to manipulate object structure.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Objects
|
||||||
|
* ```js
|
||||||
|
* var obj = {}; // Empty object literal
|
||||||
|
* var person = { name: "Steve", age: 20 }; // Object with properties
|
||||||
|
* var child = Object.create(person); // Create with prototype
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Inspecting Objects
|
||||||
|
* ```js
|
||||||
|
* var obj = { a: 1, b: 2, c: 3 };
|
||||||
|
* Object.keys(obj); // ["a", "b", "c"]
|
||||||
|
* Object.getOwnPropertyNames(obj); // ["a", "b", "c"] (includes non-enumerable)
|
||||||
|
* obj.hasOwnProperty("a"); // true
|
||||||
|
* obj.hasOwnProperty("toString"); // false (inherited, not own)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Freezing & Sealing
|
||||||
|
* ```js
|
||||||
|
* var config = { debug: false };
|
||||||
|
* Object.freeze(config); // Cannot modify, add, or delete properties
|
||||||
|
* config.debug = true; // Silently fails (or throws in strict mode)
|
||||||
|
* Object.isFrozen(config); // true
|
||||||
|
*
|
||||||
|
* var settings = { volume: 50 };
|
||||||
|
* Object.seal(settings); // Can modify values, but cannot add/delete
|
||||||
|
* settings.volume = 75; // ✅ Works
|
||||||
|
* settings.newProp = true; // Silently fails
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Property Descriptors
|
||||||
|
* ```js
|
||||||
|
* var obj = {};
|
||||||
|
* Object.defineProperty(obj, "id", {
|
||||||
|
* value: 42,
|
||||||
|
* writable: false, // Cannot be changed
|
||||||
|
* enumerable: true // Shows up in for-in / Object.keys
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* Object.keys(); // TypeError — needs an argument
|
||||||
|
* obj.keys(); // TypeError — keys is a static method
|
||||||
|
* Object.hasOwnProperty("a"); // Wrong — instance method on the object
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface Object {
|
||||||
|
/** Creates a new object with the specified prototype and optional property descriptors */
|
||||||
|
static create(proto: any, propertiesObject: any): any;
|
||||||
|
|
||||||
|
/** Defines or modifies multiple properties on an object and returns the modified object */
|
||||||
|
static defineProperties(obj: any, props: any): any;
|
||||||
|
|
||||||
|
/** Defines a new property on an object or modifies an existing property and returns the object */
|
||||||
|
static defineProperty(obj: any, prop: string, descriptor: any): any;
|
||||||
|
|
||||||
|
/** Prevents all modifications to an object (cannot add, modify, or delete properties) */
|
||||||
|
static freeze(obj: any): any;
|
||||||
|
|
||||||
|
/** Returns a property descriptor for a named property on an object, or undefined if not found */
|
||||||
|
static getOwnPropertyDescriptor(obj: any, prop: string): any;
|
||||||
|
|
||||||
|
/** Returns an array of all property names (both enumerable and non-enumerable) on an object */
|
||||||
|
static getOwnPropertyNames(obj: any): string[];
|
||||||
|
|
||||||
|
/** Returns the prototype object of the specified object */
|
||||||
|
static getPrototypeOf(obj: any): any;
|
||||||
|
|
||||||
|
/** Determines whether an object is extensible (can have new properties added to it) */
|
||||||
|
static isExtensible(obj: any): boolean;
|
||||||
|
|
||||||
|
/** Determines whether an object has been frozen (is immutable) */
|
||||||
|
static isFrozen(obj: any): boolean;
|
||||||
|
|
||||||
|
/** Determines whether an object is sealed (cannot add or delete properties) */
|
||||||
|
static isSealed(obj: any): boolean;
|
||||||
|
|
||||||
|
/** Returns an array of all enumerable property names on an object */
|
||||||
|
static keys(obj: any): string[];
|
||||||
|
|
||||||
|
/** Prevents new properties from being added to an object but allows modification of existing ones */
|
||||||
|
static preventExtensions(obj: any): any;
|
||||||
|
|
||||||
|
/** Prevents all modifications to an object except for reading and writing property values */
|
||||||
|
static seal(obj: any): any;
|
||||||
|
|
||||||
|
/** Determines whether an object has a property with the specified name (direct property, not inherited) */
|
||||||
|
hasOwnProperty(prop: string): boolean;
|
||||||
|
|
||||||
|
/** Determines whether an object is in the prototype chain of another object */
|
||||||
|
isPrototypeOf(obj: any): boolean;
|
||||||
|
|
||||||
|
/** Determines whether an object property is enumerable (would be included in a for-in loop) */
|
||||||
|
propertyIsEnumerable(prop: string): boolean;
|
||||||
|
|
||||||
|
/** Returns a localized string representation of the object (format depends on locale) */
|
||||||
|
toLocaleString(): string;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - RegExp type for pattern matching and string manipulation.
|
||||||
|
* Create with the RegExp constructor or literal syntax: /pattern/flags
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Regular Expressions
|
||||||
|
* ```js
|
||||||
|
* // Method 1: Regex literal (preferred)
|
||||||
|
* var re = /hello/;
|
||||||
|
* var reFlags = /hello/gi; // g=global, i=ignore case, m=multiline
|
||||||
|
*
|
||||||
|
* // Method 2: Constructor (useful for dynamic patterns)
|
||||||
|
* var re2 = new RegExp("hello");
|
||||||
|
* var re3 = new RegExp("hello", "gi");
|
||||||
|
* var dynamic = new RegExp(playerName); // Build pattern from variable
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Testing for Matches
|
||||||
|
* ```js
|
||||||
|
* /\d+/.test("abc123"); // true — contains digits
|
||||||
|
* /^\d+$/.test("abc123"); // false — not ALL digits
|
||||||
|
* /^\d+$/.test("12345"); // true — all digits
|
||||||
|
* /hello/i.test("Hello World"); // true — case insensitive
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Extracting Matches
|
||||||
|
* ```js
|
||||||
|
* var match = /\d+/.exec("abc123def"); // ["123"]
|
||||||
|
* var noMatch = /\d+/.exec("no digits"); // null
|
||||||
|
*
|
||||||
|
* // With capturing groups
|
||||||
|
* var result = /(\w+)@(\w+)/.exec("user@domain");
|
||||||
|
* // result[0] = "user@domain" (full match)
|
||||||
|
* // result[1] = "user" (first group)
|
||||||
|
* // result[2] = "domain" (second group)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Using with String Methods
|
||||||
|
* ```js
|
||||||
|
* "abc123".match(/\d+/); // ["123"]
|
||||||
|
* "abc123".search(/\d/); // 3 (index of first digit)
|
||||||
|
* "abc123".replace(/\d+/, "NUM"); // "abcNUMdef"
|
||||||
|
* "a,b,,c".split(/,+/); // ["a", "b", "c"]
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### RegExp Properties
|
||||||
|
* ```js
|
||||||
|
* var re = /hello/gi;
|
||||||
|
* re.source; // "hello"
|
||||||
|
* re.global; // true
|
||||||
|
* re.ignoreCase; // true
|
||||||
|
* re.multiline; // false
|
||||||
|
* re.lastIndex; // 0 (changes with global exec/test)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* RegExp.test("string"); // TypeError — test is an INSTANCE method!
|
||||||
|
* new RegExp.test("string"); // TypeError — incorrect syntax
|
||||||
|
* // ✅ CORRECT:
|
||||||
|
* /pattern/.test("string"); // Use on a regex instance
|
||||||
|
* new RegExp("pattern").test("string"); // Or create instance first
|
||||||
|
*
|
||||||
|
* // Double-escape backslashes in constructor strings:
|
||||||
|
* new RegExp("\d+"); // Wrong — \d becomes just d
|
||||||
|
* new RegExp("\\d+"); // ✅ Correct — \\d becomes \d
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface RegExp {
|
||||||
|
/** The pattern string that was used to create this regular expression */
|
||||||
|
source: string;
|
||||||
|
|
||||||
|
/** True if the 'g' (global) flag is set, affecting match behavior in exec() and test() */
|
||||||
|
global: boolean;
|
||||||
|
|
||||||
|
/** True if the 'i' (ignore case) flag is set, making pattern matching case-insensitive */
|
||||||
|
ignoreCase: boolean;
|
||||||
|
|
||||||
|
/** True if the 'm' (multiline) flag is set, affecting ^ and $ anchor behavior */
|
||||||
|
multiline: boolean;
|
||||||
|
|
||||||
|
/** The index at which to start searching in the string (used with 'g' flag in exec() loops) */
|
||||||
|
lastIndex: number;
|
||||||
|
|
||||||
|
/** Searches the string for a match and returns an array of matches or null if no match found */
|
||||||
|
exec(string: string): any[];
|
||||||
|
|
||||||
|
/** Tests whether the pattern matches the string, returning true or false */
|
||||||
|
test(string: string): boolean;
|
||||||
|
|
||||||
|
/** Returns a string representation of the regular expression (e.g., "/pattern/flags") */
|
||||||
|
toString(): string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/**
|
||||||
|
* ECMAScript 5.1 - String type for working with text. Strings are immutable sequences of characters.
|
||||||
|
* Use String.fromCharCode() to create a string from character codes.
|
||||||
|
*
|
||||||
|
* ## How to Use
|
||||||
|
*
|
||||||
|
* ### Creating Strings
|
||||||
|
* ```js
|
||||||
|
* var greeting = "Hello, world!"; // String literal (double quotes)
|
||||||
|
* var name = 'Steve'; // String literal (single quotes)
|
||||||
|
* var fromCode = String.fromCharCode(65); // "A" (from char code)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Searching & Checking
|
||||||
|
* ```js
|
||||||
|
* var str = "Hello, world!";
|
||||||
|
* str.indexOf("world"); // 7
|
||||||
|
* str.indexOf("missing"); // -1 (not found)
|
||||||
|
* str.lastIndexOf("l"); // 10
|
||||||
|
* str.search(/world/); // 7 (regex search)
|
||||||
|
* str.charAt(0); // "H"
|
||||||
|
* str.charCodeAt(0); // 72
|
||||||
|
* str.length; // 13
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Extracting & Transforming
|
||||||
|
* ```js
|
||||||
|
* var str = "Hello, world!";
|
||||||
|
* str.slice(7, 12); // "world"
|
||||||
|
* str.substring(0, 5); // "Hello"
|
||||||
|
* str.toUpperCase(); // "HELLO, WORLD!"
|
||||||
|
* str.toLowerCase(); // "hello, world!"
|
||||||
|
* str.trim(); // Removes leading/trailing whitespace
|
||||||
|
* str.replace("world", "NPC"); // "Hello, NPC!"
|
||||||
|
* str.replace(/l/g, "L"); // "HeLLo, worLd!" (regex with global flag)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Splitting & Joining
|
||||||
|
* ```js
|
||||||
|
* "a,b,c".split(","); // ["a", "b", "c"]
|
||||||
|
* "hello".split(""); // ["h", "e", "l", "l", "o"]
|
||||||
|
* ["a", "b", "c"].join("-"); // "a-b-c" (Array.join, but related)
|
||||||
|
* "one two three".split(" ", 2); // ["one", "two"] (limit results)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### Pattern Matching
|
||||||
|
* ```js
|
||||||
|
* "abc123".match(/\d+/); // ["123"]
|
||||||
|
* "no numbers".match(/\d+/); // null
|
||||||
|
* "hello".concat(" ", "world"); // "hello world"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* ### ❌ Common Mistakes
|
||||||
|
* ```js
|
||||||
|
* str.replace("l", "L"); // Only replaces FIRST "l" — use /l/g for all
|
||||||
|
* String.charAt(0); // TypeError — instance method, not static
|
||||||
|
* "abc"[0]; // May not work in all engines — use charAt()
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export interface String {
|
||||||
|
/** The number of characters in the string */
|
||||||
|
length: number;
|
||||||
|
|
||||||
|
/** Creates a string from one or more Unicode character codes (e.g., String.fromCharCode(65, 66, 67) returns "ABC") */
|
||||||
|
static fromCharCode(...codes: number[]): string;
|
||||||
|
|
||||||
|
/** Returns the Unicode code point (0–65535) of the character at the specified index. Unlike Java's charAt() + cast, this returns the numeric code directly. */
|
||||||
|
charCodeAt(pos: number): number;
|
||||||
|
|
||||||
|
/** Tests the string against a regular expression and returns an array of matches, or null if no match found */
|
||||||
|
match(regexp: any): any[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces a pattern (string or RegExp object) with a replacement string.
|
||||||
|
* Unlike Java's replace/replaceAll which only accept String/CharSequence,
|
||||||
|
* this accepts a RegExp object as the first argument.
|
||||||
|
*/
|
||||||
|
replace(searchValue: any, replaceValue: any): string;
|
||||||
|
|
||||||
|
/** Returns the index of the first character that matches a regular expression, or -1 if not found */
|
||||||
|
search(regexp: any): number;
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/.gradle
|
|
||||||
/build
|
|
||||||
/out
|
|
||||||
/bin
|
|
||||||
/.idea
|
|
||||||
/.vscode
|
|
||||||
/.settings
|
|
||||||
.project
|
|
||||||
.classpath
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
# dts-gradle-plugin
|
|
||||||
|
|
||||||
This repo contains the Gradle plugin for generating TypeScript `.d.ts` files for the CustomNPC-Plus API.
|
|
||||||
|
|
||||||
These files are used for the generation of auto-completion suggestions and type/interface documentation when scripting
|
|
||||||
in the Script Editor in-game.
|
|
||||||
|
|
||||||
### Implementation using JitPack
|
|
||||||
|
|
||||||
Add JitPack to the buildscript and depend on the plugin JAR. Using `main-SNAPSHOT` will build the latest `main` commit;
|
|
||||||
for reproducible builds use a tag or commit hash instead.
|
|
||||||
|
|
||||||
`settings.gradle`
|
|
||||||
```gradle
|
|
||||||
pluginManagement {
|
|
||||||
resolutionStrategy {
|
|
||||||
eachPlugin {
|
|
||||||
if(requested.id.toString() == "dts.typescript-generator") {
|
|
||||||
useModule("com.github.bigguy345:dts-gradle-plugin:main-SNAPSHOT")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
maven { url "https://jitpack.io" }
|
|
||||||
gradlePluginPortal()
|
|
||||||
mavenCentral()
|
|
||||||
mavenLocal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
`build.gradle`:
|
|
||||||
|
|
||||||
```gradle
|
|
||||||
plugins {
|
|
||||||
id 'dts.typescript-generator'
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// TypeScript Definition Generation Task
|
|
||||||
// Generates .d.ts files from Java API sources for scripting IDE support
|
|
||||||
// ============================================================================
|
|
||||||
// TypeScript plugin is applied above in the main plugins block
|
|
||||||
|
|
||||||
tasks.named("generateTypeScriptDefinitions").configure {
|
|
||||||
// Source directories containing the Java API code
|
|
||||||
sourceDirectories = ['src/main/java']
|
|
||||||
|
|
||||||
// Packages in source directories to generate .d.ts files for
|
|
||||||
apiPackages = ['noppes.npcs.api'] as Set
|
|
||||||
|
|
||||||
// Output directory for the generated .d.ts files
|
|
||||||
// Must be within resources/assets/${modId}/api to be detected by CNPC+
|
|
||||||
outputDirectory = "src/main/resources/assets/${modId}/api"
|
|
||||||
|
|
||||||
// Whether to clean old generated files before regenerating
|
|
||||||
cleanOutputFirst = true
|
|
||||||
|
|
||||||
// Optional: copy external patch .d.ts files into assets/<modid>/api/patches
|
|
||||||
patchesDirectory = "dts-patches"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Optional: To ensure definitions are generated on processing resources on jar build
|
|
||||||
// But in most cases, you may want to run the task manually when needed
|
|
||||||
// processResources.dependsOn generateTypeScriptDefinitions
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Patches (optional overrides)
|
|
||||||
|
|
||||||
Use `dts-patches/` to override or refine generated types. Files in this folder are copied to
|
|
||||||
`assets/<modid>/api/patches` after generation.
|
|
||||||
|
|
||||||
### Example: override `IPlayer.getDBCPlayer()` to return `IDBCAddon` instead of `IDBCPlayer`
|
|
||||||
|
|
||||||
File: `dts-patches/IPlayer.d.ts`
|
|
||||||
|
|
||||||
```ts
|
|
||||||
/**
|
|
||||||
* DBC Addon patch for IPlayer
|
|
||||||
* @javaFqn noppes.npcs.api.entity.IPlayer
|
|
||||||
*/
|
|
||||||
export interface IPlayer<T> {
|
|
||||||
getDBCPlayer(): IDBCAddon;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'groovy-gradle-plugin'
|
|
||||||
id 'maven-publish'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'dts'
|
|
||||||
version = '1.0.0'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation gradleApi()
|
|
||||||
implementation localGroovy()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure source sets if building as standalone
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
groovy {
|
|
||||||
srcDirs = ['src/main/groovy']
|
|
||||||
}
|
|
||||||
resources {
|
|
||||||
srcDirs = ['src/main/resources']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gradlePlugin {
|
|
||||||
plugins {
|
|
||||||
typescriptGenerator {
|
|
||||||
id = 'dts.typescript-generator'
|
|
||||||
implementationClass = 'dts.TypeScriptGeneratorPlugin'
|
|
||||||
displayName = 'TypeScript Definition Generator'
|
|
||||||
description = 'Generates TypeScript definition files from Java API sources'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
publishing {
|
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle duplicate resources
|
|
||||||
tasks.processResources {
|
|
||||||
duplicatesStrategy = 'include'
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
rootProject.name = 'dts-gradle-plugin'
|
|
||||||
@@ -1,175 +0,0 @@
|
|||||||
package dts
|
|
||||||
|
|
||||||
import org.gradle.api.DefaultTask
|
|
||||||
import org.gradle.api.tasks.TaskAction
|
|
||||||
import org.gradle.api.tasks.Input
|
|
||||||
import org.gradle.api.tasks.InputDirectory
|
|
||||||
import org.gradle.api.tasks.InputFiles
|
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
|
||||||
import org.gradle.api.tasks.Internal
|
|
||||||
import org.gradle.api.tasks.Optional
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gradle task that generates TypeScript definition (.d.ts) files from Java API sources.
|
|
||||||
*
|
|
||||||
* Usage in build.gradle:
|
|
||||||
*
|
|
||||||
* tasks.withType(GenerateTypeScriptTask).configureEach {
|
|
||||||
* sourceDirectories = ['src/api/java'] // Strings are converted to Files
|
|
||||||
* outputDirectory = 'src/main/resources/${modid}/api' // String converted to File
|
|
||||||
* apiPackages = ['noppes.npcs.api', 'kamkeel.npcdbc.api']
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
abstract class GenerateTypeScriptTask extends DefaultTask {
|
|
||||||
|
|
||||||
// Accept Object types (String or File) with @Internal annotation
|
|
||||||
@Internal
|
|
||||||
List<Object> sourceDirectories = []
|
|
||||||
|
|
||||||
@Internal
|
|
||||||
Object outputDirectory
|
|
||||||
|
|
||||||
@Input
|
|
||||||
Set<String> apiPackages = []
|
|
||||||
|
|
||||||
@Input
|
|
||||||
Boolean cleanOutputFirst = false
|
|
||||||
|
|
||||||
@Input
|
|
||||||
List<String> excludePatterns = []
|
|
||||||
|
|
||||||
@Internal
|
|
||||||
Object patchesDirectory
|
|
||||||
|
|
||||||
// Provide task input/output properties that Gradle can validate
|
|
||||||
@InputFiles
|
|
||||||
protected List<File> getResolvedSourceDirectories() {
|
|
||||||
return sourceDirectories.collect { obj ->
|
|
||||||
if (obj instanceof File) return obj
|
|
||||||
String pathStr = obj.toString()
|
|
||||||
if (pathStr.contains('${modid}')) {
|
|
||||||
String modid = project.archivesBaseName ?: 'mod'
|
|
||||||
pathStr = pathStr.replace('${modid}', modid)
|
|
||||||
}
|
|
||||||
File f = new File(pathStr)
|
|
||||||
if (!f.isAbsolute()) {
|
|
||||||
f = new File(project.projectDir, pathStr)
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OutputDirectory
|
|
||||||
protected File getResolvedOutputDirectory() {
|
|
||||||
def obj = outputDirectory
|
|
||||||
if (obj instanceof File) return obj
|
|
||||||
String pathStr = obj.toString()
|
|
||||||
if (pathStr.contains('${modid}')) {
|
|
||||||
String modid = project.archivesBaseName ?: 'mod'
|
|
||||||
pathStr = pathStr.replace('${modid}', modid)
|
|
||||||
}
|
|
||||||
File f = new File(pathStr)
|
|
||||||
if (!f.isAbsolute()) {
|
|
||||||
f = new File(project.projectDir, pathStr)
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
@Optional
|
|
||||||
@InputDirectory
|
|
||||||
protected File getResolvedDtsPatchesDirectory() {
|
|
||||||
if (patchesDirectory == null) return null
|
|
||||||
def obj = patchesDirectory
|
|
||||||
if (obj instanceof File) return obj
|
|
||||||
String pathStr = obj.toString()
|
|
||||||
if (pathStr.contains('${modid}')) {
|
|
||||||
String modid = project.archivesBaseName ?: 'mod'
|
|
||||||
pathStr = pathStr.replace('${modid}', modid)
|
|
||||||
}
|
|
||||||
File f = new File(pathStr)
|
|
||||||
if (!f.isAbsolute()) {
|
|
||||||
f = new File(project.projectDir, pathStr)
|
|
||||||
}
|
|
||||||
return f
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a value (String or File) to a File object.
|
|
||||||
* Supports special tokens like ${modid}.
|
|
||||||
*/
|
|
||||||
// conversion logic inlined into getters to avoid calling private helper at configuration time
|
|
||||||
|
|
||||||
GenerateTypeScriptTask() {
|
|
||||||
group = 'api'
|
|
||||||
description = 'Generates TypeScript definition files from Java API sources'
|
|
||||||
}
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
void generate() {
|
|
||||||
List<File> srcDirs = getResolvedSourceDirectories()
|
|
||||||
File outDir = getResolvedOutputDirectory()
|
|
||||||
File patchesDir = getResolvedDtsPatchesDirectory()
|
|
||||||
|
|
||||||
logger.lifecycle("=".multiply(60))
|
|
||||||
logger.lifecycle("Generating TypeScript definitions...")
|
|
||||||
logger.lifecycle("=".multiply(60))
|
|
||||||
|
|
||||||
if (srcDirs.isEmpty()) {
|
|
||||||
logger.warn("No source directories specified!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate directories
|
|
||||||
srcDirs.each { dir ->
|
|
||||||
if (!dir.exists()) {
|
|
||||||
logger.warn("Source directory does not exist: ${dir}")
|
|
||||||
} else {
|
|
||||||
logger.lifecycle("Source: ${dir}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.lifecycle("Output: ${outDir}")
|
|
||||||
logger.lifecycle("API Packages: ${apiPackages}")
|
|
||||||
|
|
||||||
// Clean output if requested
|
|
||||||
if (cleanOutputFirst && outDir.exists()) {
|
|
||||||
logger.lifecycle("Cleaning output directory...")
|
|
||||||
outDir.eachFileRecurse { file ->
|
|
||||||
if (file.name.endsWith('.d.ts') && !file.name.equals('minecraft-raw.d.ts') && !file.name.equals('forge-events-raw.d.ts')) {
|
|
||||||
file.delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create converter and process
|
|
||||||
JavaToTypeScriptConverter converter = new JavaToTypeScriptConverter(outDir, apiPackages)
|
|
||||||
|
|
||||||
List<File> validDirs = srcDirs.findAll { it.exists() }
|
|
||||||
if (validDirs.isEmpty()) {
|
|
||||||
logger.error("No valid source directories found!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
converter.processDirectories(validDirs, logger)
|
|
||||||
|
|
||||||
if (patchesDir != null) {
|
|
||||||
if (!patchesDir.exists()) {
|
|
||||||
logger.lifecycle("Patches directory does not exist: ${patchesDir}")
|
|
||||||
} else {
|
|
||||||
File patchOutputDir = new File(outDir, "patches")
|
|
||||||
if (patchOutputDir.exists()) {
|
|
||||||
patchOutputDir.deleteDir()
|
|
||||||
}
|
|
||||||
project.copy {
|
|
||||||
from patchesDir
|
|
||||||
into patchOutputDir
|
|
||||||
}
|
|
||||||
logger.lifecycle("Copied .d.ts patches to: ${patchOutputDir}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.lifecycle("=".multiply(60))
|
|
||||||
logger.lifecycle("TypeScript definition generation complete!")
|
|
||||||
logger.lifecycle("=".multiply(60))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package dts
|
|
||||||
|
|
||||||
import org.gradle.api.Plugin
|
|
||||||
import org.gradle.api.Project
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gradle plugin for generating TypeScript definition files from Java API sources.
|
|
||||||
*/
|
|
||||||
class TypeScriptGeneratorPlugin implements Plugin<Project> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void apply(Project project) {
|
|
||||||
if (project.tasks.findByName('generateTypeScriptDefinitions') == null) {
|
|
||||||
project.tasks.register('generateTypeScriptDefinitions', GenerateTypeScriptTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
implementation-class=dts.TypeScriptGeneratorPlugin
|
|
||||||
|
Before Width: | Height: | Size: 141 KiB |
|
After Width: | Height: | Size: 554 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 230 KiB After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 2.7 MiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 4.0 MiB |
|
Before Width: | Height: | Size: 337 KiB After Width: | Height: | Size: 337 KiB |
|
After Width: | Height: | Size: 573 KiB |
|
Before Width: | Height: | Size: 787 KiB |
|
Before Width: | Height: | Size: 227 KiB After Width: | Height: | Size: 227 KiB |
|
Before Width: | Height: | Size: 2.6 MiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 8.0 MiB |
@@ -0,0 +1,185 @@
|
|||||||
|
package bigguy.texteditor;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models the readiness lifecycle of the script editor's semantic pipeline.
|
||||||
|
*
|
||||||
|
* <p>Inspired by IntelliJ IDEA's {@code DumbService} dumb/smart mode pattern,
|
||||||
|
* this enum tracks how much of the analysis pipeline has completed and which
|
||||||
|
* editor features are currently safe to invoke.</p>
|
||||||
|
*
|
||||||
|
* <h3>State machine</h3>
|
||||||
|
* <pre>{@code
|
||||||
|
* UNINITIALIZED ──→ SYNTAX_READY (after initial CST parse)
|
||||||
|
* SYNTAX_READY ──→ ANALYZING (background semantic analysis started)
|
||||||
|
* ANALYZING ──→ SMART (analysis complete — all features available)
|
||||||
|
* ANALYZING ──→ DEGRADED (analysis failed — fall back to syntax-only)
|
||||||
|
* Any state ──→ SYNTAX_READY (text changed — semantics invalidated)
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* <h3>Feature gating</h3>
|
||||||
|
* <p>Each state advertises which editor capabilities are available via
|
||||||
|
* {@link #isSyntaxAvailable()} and {@link #isSemanticsAvailable()}.
|
||||||
|
* UI code should query these predicates rather than comparing states
|
||||||
|
* directly, so that new states can be added without breaking callers.</p>
|
||||||
|
*
|
||||||
|
* <h3>Thread safety</h3>
|
||||||
|
* <p>Enum constants are inherently immutable. The state <em>variable</em> holding
|
||||||
|
* the current readiness should be protected by whatever concurrency mechanism
|
||||||
|
* the orchestrator uses (e.g. {@code AtomicReference<ReadinessState>}).</p>
|
||||||
|
*/
|
||||||
|
public enum ReadinessState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No parse tree exists yet. The editor is essentially a plain text area.
|
||||||
|
* No syntax highlighting, no autocomplete, no diagnostics.
|
||||||
|
*/
|
||||||
|
UNINITIALIZED("Uninitialized — no parse tree", false, false, false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A concrete syntax tree is available. Tree-sitter highlighting, bracket
|
||||||
|
* matching, and keyword-only autocomplete are functional. Semantic features
|
||||||
|
* (type resolution, full autocomplete, error underlines) are not yet ready.
|
||||||
|
*/
|
||||||
|
SYNTAX_READY("Syntax ready — CST available, semantics pending", true, false, false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Background semantic analysis is in progress. The same features as
|
||||||
|
* {@link #SYNTAX_READY} are available; callers should show a progress
|
||||||
|
* indicator but must not block on the result.
|
||||||
|
*/
|
||||||
|
ANALYZING("Analyzing — semantic pass in progress", true, false, true),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full analysis is complete. Every editor feature is available: error
|
||||||
|
* underlines, scope-aware autocomplete, hover tooltips, go-to-definition,
|
||||||
|
* and scope coloring.
|
||||||
|
*/
|
||||||
|
SMART("Smart — full analysis complete", true, true, false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Semantic analysis failed (e.g. the type registry could not load, or an
|
||||||
|
* internal error occurred). The editor falls back to syntax-only mode
|
||||||
|
* and surface-level autocomplete. This state is recoverable: the next
|
||||||
|
* text change will transition back to {@link #SYNTAX_READY}.
|
||||||
|
*/
|
||||||
|
DEGRADED("Degraded — analysis failed, syntax-only fallback", true, false, false);
|
||||||
|
|
||||||
|
private static final Set<ReadinessState> FROM_UNINITIALIZED =
|
||||||
|
Collections.unmodifiableSet(EnumSet.of(SYNTAX_READY));
|
||||||
|
|
||||||
|
private static final Set<ReadinessState> FROM_SYNTAX_READY =
|
||||||
|
Collections.unmodifiableSet(EnumSet.of(ANALYZING, SYNTAX_READY));
|
||||||
|
|
||||||
|
private static final Set<ReadinessState> FROM_ANALYZING =
|
||||||
|
Collections.unmodifiableSet(EnumSet.of(SMART, DEGRADED, SYNTAX_READY));
|
||||||
|
|
||||||
|
private static final Set<ReadinessState> FROM_SMART =
|
||||||
|
Collections.unmodifiableSet(EnumSet.of(SYNTAX_READY));
|
||||||
|
|
||||||
|
private static final Set<ReadinessState> FROM_DEGRADED =
|
||||||
|
Collections.unmodifiableSet(EnumSet.of(SYNTAX_READY));
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
private final boolean syntaxAvailable;
|
||||||
|
private final boolean semanticsAvailable;
|
||||||
|
private final boolean analyzing;
|
||||||
|
|
||||||
|
ReadinessState(String description, boolean syntaxAvailable,
|
||||||
|
boolean semanticsAvailable, boolean analyzing) {
|
||||||
|
this.description = description;
|
||||||
|
this.syntaxAvailable = syntaxAvailable;
|
||||||
|
this.semanticsAvailable = semanticsAvailable;
|
||||||
|
this.analyzing = analyzing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} when a concrete syntax tree is available.
|
||||||
|
*
|
||||||
|
* <p>When syntax is available, the following features are safe to use:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>Tree-sitter syntax highlighting</li>
|
||||||
|
* <li>Bracket matching (CST-based)</li>
|
||||||
|
* <li>Keyword-only autocomplete</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @return whether CST-based features are available
|
||||||
|
*/
|
||||||
|
public boolean isSyntaxAvailable() {
|
||||||
|
return syntaxAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} when full semantic analysis has completed successfully.
|
||||||
|
*
|
||||||
|
* <p>When semantics are available, the following features are safe to use:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>Error underlines and diagnostic rendering</li>
|
||||||
|
* <li>Full (scope-aware, type-aware) autocomplete</li>
|
||||||
|
* <li>Hover tooltips with type information</li>
|
||||||
|
* <li>Go-to-definition navigation</li>
|
||||||
|
* <li>Scope coloring</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @return whether semantic features are available
|
||||||
|
*/
|
||||||
|
public boolean isSemanticsAvailable() {
|
||||||
|
return semanticsAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} when background analysis is currently in progress.
|
||||||
|
*
|
||||||
|
* <p>UI code can use this to display a progress indicator without blocking.</p>
|
||||||
|
*
|
||||||
|
* @return whether analysis is running
|
||||||
|
*/
|
||||||
|
public boolean isAnalyzing() {
|
||||||
|
return analyzing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a transition from this state to {@code next} is valid
|
||||||
|
* according to the state machine's transition rules.
|
||||||
|
*
|
||||||
|
* @param next the proposed target state
|
||||||
|
* @return {@code true} if the transition is allowed
|
||||||
|
* @throws NullPointerException if {@code next} is {@code null}
|
||||||
|
*/
|
||||||
|
public boolean canTransitionTo(ReadinessState next) {
|
||||||
|
if (next == null) {
|
||||||
|
throw new NullPointerException("Target state must not be null");
|
||||||
|
}
|
||||||
|
return validTargets().contains(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the set of states that this state may transition to.
|
||||||
|
*
|
||||||
|
* @return an unmodifiable set of valid target states
|
||||||
|
*/
|
||||||
|
public Set<ReadinessState> validTargets() {
|
||||||
|
switch (this) {
|
||||||
|
case UNINITIALIZED: return FROM_UNINITIALIZED;
|
||||||
|
case SYNTAX_READY: return FROM_SYNTAX_READY;
|
||||||
|
case ANALYZING: return FROM_ANALYZING;
|
||||||
|
case SMART: return FROM_SMART;
|
||||||
|
case DEGRADED: return FROM_DEGRADED;
|
||||||
|
default: return Collections.emptySet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human-readable description of this state, suitable for
|
||||||
|
* status bar display or debug logging.
|
||||||
|
*
|
||||||
|
* @return a descriptive string (never {@code null})
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,590 @@
|
|||||||
|
package bigguy.texteditor;
|
||||||
|
|
||||||
|
import bigguy.texteditor.analysis.IncrementalStrategy;
|
||||||
|
import bigguy.texteditor.analysis.SemanticAnalyzer;
|
||||||
|
import bigguy.texteditor.analysis.SemanticMarkBuilder;
|
||||||
|
import bigguy.texteditor.diagnostics.Diagnostic;
|
||||||
|
import bigguy.texteditor.diagnostics.DiagnosticStore;
|
||||||
|
import bigguy.texteditor.render.Mark;
|
||||||
|
import bigguy.texteditor.render.MarkLayer;
|
||||||
|
import bigguy.texteditor.render.RenderLine;
|
||||||
|
import bigguy.texteditor.render.RenderModel;
|
||||||
|
import bigguy.texteditor.semantics.SemanticModel;
|
||||||
|
import bigguy.texteditor.syntax.DocumentSyntax;
|
||||||
|
import bigguy.texteditor.syntax.SemanticNode;
|
||||||
|
import bigguy.texteditor.treesitter.java.HighlightCapture;
|
||||||
|
import bigguy.texteditor.treesitter.java.HighlightGroup;
|
||||||
|
import bigguy.texteditor.treesitter.java.JavaParser;
|
||||||
|
import bigguy.texteditor.treesitter.java.JavaQueryEngine;
|
||||||
|
import bigguy.texteditor.treesitter.java.SyntaxTree;
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Central pipeline coordinator for the script editor.
|
||||||
|
* Replaces ScriptDocument's coordination role with a clean,
|
||||||
|
* modular pipeline following IntelliJ IDEA's architecture.
|
||||||
|
*
|
||||||
|
* <h3>Pipeline</h3>
|
||||||
|
* <pre>{@code
|
||||||
|
* onTextChanged(text)
|
||||||
|
* → parser.parse(text) → SyntaxTree
|
||||||
|
* → DocumentSyntax.create(tree, version)
|
||||||
|
* → queryEngine.highlights(tree, text) → HighlightCaptures
|
||||||
|
* → convertHighlightsToMarks(captures, text) → List<Mark>
|
||||||
|
* → markLayer.setSyntaxMarks(marks)
|
||||||
|
* → markLayer.merge() → mergedMarks
|
||||||
|
* → renderModel.rebuild(text, mergedMarks, lineHeight)
|
||||||
|
* → state = SYNTAX_READY
|
||||||
|
* → semanticAnalyzer.scheduleAnalysis(syntax, rev, callback)
|
||||||
|
* → state = ANALYZING
|
||||||
|
* → (background) onAnalysisComplete → state = SMART
|
||||||
|
* onAnalysisFailed → state = DEGRADED
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
|
* <h3>Thread model</h3>
|
||||||
|
* <ul>
|
||||||
|
* <li>Syntax highlighting runs on the UI thread (fast, <5ms)</li>
|
||||||
|
* <li>Semantic analysis runs on a background daemon thread via {@link SemanticAnalyzer}</li>
|
||||||
|
* <li>Analysis callbacks fire on the background thread, updating {@code volatile state}</li>
|
||||||
|
* <li>State transitions are atomic via volatile {@link ReadinessState}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <h3>State machine</h3>
|
||||||
|
* <pre>{@code
|
||||||
|
* UNINITIALIZED → SYNTAX_READY (first onTextChanged)
|
||||||
|
* SYNTAX_READY → ANALYZING (analysis scheduled)
|
||||||
|
* ANALYZING → SMART (analysis complete, revision matches)
|
||||||
|
* ANALYZING → DEGRADED (analysis failed, revision matches)
|
||||||
|
* ANALYZING → SYNTAX_READY (new text change arrives)
|
||||||
|
* SMART → SYNTAX_READY (text changed again)
|
||||||
|
* DEGRADED → SYNTAX_READY (text changed again)
|
||||||
|
* }</pre>
|
||||||
|
*/
|
||||||
|
public class ScriptOrchestrator implements SemanticAnalyzer.AnalysisCallback {
|
||||||
|
|
||||||
|
// --- Error underline colors (ARGB) ---
|
||||||
|
private static final int ERROR_COLOR = 0xFFFF5555;
|
||||||
|
private static final int WARNING_COLOR = 0xFFFFAA00;
|
||||||
|
private static final int INFO_COLOR = 0xFF5555FF;
|
||||||
|
|
||||||
|
// --- Core state ---
|
||||||
|
private volatile ReadinessState state = ReadinessState.UNINITIALIZED;
|
||||||
|
private final AtomicLong revision = new AtomicLong(0);
|
||||||
|
|
||||||
|
// --- Syntax layer ---
|
||||||
|
private final JavaParser parser;
|
||||||
|
private final JavaQueryEngine queryEngine;
|
||||||
|
private volatile DocumentSyntax currentSyntax;
|
||||||
|
|
||||||
|
// --- Render pipeline ---
|
||||||
|
private final MarkLayer markLayer;
|
||||||
|
private final RenderModel renderModel;
|
||||||
|
private final DiagnosticStore diagnosticStore;
|
||||||
|
|
||||||
|
// --- Configuration ---
|
||||||
|
private int lineHeight = 10;
|
||||||
|
|
||||||
|
// --- Semantic analysis ---
|
||||||
|
private final SemanticAnalyzer semanticAnalyzer;
|
||||||
|
private final IncrementalStrategy incrementalStrategy;
|
||||||
|
private TextSpan[] lastChangedRanges;
|
||||||
|
private volatile String currentSourceText = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new orchestrator with default-configured components.
|
||||||
|
*
|
||||||
|
* <p>Initializes the tree-sitter parser, query engine, mark layer,
|
||||||
|
* render model, diagnostic store, semantic analyzer, and incremental
|
||||||
|
* strategy. All components start empty; call
|
||||||
|
* {@link #onTextChanged(String)} to kick off the pipeline.</p>
|
||||||
|
*/
|
||||||
|
public ScriptOrchestrator() {
|
||||||
|
this.parser = new JavaParser();
|
||||||
|
this.queryEngine = new JavaQueryEngine();
|
||||||
|
this.markLayer = new MarkLayer();
|
||||||
|
this.renderModel = new RenderModel();
|
||||||
|
this.diagnosticStore = new DiagnosticStore();
|
||||||
|
this.semanticAnalyzer = new SemanticAnalyzer();
|
||||||
|
this.incrementalStrategy = new IncrementalStrategy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== MAIN PIPELINE ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the source text changes. Runs the syntax pipeline
|
||||||
|
* synchronously on the UI thread (fast path), then schedules
|
||||||
|
* background semantic analysis.
|
||||||
|
*
|
||||||
|
* <p>Any in-flight analysis from a previous edit is cancelled before
|
||||||
|
* scheduling a new one, ensuring stale results are never applied.</p>
|
||||||
|
*
|
||||||
|
* @param text the complete source text of the document
|
||||||
|
*/
|
||||||
|
public void onTextChanged(String text) {
|
||||||
|
long rev = revision.incrementAndGet();
|
||||||
|
|
||||||
|
// Cancel any in-flight analysis from the previous edit
|
||||||
|
semanticAnalyzer.cancelInFlight();
|
||||||
|
|
||||||
|
// Step 1: Parse CST
|
||||||
|
SyntaxTree syntaxTree = parser.parse(text);
|
||||||
|
|
||||||
|
// Step 2: Create DocumentSyntax
|
||||||
|
currentSyntax = DocumentSyntax.create(syntaxTree, (int) rev);
|
||||||
|
|
||||||
|
// Step 3: Collect parser errors as diagnostics
|
||||||
|
diagnosticStore.clearBySource(Diagnostic.Source.PARSER);
|
||||||
|
collectParserErrors(currentSyntax);
|
||||||
|
|
||||||
|
// Step 4: Extract syntax highlights from tree-sitter
|
||||||
|
List<HighlightCapture> highlights = queryEngine.highlights(syntaxTree, text);
|
||||||
|
|
||||||
|
// Step 5: Convert highlights to Mark objects
|
||||||
|
List<Mark> syntaxMarks = convertHighlightsToMarks(highlights, text);
|
||||||
|
|
||||||
|
// Step 6: Set syntax marks in the mark layer
|
||||||
|
markLayer.setSyntaxMarks(syntaxMarks);
|
||||||
|
|
||||||
|
// Step 7: Merge marks (syntax + any prior semantic marks)
|
||||||
|
List<Mark> mergedMarks = markLayer.merge();
|
||||||
|
|
||||||
|
// Step 8: Rebuild render model from source + merged marks
|
||||||
|
currentSourceText = text;
|
||||||
|
renderModel.rebuild(text, mergedMarks, lineHeight);
|
||||||
|
|
||||||
|
// Step 9: Syntax pipeline complete
|
||||||
|
state = ReadinessState.SYNTAX_READY;
|
||||||
|
|
||||||
|
// Step 10: Schedule background semantic analysis
|
||||||
|
state = ReadinessState.ANALYZING;
|
||||||
|
semanticAnalyzer.scheduleAnalysis(currentSyntax, rev, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== ANALYSIS CALLBACKS ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnalysisComplete(long revision, SemanticModel semanticModel, DocumentSyntax syntax) {
|
||||||
|
if (revision != this.revision.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Mark> semanticMarks = SemanticMarkBuilder.build(semanticModel, syntax);
|
||||||
|
markLayer.setSemanticMarks(semanticMarks);
|
||||||
|
List<Mark> mergedMarks = markLayer.merge();
|
||||||
|
renderModel.rebuild(currentSourceText, mergedMarks, lineHeight);
|
||||||
|
|
||||||
|
state = ReadinessState.SMART;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnalysisFailed(long revision, Exception error) {
|
||||||
|
if (revision != this.revision.get()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
state = ReadinessState.DEGRADED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== HIGHLIGHT → MARK CONVERSION ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts tree-sitter {@link HighlightCapture}s into {@link Mark} objects.
|
||||||
|
* Maps each {@link HighlightGroup} to a {@link TokenType} for rendering.
|
||||||
|
*
|
||||||
|
* @param highlights the highlight captures from the query engine
|
||||||
|
* @param text the complete source text (used for bounds validation)
|
||||||
|
* @return a list of syntax marks, one per highlight capture
|
||||||
|
*/
|
||||||
|
private List<Mark> convertHighlightsToMarks(List<HighlightCapture> highlights, String text) {
|
||||||
|
if (highlights.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
int textLength = text.length();
|
||||||
|
List<Mark> marks = new ArrayList<>(highlights.size());
|
||||||
|
for (HighlightCapture capture : highlights) {
|
||||||
|
TextSpan span = capture.getSpan();
|
||||||
|
if (span == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int startByte = span.getStartByte();
|
||||||
|
int endByte = span.getEndByte();
|
||||||
|
if (startByte < 0 || endByte <= startByte || startByte >= textLength) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (endByte > textLength) {
|
||||||
|
endByte = textLength;
|
||||||
|
}
|
||||||
|
TokenType tokenType = mapHighlightGroupToTokenType(capture.getGroup());
|
||||||
|
marks.add(Mark.syntax(startByte, endByte, tokenType));
|
||||||
|
}
|
||||||
|
return marks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps a tree-sitter {@link HighlightGroup} to the rendering
|
||||||
|
* {@link TokenType}. Every group is explicitly mapped — no fallthrough.
|
||||||
|
*
|
||||||
|
* <p>The mapping aims to match IntelliJ-style colorization:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>Language keywords and control flow → {@link TokenType#KEYWORD}</li>
|
||||||
|
* <li>Type references and declarations → {@link TokenType#TYPE_DECL} / specific decl types</li>
|
||||||
|
* <li>Function/method names → {@link TokenType#METHOD_DECL} or {@link TokenType#METHOD_CALL}</li>
|
||||||
|
* <li>Strings, numbers, booleans → their respective literal types</li>
|
||||||
|
* <li>Comments → {@link TokenType#COMMENT}</li>
|
||||||
|
* <li>Punctuation/operators → {@link TokenType#DEFAULT} (white, lowest priority)</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param group the highlight group from tree-sitter
|
||||||
|
* @return the corresponding token type for rendering
|
||||||
|
*/
|
||||||
|
private static TokenType mapHighlightGroupToTokenType(HighlightGroup group) {
|
||||||
|
switch (group) {
|
||||||
|
// --- Properties and variables ---
|
||||||
|
case PROPERTY:
|
||||||
|
return TokenType.GLOBAL_FIELD;
|
||||||
|
case VARIABLE:
|
||||||
|
return TokenType.VARIABLE;
|
||||||
|
case PARAMETER:
|
||||||
|
return TokenType.PARAMETER;
|
||||||
|
|
||||||
|
// --- Functions / methods ---
|
||||||
|
case FUNCTION:
|
||||||
|
return TokenType.METHOD_DECL;
|
||||||
|
case FUNCTION_CALL:
|
||||||
|
return TokenType.METHOD_CALL;
|
||||||
|
case SUPER:
|
||||||
|
// "super" is function.builtin in tree-sitter — render as keyword
|
||||||
|
return TokenType.KEYWORD;
|
||||||
|
case CONSTRUCTOR:
|
||||||
|
return TokenType.METHOD_DECL;
|
||||||
|
|
||||||
|
// --- Types ---
|
||||||
|
case TYPE:
|
||||||
|
return TokenType.TYPE_DECL;
|
||||||
|
case TYPE_PARAMETER:
|
||||||
|
return TokenType.GENERIC_TYPE_PARAM;
|
||||||
|
case INTERFACE:
|
||||||
|
return TokenType.INTERFACE_DECL;
|
||||||
|
case TYPE_BUILTIN:
|
||||||
|
// Primitive types (int, boolean, void) — styled like keywords
|
||||||
|
return TokenType.KEYWORD;
|
||||||
|
case ENUM:
|
||||||
|
return TokenType.ENUM_DECL;
|
||||||
|
|
||||||
|
// --- Constants ---
|
||||||
|
case CONSTANT:
|
||||||
|
return TokenType.STATIC_FINAL_FIELD;
|
||||||
|
case CONSTANT_BUILTIN:
|
||||||
|
// true, false, null
|
||||||
|
return TokenType.LITERAL;
|
||||||
|
|
||||||
|
// --- Keywords (all keyword.* variants) ---
|
||||||
|
case KEYWORD:
|
||||||
|
case KEYWORD_CONTROL:
|
||||||
|
case KEYWORD_OPERATOR:
|
||||||
|
case KEYWORD_FUNCTION:
|
||||||
|
case KEYWORD_TYPE:
|
||||||
|
case KEYWORD_MODIFIER:
|
||||||
|
return TokenType.KEYWORD;
|
||||||
|
|
||||||
|
// --- Operators ---
|
||||||
|
case OPERATOR:
|
||||||
|
return TokenType.DEFAULT;
|
||||||
|
|
||||||
|
// --- Strings ---
|
||||||
|
case STRING:
|
||||||
|
case STRING_ESCAPE:
|
||||||
|
case STRING_SPECIAL:
|
||||||
|
return TokenType.STRING;
|
||||||
|
|
||||||
|
// --- Numeric and boolean literals ---
|
||||||
|
case NUMBER:
|
||||||
|
return TokenType.LITERAL;
|
||||||
|
case BOOLEAN:
|
||||||
|
return TokenType.LITERAL;
|
||||||
|
|
||||||
|
// --- Comments ---
|
||||||
|
case COMMENT:
|
||||||
|
return TokenType.COMMENT;
|
||||||
|
case COMMENT_DOC:
|
||||||
|
return TokenType.COMMENT;
|
||||||
|
|
||||||
|
// --- Annotations ---
|
||||||
|
case ATTRIBUTE:
|
||||||
|
// Java annotations (@Override, @Test) — styled like JSDoc tags
|
||||||
|
return TokenType.JSDOC_TAG;
|
||||||
|
|
||||||
|
// --- Labels ---
|
||||||
|
case LABEL:
|
||||||
|
return TokenType.KEYWORD;
|
||||||
|
|
||||||
|
// --- Punctuation ---
|
||||||
|
case PUNCTUATION_BRACKET:
|
||||||
|
case PUNCTUATION_DELIMITER:
|
||||||
|
case PUNCTUATION_SPECIAL:
|
||||||
|
return TokenType.DEFAULT;
|
||||||
|
|
||||||
|
// --- Embedded / unknown ---
|
||||||
|
case EMBEDDED:
|
||||||
|
return TokenType.DEFAULT;
|
||||||
|
case UNKNOWN:
|
||||||
|
return TokenType.DEFAULT;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return TokenType.DEFAULT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== PARSER ERROR COLLECTION ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Walks the CST root and collects all ERROR and MISSING nodes as
|
||||||
|
* parser diagnostics in the {@link DiagnosticStore}.
|
||||||
|
*
|
||||||
|
* <p>ERROR nodes represent unparseable source regions. MISSING nodes
|
||||||
|
* represent tokens the parser expected but did not find (e.g. a
|
||||||
|
* missing semicolon).</p>
|
||||||
|
*
|
||||||
|
* @param syntax the document syntax to scan for errors
|
||||||
|
*/
|
||||||
|
private void collectParserErrors(DocumentSyntax syntax) {
|
||||||
|
SemanticNode root = syntax.root();
|
||||||
|
if (root == null || !root.hasError()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
collectParserErrorsRecursive(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively walks the semantic node tree, creating diagnostics
|
||||||
|
* for any ERROR or MISSING nodes encountered.
|
||||||
|
*
|
||||||
|
* @param node the current node being visited
|
||||||
|
*/
|
||||||
|
private void collectParserErrorsRecursive(SemanticNode node) {
|
||||||
|
if (node.isError()) {
|
||||||
|
TextSpan span = node.span();
|
||||||
|
if (span != null && span.getByteLength() > 0) {
|
||||||
|
String text = node.text();
|
||||||
|
String message = "Syntax error" + (text != null && !text.isEmpty()
|
||||||
|
? ": unexpected '" + truncate(text, 30) + "'"
|
||||||
|
: "");
|
||||||
|
diagnosticStore.addDiagnostic(Diagnostic.of(
|
||||||
|
span, Diagnostic.Severity.ERROR, message, Diagnostic.Source.PARSER));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (node.isMissing()) {
|
||||||
|
TextSpan span = node.span();
|
||||||
|
if (span != null) {
|
||||||
|
String nodeType = node.nodeType();
|
||||||
|
String message = "Missing " + (nodeType != null ? "'" + nodeType + "'" : "token");
|
||||||
|
diagnosticStore.addDiagnostic(Diagnostic.of(
|
||||||
|
span, Diagnostic.Severity.ERROR, message, Diagnostic.Source.PARSER));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int childCount = node.childCount();
|
||||||
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
SemanticNode child = node.child(i);
|
||||||
|
if (child != null && child.hasError()) {
|
||||||
|
collectParserErrorsRecursive(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== STATE QUERIES ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current readiness state of the pipeline.
|
||||||
|
*
|
||||||
|
* @return the current {@link ReadinessState}
|
||||||
|
*/
|
||||||
|
public ReadinessState getReadinessState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the monotonically increasing revision counter.
|
||||||
|
* Incremented on every {@link #onTextChanged(String)} call.
|
||||||
|
*
|
||||||
|
* @return the current revision number
|
||||||
|
*/
|
||||||
|
public long getRevision() {
|
||||||
|
return revision.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== COMPONENT ACCESS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the render model containing the line layout and viewport calculations.
|
||||||
|
*
|
||||||
|
* @return the render model, never {@code null}
|
||||||
|
*/
|
||||||
|
public RenderModel getRenderModel() {
|
||||||
|
return renderModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the mark layer used for syntax/semantic/error mark merging.
|
||||||
|
*
|
||||||
|
* @return the mark layer, never {@code null}
|
||||||
|
*/
|
||||||
|
public MarkLayer getMarkLayer() {
|
||||||
|
return markLayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the diagnostic store containing all parser and analysis errors.
|
||||||
|
*
|
||||||
|
* @return the diagnostic store, never {@code null}
|
||||||
|
*/
|
||||||
|
public DiagnosticStore getDiagnosticStore() {
|
||||||
|
return diagnosticStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current document syntax, or {@code null} if no parse
|
||||||
|
* has been performed yet.
|
||||||
|
*
|
||||||
|
* @return the latest {@link DocumentSyntax}, or {@code null}
|
||||||
|
*/
|
||||||
|
public DocumentSyntax getCurrentSyntax() {
|
||||||
|
return currentSyntax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current semantic model from the analyzer.
|
||||||
|
* May be {@code null} or unbuilt if no analysis has completed yet.
|
||||||
|
*
|
||||||
|
* @return the latest {@link SemanticModel}, or {@code null}
|
||||||
|
*/
|
||||||
|
public SemanticModel getSemanticModel() {
|
||||||
|
return semanticAnalyzer.getSemanticModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== CONFIGURATION ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pixel height per line used for render model layout.
|
||||||
|
*
|
||||||
|
* @param lineHeight pixel height per line (must be positive)
|
||||||
|
*/
|
||||||
|
public void setLineHeight(int lineHeight) {
|
||||||
|
this.lineHeight = lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current pixel height per line.
|
||||||
|
*
|
||||||
|
* @return the line height in pixels
|
||||||
|
*/
|
||||||
|
public int getLineHeight() {
|
||||||
|
return lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== DIAGNOSTIC HELPERS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns diagnostic ranges for a specific render line, suitable for
|
||||||
|
* passing to {@link RenderLine#drawErrorUnderlines(int, int, List)}.
|
||||||
|
*
|
||||||
|
* <p>Queries the {@link DiagnosticStore} for diagnostics overlapping the
|
||||||
|
* line's byte range, then converts each to a
|
||||||
|
* {@link RenderLine.DiagnosticRange} with an appropriate underline color
|
||||||
|
* based on severity.</p>
|
||||||
|
*
|
||||||
|
* @param line the render line to query diagnostics for
|
||||||
|
* @return a list of diagnostic ranges, possibly empty, never {@code null}
|
||||||
|
*/
|
||||||
|
public List<RenderLine.DiagnosticRange> getDiagnosticsForLine(RenderLine line) {
|
||||||
|
if (line == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<Diagnostic> lineDiagnostics = diagnosticStore.getDiagnosticsInRange(
|
||||||
|
line.getGlobalStart(), line.getGlobalEnd());
|
||||||
|
if (lineDiagnostics.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<RenderLine.DiagnosticRange> ranges = new ArrayList<>(lineDiagnostics.size());
|
||||||
|
for (Diagnostic diag : lineDiagnostics) {
|
||||||
|
TextSpan range = diag.range();
|
||||||
|
int color = diagnosticColor(diag.severity());
|
||||||
|
ranges.add(new RenderLine.DiagnosticRange(
|
||||||
|
range.getStartByte(), range.getEndByte(), color));
|
||||||
|
}
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ARGB underline color for a diagnostic severity level.
|
||||||
|
*
|
||||||
|
* @param severity the diagnostic severity
|
||||||
|
* @return the ARGB color for the wavy underline
|
||||||
|
*/
|
||||||
|
private static int diagnosticColor(Diagnostic.Severity severity) {
|
||||||
|
switch (severity) {
|
||||||
|
case ERROR:
|
||||||
|
return ERROR_COLOR;
|
||||||
|
case WARNING:
|
||||||
|
return WARNING_COLOR;
|
||||||
|
case INFO:
|
||||||
|
case HINT:
|
||||||
|
return INFO_COLOR;
|
||||||
|
default:
|
||||||
|
return ERROR_COLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== LIFECYCLE ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases all resources held by this orchestrator.
|
||||||
|
* Called when the editor is closed.
|
||||||
|
*
|
||||||
|
* <p>Disposes the semantic analyzer (cancels in-flight analysis and shuts
|
||||||
|
* down its executor), closes the tree-sitter parser (releasing native
|
||||||
|
* memory), clears the mark layer, diagnostic store, and nullifies the
|
||||||
|
* current syntax reference.</p>
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
semanticAnalyzer.dispose();
|
||||||
|
parser.close();
|
||||||
|
markLayer.clear();
|
||||||
|
diagnosticStore.clear();
|
||||||
|
currentSyntax = null;
|
||||||
|
state = ReadinessState.UNINITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== INTERNAL UTILITIES ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Truncates a string to the given maximum length, appending "..." if truncated.
|
||||||
|
*
|
||||||
|
* @param text the string to truncate
|
||||||
|
* @param maxLength the maximum length before truncation
|
||||||
|
* @return the original string if short enough, or a truncated version
|
||||||
|
*/
|
||||||
|
private static String truncate(String text, int maxLength) {
|
||||||
|
if (text.length() <= maxLength) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return text.substring(0, maxLength) + "...";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ScriptOrchestrator{state=" + state
|
||||||
|
+ ", revision=" + revision.get()
|
||||||
|
+ ", syntax=" + (currentSyntax != null ? currentSyntax : "null")
|
||||||
|
+ ", renderModel=" + renderModel
|
||||||
|
+ ", diagnostics=" + diagnosticStore
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,386 @@
|
|||||||
|
package bigguy.texteditor.analysis;
|
||||||
|
|
||||||
|
import bigguy.texteditor.syntax.DocumentSyntax;
|
||||||
|
import bigguy.texteditor.syntax.SemanticNode;
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classifies text edits into invalidation scopes, determining how much of
|
||||||
|
* the semantic model needs rebuilding after an incremental reparse.
|
||||||
|
*
|
||||||
|
* <p>This is the intelligence behind incremental analysis — the core of the
|
||||||
|
* "every keystroke must NOT cause a full rebuild" requirement. By inspecting
|
||||||
|
* which CST nodes changed, the strategy assigns a minimal
|
||||||
|
* {@link InvalidationScope} that tells {@code SemanticModel} exactly which
|
||||||
|
* sub-components need updating.</p>
|
||||||
|
*
|
||||||
|
* <h3>Design</h3>
|
||||||
|
* <p>The algorithm walks upward from each changed range's deepest node to
|
||||||
|
* classify the edit into one of five categories:</p>
|
||||||
|
* <ol>
|
||||||
|
* <li>{@link InvalidationScope#NONE NONE} — edit inside string/comment</li>
|
||||||
|
* <li>{@link InvalidationScope#LOCAL_SCOPE LOCAL_SCOPE} — edit inside method body</li>
|
||||||
|
* <li>{@link InvalidationScope#DECLARATION DECLARATION} — signature changed</li>
|
||||||
|
* <li>{@link InvalidationScope#IMPORTS IMPORTS} — import changed</li>
|
||||||
|
* <li>{@link InvalidationScope#STRUCTURAL STRUCTURAL} — class/method boundary changed</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* <h3>Performance impact</h3>
|
||||||
|
* <pre>
|
||||||
|
* | InvalidationScope | SymbolTable | ScopeTree | ImportIndex | Cost |
|
||||||
|
* |-------------------|-------------|-----------------|-------------|---------|
|
||||||
|
* | NONE | Keep | Keep | Keep | ~0.01ms |
|
||||||
|
* | LOCAL_SCOPE | Keep | Rebuild 1 scope | Keep | ~2ms |
|
||||||
|
* | DECLARATION | Rebuild | Rebuild | Keep | ~10ms |
|
||||||
|
* | IMPORTS | Keep | Keep | Rebuild | ~10ms |
|
||||||
|
* | STRUCTURAL | Rebuild all | Rebuild all | Rebuild all | ~50ms |
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <h3>Thread safety</h3>
|
||||||
|
* <p>This class is stateless and therefore inherently thread-safe. All methods
|
||||||
|
* are pure functions of their arguments.</p>
|
||||||
|
*
|
||||||
|
* @see InvalidationScope
|
||||||
|
*/
|
||||||
|
public final class IncrementalStrategy {
|
||||||
|
|
||||||
|
// ── CST node type constants ────────────────────────────────────────────────
|
||||||
|
// Centralised here to avoid scattered string literals throughout the class.
|
||||||
|
|
||||||
|
private static final String NODE_IMPORT_DECLARATION = "import_declaration";
|
||||||
|
private static final String NODE_CLASS_DECLARATION = "class_declaration";
|
||||||
|
private static final String NODE_INTERFACE_DECLARATION = "interface_declaration";
|
||||||
|
private static final String NODE_ENUM_DECLARATION = "enum_declaration";
|
||||||
|
private static final String NODE_ANNOTATION_TYPE_DECLARATION = "annotation_type_declaration";
|
||||||
|
private static final String NODE_METHOD_DECLARATION = "method_declaration";
|
||||||
|
private static final String NODE_CONSTRUCTOR_DECLARATION = "constructor_declaration";
|
||||||
|
private static final String NODE_FIELD_DECLARATION = "field_declaration";
|
||||||
|
private static final String NODE_BLOCK = "block";
|
||||||
|
private static final String NODE_PROGRAM = "program";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node types that represent type/member declarations whose modification
|
||||||
|
* requires at least a {@link InvalidationScope#DECLARATION DECLARATION}
|
||||||
|
* level rebuild.
|
||||||
|
*/
|
||||||
|
private static final Set<String> DECLARATION_NODE_TYPES = Collections.unmodifiableSet(
|
||||||
|
new HashSet<String>(Arrays.asList(
|
||||||
|
NODE_CLASS_DECLARATION,
|
||||||
|
NODE_INTERFACE_DECLARATION,
|
||||||
|
NODE_ENUM_DECLARATION,
|
||||||
|
NODE_ANNOTATION_TYPE_DECLARATION,
|
||||||
|
NODE_METHOD_DECLARATION,
|
||||||
|
NODE_CONSTRUCTOR_DECLARATION,
|
||||||
|
NODE_FIELD_DECLARATION
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Node types that represent method-like constructs (nodes whose "body"
|
||||||
|
* child introduces a local scope).
|
||||||
|
*/
|
||||||
|
private static final Set<String> METHOD_LIKE_NODE_TYPES = Collections.unmodifiableSet(
|
||||||
|
new HashSet<String>(Arrays.asList(
|
||||||
|
NODE_METHOD_DECLARATION,
|
||||||
|
NODE_CONSTRUCTOR_DECLARATION
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── Invalidation scope enum ────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the extent of semantic invalidation required after an edit.
|
||||||
|
*
|
||||||
|
* <p>Scopes are ordered from cheapest ({@link #NONE}) to most expensive
|
||||||
|
* ({@link #STRUCTURAL}). When multiple changed ranges yield different
|
||||||
|
* scopes, the highest (most expensive) scope wins.</p>
|
||||||
|
*/
|
||||||
|
public enum InvalidationScope {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No semantic change — the edit was entirely inside a string literal or
|
||||||
|
* comment. Only byte-offset adjustment is needed; all semantic data
|
||||||
|
* structures remain valid.
|
||||||
|
*/
|
||||||
|
NONE(0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit inside a method or constructor body — only the affected scope
|
||||||
|
* needs to be rebuilt in the {@code ScopeTree}. The {@code SymbolTable}
|
||||||
|
* and {@code ImportIndex} are unaffected because no declarations or
|
||||||
|
* imports changed.
|
||||||
|
*/
|
||||||
|
LOCAL_SCOPE(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type, method, or field declaration changed — the {@code SymbolTable}
|
||||||
|
* and {@code ScopeTree} need rebuilding, but the {@code ImportIndex}
|
||||||
|
* remains valid.
|
||||||
|
*/
|
||||||
|
DECLARATION(2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An import declaration changed — the {@code ImportIndex} needs
|
||||||
|
* rebuilding. Downstream type resolution may also need re-running.
|
||||||
|
*/
|
||||||
|
IMPORTS(3),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class or method boundary changed (structural edit) — all semantic
|
||||||
|
* data structures must be fully rebuilt. This is the worst case and
|
||||||
|
* corresponds to edits that alter the fundamental structure of the file
|
||||||
|
* (e.g., adding/removing a class, changing method signatures across
|
||||||
|
* multiple declarations).
|
||||||
|
*/
|
||||||
|
STRUCTURAL(4);
|
||||||
|
|
||||||
|
private final int severity;
|
||||||
|
|
||||||
|
InvalidationScope(int severity) {
|
||||||
|
this.severity = severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the numeric severity level for comparison. Higher values
|
||||||
|
* indicate more expensive rebuilds.
|
||||||
|
*
|
||||||
|
* @return the severity ordinal (0 = cheapest, 4 = most expensive)
|
||||||
|
*/
|
||||||
|
public int severity() {
|
||||||
|
return severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the more severe of two scopes.
|
||||||
|
*
|
||||||
|
* @param a the first scope
|
||||||
|
* @param b the second scope
|
||||||
|
* @return the scope with the higher severity
|
||||||
|
*/
|
||||||
|
public static InvalidationScope max(InvalidationScope a, InvalidationScope b) {
|
||||||
|
if (a == null) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
if (b == null) {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
return a.severity >= b.severity ? a : b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Constructor ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new incremental strategy instance.
|
||||||
|
*
|
||||||
|
* <p>This class is stateless; a single instance can be reused across
|
||||||
|
* all analysis cycles.</p>
|
||||||
|
*/
|
||||||
|
public IncrementalStrategy() {
|
||||||
|
// Stateless — no initialisation needed.
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Public API ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classifies the combined impact of all CST changes to determine how much
|
||||||
|
* of the semantic model needs re-analysis.
|
||||||
|
*
|
||||||
|
* <p>Each changed range is classified independently via
|
||||||
|
* {@link #classifySingleChange(TextSpan, DocumentSyntax)}, and the
|
||||||
|
* worst-case (highest severity) scope across all ranges is returned.</p>
|
||||||
|
*
|
||||||
|
* <p>If no ranges changed, returns {@link InvalidationScope#NONE}.</p>
|
||||||
|
*
|
||||||
|
* @param changedRanges the byte ranges that changed (from tree-sitter's
|
||||||
|
* {@code getChangedRanges()}); may be {@code null} or empty
|
||||||
|
* @param syntax the <em>new</em> document syntax after reparse
|
||||||
|
* @return the invalidation scope indicating how much needs rebuilding
|
||||||
|
* @throws IllegalArgumentException if {@code syntax} is {@code null}
|
||||||
|
*/
|
||||||
|
public InvalidationScope classify(TextSpan[] changedRanges, DocumentSyntax syntax) {
|
||||||
|
if (syntax == null) {
|
||||||
|
throw new IllegalArgumentException("syntax must not be null");
|
||||||
|
}
|
||||||
|
if (changedRanges == null || changedRanges.length == 0) {
|
||||||
|
return InvalidationScope.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
InvalidationScope worst = InvalidationScope.NONE;
|
||||||
|
|
||||||
|
for (TextSpan range : changedRanges) {
|
||||||
|
if (range == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
InvalidationScope rangeScope = classifySingleChange(range, syntax);
|
||||||
|
worst = InvalidationScope.max(worst, rangeScope);
|
||||||
|
|
||||||
|
// Short-circuit: STRUCTURAL is the maximum possible severity.
|
||||||
|
if (worst == InvalidationScope.STRUCTURAL) {
|
||||||
|
return worst;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return worst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classifies a single changed byte range to determine its invalidation scope.
|
||||||
|
*
|
||||||
|
* <p>The algorithm proceeds in three steps:</p>
|
||||||
|
* <ol>
|
||||||
|
* <li><strong>Exclusion check:</strong> If the edit start falls inside a
|
||||||
|
* string literal or comment, the edit is semantically invisible →
|
||||||
|
* {@link InvalidationScope#NONE}.</li>
|
||||||
|
* <li><strong>Node lookup:</strong> Find the deepest named CST node at the
|
||||||
|
* edit's start byte offset.</li>
|
||||||
|
* <li><strong>Ancestor walk:</strong> Walk upward from the deepest node,
|
||||||
|
* checking whether the change falls inside a method body (local scope),
|
||||||
|
* an import declaration, or a type/member declaration.</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param changedRange the byte range that changed
|
||||||
|
* @param syntax the <em>new</em> document syntax after reparse
|
||||||
|
* @return the invalidation scope for this single change
|
||||||
|
* @throws IllegalArgumentException if either argument is {@code null}
|
||||||
|
*/
|
||||||
|
public InvalidationScope classifySingleChange(TextSpan changedRange, DocumentSyntax syntax) {
|
||||||
|
if (changedRange == null) {
|
||||||
|
throw new IllegalArgumentException("changedRange must not be null");
|
||||||
|
}
|
||||||
|
if (syntax == null) {
|
||||||
|
throw new IllegalArgumentException("syntax must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 1: Check if the edit is inside an excluded region (string/comment).
|
||||||
|
// If so, no semantic data structures are affected.
|
||||||
|
if (syntax.isExcluded(changedRange.getStartByte())) {
|
||||||
|
return InvalidationScope.NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Find the deepest named node at the start of the change.
|
||||||
|
SemanticNode node = syntax.nodeAtOffset(changedRange.getStartByte());
|
||||||
|
if (node == null) {
|
||||||
|
// Cannot determine context — assume the worst case.
|
||||||
|
return InvalidationScope.STRUCTURAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 3: Walk up the ancestry chain to classify the change.
|
||||||
|
return classifyByAncestry(node, changedRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Private classification logic ───────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Walks upward from the given node to its ancestors, classifying the change
|
||||||
|
* based on which syntactic construct encloses it.
|
||||||
|
*
|
||||||
|
* <p>The walk checks in order:</p>
|
||||||
|
* <ol>
|
||||||
|
* <li>Is the node inside a method/constructor body? → {@code LOCAL_SCOPE}</li>
|
||||||
|
* <li>Is the node inside an import declaration? → {@code IMPORTS}</li>
|
||||||
|
* <li>Is the node inside a declaration node? → {@code DECLARATION}</li>
|
||||||
|
* <li>Otherwise → {@code STRUCTURAL}</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param startNode the deepest node at the change offset
|
||||||
|
* @param changedRange the byte range that changed
|
||||||
|
* @return the classified invalidation scope
|
||||||
|
*/
|
||||||
|
private InvalidationScope classifyByAncestry(SemanticNode startNode, TextSpan changedRange) {
|
||||||
|
SemanticNode current = startNode;
|
||||||
|
|
||||||
|
// Track whether we've seen a block node that could be a method body.
|
||||||
|
// This prevents misclassifying standalone blocks (like static initialisers)
|
||||||
|
// as method bodies.
|
||||||
|
boolean insideMethodBody = false;
|
||||||
|
|
||||||
|
while (current != null) {
|
||||||
|
String nodeType = current.nodeType();
|
||||||
|
if (nodeType == null) {
|
||||||
|
current = current.parent();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we're inside a method/constructor body.
|
||||||
|
// A "block" node that is the "body" field of a method/constructor
|
||||||
|
// means the edit is contained within a local scope.
|
||||||
|
if (NODE_BLOCK.equals(nodeType)) {
|
||||||
|
SemanticNode parent = current.parent();
|
||||||
|
if (parent != null && isMethodLikeNode(parent.nodeType())) {
|
||||||
|
// Verify the change is entirely within this body block.
|
||||||
|
TextSpan bodySpan = current.span();
|
||||||
|
if (bodySpan != null && bodySpan.contains(changedRange)) {
|
||||||
|
insideMethodBody = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've reached a method-like node and the edit was inside its body,
|
||||||
|
// we can classify as LOCAL_SCOPE.
|
||||||
|
if (isMethodLikeNode(nodeType) && insideMethodBody) {
|
||||||
|
return InvalidationScope.LOCAL_SCOPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for import declarations.
|
||||||
|
if (NODE_IMPORT_DECLARATION.equals(nodeType)) {
|
||||||
|
return InvalidationScope.IMPORTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for declaration nodes (but not if we already know we're in a method body).
|
||||||
|
// For method/constructor declarations, we reach here only if the edit was in
|
||||||
|
// the signature (not the body), which is a DECLARATION-level change.
|
||||||
|
if (isDeclarationNode(nodeType) && !insideMethodBody) {
|
||||||
|
return InvalidationScope.DECLARATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've reached the program root without finding a specific construct,
|
||||||
|
// the edit is at the top level — structural change.
|
||||||
|
if (NODE_PROGRAM.equals(nodeType)) {
|
||||||
|
// If the edit is directly inside the program node (e.g., adding a new
|
||||||
|
// class or import), and we haven't classified it yet, it's structural.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = current.parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: structural change (couldn't classify more specifically).
|
||||||
|
return InvalidationScope.STRUCTURAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Static helper methods ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the given node type represents a declaration construct
|
||||||
|
* (class, interface, enum, annotation, method, constructor, or field).
|
||||||
|
*
|
||||||
|
* @param nodeType the tree-sitter node type string
|
||||||
|
* @return {@code true} if the node type is a declaration
|
||||||
|
*/
|
||||||
|
private static boolean isDeclarationNode(String nodeType) {
|
||||||
|
return nodeType != null && DECLARATION_NODE_TYPES.contains(nodeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the given node type represents a method-like construct
|
||||||
|
* (method or constructor declaration) that has a body introducing a
|
||||||
|
* local scope.
|
||||||
|
*
|
||||||
|
* @param nodeType the tree-sitter node type string
|
||||||
|
* @return {@code true} if the node type is method-like
|
||||||
|
*/
|
||||||
|
private static boolean isMethodLikeNode(String nodeType) {
|
||||||
|
return nodeType != null && METHOD_LIKE_NODE_TYPES.contains(nodeType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "IncrementalStrategy{}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,651 @@
|
|||||||
|
package bigguy.texteditor.analysis;
|
||||||
|
|
||||||
|
import bigguy.texteditor.analysis.IncrementalStrategy.InvalidationScope;
|
||||||
|
import bigguy.texteditor.semantics.SemanticModel;
|
||||||
|
import bigguy.texteditor.syntax.DocumentSyntax;
|
||||||
|
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ThreadFactory;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Owns the background semantic analysis pipeline and schedules semantic
|
||||||
|
* analysis after syntax parsing completes.
|
||||||
|
*
|
||||||
|
* <p>This class is the bridge between the UI-thread syntax pipeline and the
|
||||||
|
* background semantic pipeline. It is called by the orchestrator after each
|
||||||
|
* text change and follows a strict revision-based protocol to prevent stale
|
||||||
|
* semantic data from contaminating fresh syntax state.</p>
|
||||||
|
*
|
||||||
|
* <h3>Lifecycle</h3>
|
||||||
|
* <ol>
|
||||||
|
* <li>The orchestrator calls {@link #scheduleAnalysis} or
|
||||||
|
* {@link #scheduleIncrementalAnalysis} after each text change.</li>
|
||||||
|
* <li>Any in-flight analysis is cancelled immediately.</li>
|
||||||
|
* <li>An immutable snapshot of the current state is captured and submitted
|
||||||
|
* to a single-thread {@link ExecutorService}.</li>
|
||||||
|
* <li>On completion, results are published back to the caller via an
|
||||||
|
* {@link AnalysisCallback}.</li>
|
||||||
|
* <li>Stale results (where the revision has advanced since submission)
|
||||||
|
* are silently discarded.</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* <h3>Stale-result protocol</h3>
|
||||||
|
* <p>The key invariant is: <strong>never blend stale semantic data with fresh
|
||||||
|
* syntax</strong>. When a revision changes:</p>
|
||||||
|
* <ol>
|
||||||
|
* <li>Drop ALL semantic decorations immediately.</li>
|
||||||
|
* <li>Show syntax-only highlighting.</li>
|
||||||
|
* <li>When semantic analysis completes for the <em>current</em> revision,
|
||||||
|
* apply atomically.</li>
|
||||||
|
* <li>When semantic analysis completes for an <em>old</em> revision,
|
||||||
|
* discard silently.</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* <h3>Thread safety</h3>
|
||||||
|
* <p>All public methods are safe to call from any thread. The executor is a
|
||||||
|
* single-thread pool, so analysis tasks are serialised. The {@code disposed}
|
||||||
|
* and {@code inFlightAnalysis} fields use {@code volatile} for visibility
|
||||||
|
* across threads, and the {@code currentRevision} uses {@link AtomicLong}
|
||||||
|
* for atomic updates.</p>
|
||||||
|
*
|
||||||
|
* <h3>Callback threading</h3>
|
||||||
|
* <p>The {@link AnalysisCallback} is invoked on the <em>background</em>
|
||||||
|
* analysis thread, not the UI thread. Callers (typically the orchestrator)
|
||||||
|
* must handle the thread boundary themselves — for example, via
|
||||||
|
* Minecraft's scheduled-task system — before applying results to
|
||||||
|
* UI-visible state.</p>
|
||||||
|
*
|
||||||
|
* @see SemanticModel
|
||||||
|
* @see IncrementalStrategy
|
||||||
|
* @see DocumentSyntax
|
||||||
|
*/
|
||||||
|
public final class SemanticAnalyzer {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(SemanticAnalyzer.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name assigned to the daemon analysis thread. Appears in thread dumps
|
||||||
|
* and debugger views for easy identification.
|
||||||
|
*/
|
||||||
|
private static final String THREAD_NAME = "ScriptEditor-SemanticAnalysis";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum time (in milliseconds) to wait for the executor to terminate
|
||||||
|
* during {@link #dispose()}.
|
||||||
|
*/
|
||||||
|
private static final long SHUTDOWN_TIMEOUT_MS = 2000L;
|
||||||
|
|
||||||
|
// ── Callback interface ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface for receiving analysis results.
|
||||||
|
*
|
||||||
|
* <p>The orchestrator implements this to apply semantic marks and
|
||||||
|
* transition state. <strong>Important:</strong> callbacks are invoked on
|
||||||
|
* the background analysis thread, not the UI thread. Implementors must
|
||||||
|
* marshal results to the appropriate thread before modifying UI state.</p>
|
||||||
|
*
|
||||||
|
* <p>The caller <strong>must</strong> check that the revision still matches
|
||||||
|
* the current document revision before applying results. The analyzer
|
||||||
|
* performs its own revision check before invoking the callback, but there
|
||||||
|
* is an inherent race window between the check and the callback body
|
||||||
|
* executing, so a second check in the callback is recommended.</p>
|
||||||
|
*/
|
||||||
|
public interface AnalysisCallback {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when analysis completes successfully for the given revision.
|
||||||
|
*
|
||||||
|
* <p>The caller <strong>must</strong> verify that the revision still
|
||||||
|
* matches the current document revision before applying results.
|
||||||
|
* If the revision has advanced, these results are stale and must
|
||||||
|
* be discarded.</p>
|
||||||
|
*
|
||||||
|
* @param revision the revision number this analysis was for
|
||||||
|
* @param semanticModel the populated semantic model
|
||||||
|
* @param syntax the {@link DocumentSyntax} that was analyzed
|
||||||
|
*/
|
||||||
|
void onAnalysisComplete(long revision, SemanticModel semanticModel, DocumentSyntax syntax);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when analysis fails with an exception.
|
||||||
|
*
|
||||||
|
* <p>The revision is provided so the caller can determine whether
|
||||||
|
* the failure is still relevant to the current document state.</p>
|
||||||
|
*
|
||||||
|
* @param revision the revision number this analysis was for
|
||||||
|
* @param error the exception that occurred during analysis
|
||||||
|
*/
|
||||||
|
void onAnalysisFailed(long revision, Exception error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Fields ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single-thread executor for background analysis. Uses a daemon thread
|
||||||
|
* so it does not prevent JVM (Minecraft) shutdown.
|
||||||
|
*/
|
||||||
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The semantic model being built and updated. Owned exclusively by this
|
||||||
|
* analyzer; only accessed from the analysis thread (except for
|
||||||
|
* {@link #getSemanticModel()} which returns a snapshot reference).
|
||||||
|
*/
|
||||||
|
private final SemanticModel semanticModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stateless strategy for classifying edits into invalidation scopes.
|
||||||
|
* Used by the incremental analysis path to determine which parts of
|
||||||
|
* the semantic model need rebuilding.
|
||||||
|
*/
|
||||||
|
private final IncrementalStrategy strategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currently in-flight analysis {@link Future}, or {@code null} if
|
||||||
|
* no analysis is running. Volatile for cross-thread visibility.
|
||||||
|
*/
|
||||||
|
private volatile Future<?> inFlightAnalysis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The revision number that was most recently submitted for analysis.
|
||||||
|
* Used for stale-result detection: if the revision has advanced past
|
||||||
|
* this value by the time analysis completes, the results are discarded.
|
||||||
|
*/
|
||||||
|
private final AtomicLong currentRevision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to {@code true} when {@link #dispose()} is called. Prevents new
|
||||||
|
* analysis submissions and causes in-flight analysis to bail out early.
|
||||||
|
*/
|
||||||
|
private volatile boolean disposed;
|
||||||
|
|
||||||
|
// ── Constructor ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@code SemanticAnalyzer} with a single-thread daemon
|
||||||
|
* executor, a fresh {@link SemanticModel}, and a stateless
|
||||||
|
* {@link IncrementalStrategy}.
|
||||||
|
*
|
||||||
|
* <p>The executor uses a daemon thread with slightly lower than normal
|
||||||
|
* priority ({@link Thread#NORM_PRIORITY} - 1) so that analysis does not
|
||||||
|
* compete with UI rendering for CPU time.</p>
|
||||||
|
*/
|
||||||
|
public SemanticAnalyzer() {
|
||||||
|
this.executor = Executors.newSingleThreadExecutor(createDaemonThreadFactory());
|
||||||
|
this.semanticModel = new SemanticModel();
|
||||||
|
this.strategy = new IncrementalStrategy();
|
||||||
|
this.inFlightAnalysis = null;
|
||||||
|
this.currentRevision = new AtomicLong(0L);
|
||||||
|
this.disposed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Public API ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules a full semantic analysis for the given syntax snapshot.
|
||||||
|
*
|
||||||
|
* <p>Any currently in-flight analysis is cancelled before scheduling the
|
||||||
|
* new one. The revision number is recorded so that stale results can be
|
||||||
|
* detected and discarded when the analysis completes.</p>
|
||||||
|
*
|
||||||
|
* <p>The analysis performs a complete rebuild of the {@link SemanticModel}:
|
||||||
|
* all sub-components (SymbolTable, ScopeTree, ImportIndex, InferenceCache)
|
||||||
|
* are cleared and rebuilt from scratch by walking the CST.</p>
|
||||||
|
*
|
||||||
|
* <p>If the analyzer has been {@linkplain #dispose() disposed}, this
|
||||||
|
* method is a no-op.</p>
|
||||||
|
*
|
||||||
|
* @param syntax the document syntax to analyze (immutable snapshot from
|
||||||
|
* the parser); must not be {@code null}
|
||||||
|
* @param revision the revision number for stale-detection; callers should
|
||||||
|
* use a monotonically increasing counter
|
||||||
|
* @param callback the callback to invoke with results; must not be
|
||||||
|
* {@code null}
|
||||||
|
* @throws IllegalArgumentException if {@code syntax} or {@code callback}
|
||||||
|
* is {@code null}
|
||||||
|
*/
|
||||||
|
public void scheduleAnalysis(DocumentSyntax syntax, long revision, AnalysisCallback callback) {
|
||||||
|
validateScheduleArguments(syntax, revision, callback);
|
||||||
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRevision.set(revision);
|
||||||
|
cancelInFlight();
|
||||||
|
|
||||||
|
inFlightAnalysis = executor.submit(new FullAnalysisTask(syntax, revision, callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Schedules an incremental analysis using the provided invalidation scope.
|
||||||
|
*
|
||||||
|
* <p>Only rebuilds the affected parts of the semantic model, as determined
|
||||||
|
* by the {@link InvalidationScope}:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link InvalidationScope#NONE NONE} — no-op; the callback
|
||||||
|
* is still invoked with the existing model so the orchestrator can
|
||||||
|
* apply offset-adjusted decorations.</li>
|
||||||
|
* <li>{@link InvalidationScope#LOCAL_SCOPE LOCAL_SCOPE} — only
|
||||||
|
* the scope tree is rebuilt.</li>
|
||||||
|
* <li>{@link InvalidationScope#DECLARATION DECLARATION} — full
|
||||||
|
* rebuild (symbol table + scope tree).</li>
|
||||||
|
* <li>{@link InvalidationScope#IMPORTS IMPORTS} — only the import
|
||||||
|
* index is rebuilt.</li>
|
||||||
|
* <li>{@link InvalidationScope#STRUCTURAL STRUCTURAL} — full
|
||||||
|
* rebuild of all sub-components.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Any currently in-flight analysis is cancelled before scheduling.
|
||||||
|
* If the analyzer has been {@linkplain #dispose() disposed}, this method
|
||||||
|
* is a no-op.</p>
|
||||||
|
*
|
||||||
|
* @param syntax the document syntax after reparse; must not be
|
||||||
|
* {@code null}
|
||||||
|
* @param revision the revision number for stale-detection
|
||||||
|
* @param scope the invalidation scope from {@link IncrementalStrategy};
|
||||||
|
* must not be {@code null}
|
||||||
|
* @param callback the callback to invoke with results; must not be
|
||||||
|
* {@code null}
|
||||||
|
* @throws IllegalArgumentException if any argument is {@code null}
|
||||||
|
*/
|
||||||
|
public void scheduleIncrementalAnalysis(DocumentSyntax syntax, long revision,
|
||||||
|
InvalidationScope scope,
|
||||||
|
AnalysisCallback callback) {
|
||||||
|
validateScheduleArguments(syntax, revision, callback);
|
||||||
|
if (scope == null) {
|
||||||
|
throw new IllegalArgumentException("scope must not be null");
|
||||||
|
}
|
||||||
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRevision.set(revision);
|
||||||
|
cancelInFlight();
|
||||||
|
|
||||||
|
inFlightAnalysis = executor.submit(
|
||||||
|
new IncrementalAnalysisTask(syntax, revision, scope, callback)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cancels any in-flight analysis. Safe to call from any thread.
|
||||||
|
*
|
||||||
|
* <p>If an analysis is currently running, it is interrupted via
|
||||||
|
* {@link Future#cancel(boolean) cancel(true)}. The background task checks
|
||||||
|
* for interruption at key points and will bail out gracefully.</p>
|
||||||
|
*
|
||||||
|
* <p>After cancellation, {@link #isAnalyzing()} will return {@code false}
|
||||||
|
* once the background thread has actually stopped (which may not be
|
||||||
|
* immediate if the task is in the middle of a non-interruptible
|
||||||
|
* operation).</p>
|
||||||
|
*/
|
||||||
|
public void cancelInFlight() {
|
||||||
|
Future<?> current = inFlightAnalysis;
|
||||||
|
if (current != null && !current.isDone()) {
|
||||||
|
current.cancel(true);
|
||||||
|
}
|
||||||
|
inFlightAnalysis = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether an analysis is currently running or queued.
|
||||||
|
*
|
||||||
|
* <p>A return value of {@code true} means there is a {@link Future} that
|
||||||
|
* has not yet completed. Note that due to the inherent race between
|
||||||
|
* checking and acting, this method is advisory only — the analysis
|
||||||
|
* may complete (or be cancelled) between the check and the caller's next
|
||||||
|
* action.</p>
|
||||||
|
*
|
||||||
|
* @return {@code true} if an analysis task is in flight
|
||||||
|
*/
|
||||||
|
public boolean isAnalyzing() {
|
||||||
|
Future<?> current = inFlightAnalysis;
|
||||||
|
return current != null && !current.isDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current semantic model.
|
||||||
|
*
|
||||||
|
* <p>The returned reference is the <em>live</em> model that the background
|
||||||
|
* thread mutates during analysis. Callers should be aware that the model's
|
||||||
|
* contents may change between calls if an analysis is in flight. For
|
||||||
|
* consistent reads, callers should either:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>Read only when {@link #isAnalyzing()} is {@code false}, or</li>
|
||||||
|
* <li>Use the model snapshot provided via {@link AnalysisCallback}.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>This method is primarily intended for incremental analysis paths that
|
||||||
|
* need access to the previous model state before scheduling an update.</p>
|
||||||
|
*
|
||||||
|
* @return the semantic model (never {@code null})
|
||||||
|
*/
|
||||||
|
public SemanticModel getSemanticModel() {
|
||||||
|
return semanticModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the incremental strategy used by this analyzer.
|
||||||
|
*
|
||||||
|
* <p>The strategy is stateless and can be used by external callers
|
||||||
|
* (e.g., the orchestrator) to classify edits before deciding whether
|
||||||
|
* to call {@link #scheduleAnalysis} or
|
||||||
|
* {@link #scheduleIncrementalAnalysis}.</p>
|
||||||
|
*
|
||||||
|
* @return the incremental strategy (never {@code null})
|
||||||
|
*/
|
||||||
|
public IncrementalStrategy getStrategy() {
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the revision number that was most recently submitted for
|
||||||
|
* analysis.
|
||||||
|
*
|
||||||
|
* <p>This can be compared against the document's current revision to
|
||||||
|
* determine whether the latest analysis results are still relevant.</p>
|
||||||
|
*
|
||||||
|
* @return the most recently submitted revision number
|
||||||
|
*/
|
||||||
|
public long getCurrentRevision() {
|
||||||
|
return currentRevision.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down the background executor and cancels any in-flight analysis.
|
||||||
|
*
|
||||||
|
* <p><strong>Must</strong> be called when the editor closes to release
|
||||||
|
* the background thread. After disposal:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>All {@code schedule*} methods become no-ops.</li>
|
||||||
|
* <li>{@link #isAnalyzing()} returns {@code false}.</li>
|
||||||
|
* <li>Any in-flight analysis bails out without invoking the callback.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>This method blocks for up to {@value #SHUTDOWN_TIMEOUT_MS}ms waiting
|
||||||
|
* for the executor to terminate. If the executor does not terminate in
|
||||||
|
* time, it is forcefully shut down via {@link ExecutorService#shutdownNow()}.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* <p>Safe to call multiple times; subsequent calls are no-ops.</p>
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
if (disposed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
disposed = true;
|
||||||
|
|
||||||
|
cancelInFlight();
|
||||||
|
semanticModel.clear();
|
||||||
|
|
||||||
|
executor.shutdown();
|
||||||
|
try {
|
||||||
|
if (!executor.awaitTermination(SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Semantic analysis executor did not terminate within {0}ms; forcing shutdown",
|
||||||
|
SHUTDOWN_TIMEOUT_MS);
|
||||||
|
executor.shutdownNow();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
executor.shutdownNow();
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this analyzer has been disposed.
|
||||||
|
*
|
||||||
|
* @return {@code true} if {@link #dispose()} has been called
|
||||||
|
*/
|
||||||
|
public boolean isDisposed() {
|
||||||
|
return disposed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Analysis tasks ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runnable that performs a full semantic model rebuild on the background
|
||||||
|
* thread. Checks for disposal and revision staleness before and after
|
||||||
|
* the rebuild.
|
||||||
|
*/
|
||||||
|
private final class FullAnalysisTask implements Runnable {
|
||||||
|
|
||||||
|
private final DocumentSyntax syntax;
|
||||||
|
private final long revision;
|
||||||
|
private final AnalysisCallback callback;
|
||||||
|
|
||||||
|
FullAnalysisTask(DocumentSyntax syntax, long revision, AnalysisCallback callback) {
|
||||||
|
this.syntax = syntax;
|
||||||
|
this.revision = revision;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (shouldAbort()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
semanticModel.rebuild(syntax);
|
||||||
|
|
||||||
|
if (shouldAbort()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deliverSuccess();
|
||||||
|
} catch (Exception e) {
|
||||||
|
deliverFailure(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this task should abort execution.
|
||||||
|
*
|
||||||
|
* <p>Abort conditions:</p>
|
||||||
|
* <ul>
|
||||||
|
* <li>The analyzer has been disposed.</li>
|
||||||
|
* <li>The thread has been interrupted (task was cancelled).</li>
|
||||||
|
* <li>The revision has been superseded by a newer submission.</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @return {@code true} if the task should stop immediately
|
||||||
|
*/
|
||||||
|
private boolean shouldAbort() {
|
||||||
|
return disposed
|
||||||
|
|| Thread.currentThread().isInterrupted()
|
||||||
|
|| currentRevision.get() != revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers the successful analysis result via the callback, after a
|
||||||
|
* final staleness check. If the revision has been superseded between
|
||||||
|
* the analysis completing and this delivery attempt, the result is
|
||||||
|
* silently discarded.
|
||||||
|
*/
|
||||||
|
private void deliverSuccess() {
|
||||||
|
if (disposed || currentRevision.get() != revision) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
callback.onAnalysisComplete(revision, semanticModel, syntax);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Exception in AnalysisCallback.onAnalysisComplete for revision " + revision, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers a failure notification via the callback, unless the
|
||||||
|
* analyzer is disposed or the thread was interrupted (in which case
|
||||||
|
* the failure is expected and not reported to the caller).
|
||||||
|
*/
|
||||||
|
private void deliverFailure(Exception error) {
|
||||||
|
if (disposed || Thread.currentThread().isInterrupted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
callback.onAnalysisFailed(revision, error);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Exception in AnalysisCallback.onAnalysisFailed for revision " + revision, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runnable that performs an incremental semantic model update on the
|
||||||
|
* background thread. Uses the {@link InvalidationScope} to determine
|
||||||
|
* which sub-components of the model need rebuilding.
|
||||||
|
*
|
||||||
|
* <p>For {@link InvalidationScope#NONE}, the model is left untouched but
|
||||||
|
* the callback is still invoked so the orchestrator can apply
|
||||||
|
* offset-adjusted decorations using the existing model state.</p>
|
||||||
|
*/
|
||||||
|
private final class IncrementalAnalysisTask implements Runnable {
|
||||||
|
|
||||||
|
private final DocumentSyntax syntax;
|
||||||
|
private final long revision;
|
||||||
|
private final InvalidationScope scope;
|
||||||
|
private final AnalysisCallback callback;
|
||||||
|
|
||||||
|
IncrementalAnalysisTask(DocumentSyntax syntax, long revision,
|
||||||
|
InvalidationScope scope, AnalysisCallback callback) {
|
||||||
|
this.syntax = syntax;
|
||||||
|
this.revision = revision;
|
||||||
|
this.scope = scope;
|
||||||
|
this.callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (shouldAbort()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// For NONE scope, the model is already up-to-date; we still
|
||||||
|
// invoke the callback so the orchestrator can re-apply
|
||||||
|
// decorations with corrected offsets.
|
||||||
|
if (scope != InvalidationScope.NONE) {
|
||||||
|
semanticModel.incrementalUpdate(syntax, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldAbort()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deliverSuccess();
|
||||||
|
} catch (Exception e) {
|
||||||
|
deliverFailure(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this task should abort execution.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the task should stop immediately
|
||||||
|
* @see FullAnalysisTask#shouldAbort()
|
||||||
|
*/
|
||||||
|
private boolean shouldAbort() {
|
||||||
|
return disposed
|
||||||
|
|| Thread.currentThread().isInterrupted()
|
||||||
|
|| currentRevision.get() != revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers the successful analysis result via the callback, after a
|
||||||
|
* final staleness check.
|
||||||
|
*/
|
||||||
|
private void deliverSuccess() {
|
||||||
|
if (disposed || currentRevision.get() != revision) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
callback.onAnalysisComplete(revision, semanticModel, syntax);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Exception in AnalysisCallback.onAnalysisComplete for revision " + revision, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers a failure notification via the callback.
|
||||||
|
*/
|
||||||
|
private void deliverFailure(Exception error) {
|
||||||
|
if (disposed || Thread.currentThread().isInterrupted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
callback.onAnalysisFailed(revision, error);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.log(Level.WARNING,
|
||||||
|
"Exception in AnalysisCallback.onAnalysisFailed for revision " + revision, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Argument validation ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates common arguments for the {@code schedule*} methods.
|
||||||
|
*
|
||||||
|
* @param syntax the document syntax (must not be {@code null})
|
||||||
|
* @param revision the revision number (informational; no constraint)
|
||||||
|
* @param callback the analysis callback (must not be {@code null})
|
||||||
|
* @throws IllegalArgumentException if {@code syntax} or {@code callback}
|
||||||
|
* is {@code null}
|
||||||
|
*/
|
||||||
|
private static void validateScheduleArguments(DocumentSyntax syntax, long revision,
|
||||||
|
AnalysisCallback callback) {
|
||||||
|
if (syntax == null) {
|
||||||
|
throw new IllegalArgumentException("syntax must not be null");
|
||||||
|
}
|
||||||
|
if (callback == null) {
|
||||||
|
throw new IllegalArgumentException("callback must not be null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Thread factory ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a {@link ThreadFactory} that produces a single daemon thread
|
||||||
|
* with a descriptive name and slightly reduced priority.
|
||||||
|
*
|
||||||
|
* <p>The daemon flag ensures the thread does not prevent JVM shutdown
|
||||||
|
* (critical in Minecraft's modded environment where the game client may
|
||||||
|
* close while analysis is in flight). The reduced priority
|
||||||
|
* ({@link Thread#NORM_PRIORITY} - 1) ensures analysis does not starve
|
||||||
|
* the render thread.</p>
|
||||||
|
*
|
||||||
|
* @return a thread factory for the analysis executor
|
||||||
|
*/
|
||||||
|
private static ThreadFactory createDaemonThreadFactory() {
|
||||||
|
return new ThreadFactory() {
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable r) {
|
||||||
|
Thread t = new Thread(r, THREAD_NAME);
|
||||||
|
t.setDaemon(true);
|
||||||
|
t.setPriority(Thread.NORM_PRIORITY - 1);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SemanticAnalyzer{"
|
||||||
|
+ "analyzing=" + isAnalyzing()
|
||||||
|
+ ", revision=" + currentRevision.get()
|
||||||
|
+ ", disposed=" + disposed
|
||||||
|
+ ", model=" + semanticModel
|
||||||
|
+ '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,576 @@
|
|||||||
|
package bigguy.texteditor.analysis;
|
||||||
|
|
||||||
|
import bigguy.texteditor.index.Symbol;
|
||||||
|
import bigguy.texteditor.index.Symbol.FieldSymbol;
|
||||||
|
import bigguy.texteditor.index.Symbol.ImportSymbol;
|
||||||
|
import bigguy.texteditor.index.Symbol.MethodSymbol;
|
||||||
|
import bigguy.texteditor.index.Symbol.TypeSymbol;
|
||||||
|
import bigguy.texteditor.index.SymbolKind;
|
||||||
|
import bigguy.texteditor.render.Mark;
|
||||||
|
import bigguy.texteditor.semantics.SemanticModel;
|
||||||
|
import bigguy.texteditor.semantics.SymbolTable;
|
||||||
|
import bigguy.texteditor.syntax.DocumentSyntax;
|
||||||
|
import bigguy.texteditor.syntax.SemanticNode;
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translates the semantic model (symbols extracted from the CST) into {@link Mark}
|
||||||
|
* objects that the render pipeline can merge with syntax marks.
|
||||||
|
*
|
||||||
|
* <p>This builder bridges semantic analysis and visual rendering. It walks the CST
|
||||||
|
* via {@link DocumentSyntax} to locate the <em>name</em> portion of each declaration,
|
||||||
|
* then creates a {@link Mark#semantic(int, int, TokenType, Object) semantic mark}
|
||||||
|
* with the correct {@link TokenType} and the originating {@link Symbol} as metadata.
|
||||||
|
* Attaching the symbol enables downstream features like hover tooltips and
|
||||||
|
* go-to-definition.</p>
|
||||||
|
*
|
||||||
|
* <h3>Why walk the CST instead of using Symbol ranges?</h3>
|
||||||
|
* <p>{@link Symbol#range()} covers the <em>entire</em> declaration (e.g., the full
|
||||||
|
* {@code public class Foo { ... }} block for a {@link TypeSymbol}). Highlighting
|
||||||
|
* the full range would incorrectly color keywords, punctuation, and body content.
|
||||||
|
* By walking the CST and extracting each declaration's "name" child node, we
|
||||||
|
* highlight only the identifier — matching what users expect from a modern IDE.</p>
|
||||||
|
*
|
||||||
|
* <h3>Symbol → TokenType mapping</h3>
|
||||||
|
* <table>
|
||||||
|
* <tr><th>Symbol type</th><th>Condition</th><th>TokenType</th></tr>
|
||||||
|
* <tr><td>{@link TypeSymbol}</td><td>{@link SymbolKind#CLASS}</td>
|
||||||
|
* <td>{@link TokenType#CLASS_DECL}</td></tr>
|
||||||
|
* <tr><td>{@link TypeSymbol}</td><td>{@link SymbolKind#INTERFACE}</td>
|
||||||
|
* <td>{@link TokenType#INTERFACE_DECL}</td></tr>
|
||||||
|
* <tr><td>{@link TypeSymbol}</td><td>{@link SymbolKind#ENUM}</td>
|
||||||
|
* <td>{@link TokenType#ENUM_DECL}</td></tr>
|
||||||
|
* <tr><td>{@link TypeSymbol}</td><td>{@link SymbolKind#ANNOTATION}</td>
|
||||||
|
* <td>{@link TokenType#JSDOC_TAG}</td></tr>
|
||||||
|
* <tr><td>{@link MethodSymbol}</td><td>any</td>
|
||||||
|
* <td>{@link TokenType#METHOD_DECL}</td></tr>
|
||||||
|
* <tr><td>{@link FieldSymbol}</td><td>static & final</td>
|
||||||
|
* <td>{@link TokenType#STATIC_FINAL_FIELD}</td></tr>
|
||||||
|
* <tr><td>{@link FieldSymbol}</td><td>otherwise</td>
|
||||||
|
* <td>{@link TokenType#GLOBAL_FIELD}</td></tr>
|
||||||
|
* <tr><td>{@link ImportSymbol}</td><td>always</td>
|
||||||
|
* <td>{@link TokenType#IMPORTED_CLASS}</td></tr>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* <h3>Thread safety</h3>
|
||||||
|
* <p>This class is stateless — all state lives in the method parameters.
|
||||||
|
* It is safe to call {@link #build(SemanticModel, DocumentSyntax)} from any
|
||||||
|
* thread, provided the model and syntax are not being concurrently mutated.</p>
|
||||||
|
*
|
||||||
|
* @see Mark#semantic(int, int, TokenType, Object)
|
||||||
|
* @see SemanticModel
|
||||||
|
* @see SymbolTable
|
||||||
|
*/
|
||||||
|
public final class SemanticMarkBuilder {
|
||||||
|
|
||||||
|
// ── CST node type constants (mirror SemanticModel's constants) ──────────
|
||||||
|
|
||||||
|
private static final String NODE_IMPORT_DECLARATION = "import_declaration";
|
||||||
|
private static final String NODE_CLASS_DECLARATION = "class_declaration";
|
||||||
|
private static final String NODE_INTERFACE_DECLARATION = "interface_declaration";
|
||||||
|
private static final String NODE_ENUM_DECLARATION = "enum_declaration";
|
||||||
|
private static final String NODE_ANNOTATION_TYPE_DECLARATION = "annotation_type_declaration";
|
||||||
|
private static final String NODE_METHOD_DECLARATION = "method_declaration";
|
||||||
|
private static final String NODE_CONSTRUCTOR_DECLARATION = "constructor_declaration";
|
||||||
|
private static final String NODE_FIELD_DECLARATION = "field_declaration";
|
||||||
|
private static final String NODE_VARIABLE_DECLARATOR = "variable_declarator";
|
||||||
|
private static final String NODE_SCOPED_IDENTIFIER = "scoped_identifier";
|
||||||
|
private static final String NODE_IDENTIFIER = "identifier";
|
||||||
|
|
||||||
|
private static final String FIELD_NAME = "name";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All CST node types that represent type declarations.
|
||||||
|
*/
|
||||||
|
private static final Set<String> TYPE_DECLARATION_TYPES;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Set<String> types = new HashSet<String>();
|
||||||
|
types.add(NODE_CLASS_DECLARATION);
|
||||||
|
types.add(NODE_INTERFACE_DECLARATION);
|
||||||
|
types.add(NODE_ENUM_DECLARATION);
|
||||||
|
types.add(NODE_ANNOTATION_TYPE_DECLARATION);
|
||||||
|
TYPE_DECLARATION_TYPES = Collections.unmodifiableSet(types);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SemanticMarkBuilder() {
|
||||||
|
// Utility class — no instances
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Public API
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates semantic marks from the given model and syntax tree.
|
||||||
|
*
|
||||||
|
* <p>Walks all declaration nodes in the CST, looks up the corresponding
|
||||||
|
* {@link Symbol} in the {@link SymbolTable}, and creates a
|
||||||
|
* {@link Mark#semantic(int, int, TokenType, Object)} for each declaration's
|
||||||
|
* <em>name</em> node. Only the name identifier is highlighted — keywords,
|
||||||
|
* modifiers, and body content are left to tree-sitter's syntax marks.</p>
|
||||||
|
*
|
||||||
|
* <p>The returned list is unsorted. Callers (typically {@code MarkLayer})
|
||||||
|
* should sort the marks before merging them with syntax marks.</p>
|
||||||
|
*
|
||||||
|
* @param model the populated semantic model (may be {@code null})
|
||||||
|
* @param syntax the document syntax produced by the parser (may be {@code null})
|
||||||
|
* @return a mutable list of semantic marks, never {@code null}; empty if the
|
||||||
|
* model is not built or either argument is {@code null}
|
||||||
|
*/
|
||||||
|
public static List<Mark> build(SemanticModel model, DocumentSyntax syntax) {
|
||||||
|
if (model == null || syntax == null || !model.isBuilt()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
SymbolTable table = model.getSymbolTable();
|
||||||
|
if (table.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
SemanticNode root = syntax.root();
|
||||||
|
if (root == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Mark> marks = new ArrayList<Mark>();
|
||||||
|
walkDeclarations(root, table, marks);
|
||||||
|
return marks;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// CST walking
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively walks the CST, visiting declaration nodes and creating marks
|
||||||
|
* for each declaration's name identifier.
|
||||||
|
*
|
||||||
|
* @param node the current CST node
|
||||||
|
* @param table the symbol table to look up symbols
|
||||||
|
* @param marks the output list to append marks to
|
||||||
|
*/
|
||||||
|
private static void walkDeclarations(SemanticNode node, SymbolTable table, List<Mark> marks) {
|
||||||
|
List<SemanticNode> children = node.namedChildren();
|
||||||
|
for (SemanticNode child : children) {
|
||||||
|
String nodeType = child.nodeType();
|
||||||
|
if (nodeType == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TYPE_DECLARATION_TYPES.contains(nodeType)) {
|
||||||
|
processTypeDeclaration(child, nodeType, table, marks);
|
||||||
|
} else if (NODE_METHOD_DECLARATION.equals(nodeType)
|
||||||
|
|| NODE_CONSTRUCTOR_DECLARATION.equals(nodeType)) {
|
||||||
|
processMethodDeclaration(child, table, marks);
|
||||||
|
} else if (NODE_FIELD_DECLARATION.equals(nodeType)) {
|
||||||
|
processFieldDeclaration(child, table, marks);
|
||||||
|
} else if (NODE_IMPORT_DECLARATION.equals(nodeType)) {
|
||||||
|
processImportDeclaration(child, table, marks);
|
||||||
|
} else {
|
||||||
|
// Recurse into non-declaration nodes (e.g., class_body, block)
|
||||||
|
// to find nested declarations.
|
||||||
|
walkDeclarations(child, table, marks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Declaration processors
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a type declaration (class, interface, enum, annotation).
|
||||||
|
* Creates a mark for the type's name identifier and recurses into the body
|
||||||
|
* for nested declarations.
|
||||||
|
*
|
||||||
|
* @param typeNode the CST node for the type declaration
|
||||||
|
* @param nodeType the node type string (e.g., "class_declaration")
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param marks the output list
|
||||||
|
*/
|
||||||
|
private static void processTypeDeclaration(SemanticNode typeNode, String nodeType,
|
||||||
|
SymbolTable table, List<Mark> marks) {
|
||||||
|
SemanticNode nameNode = typeNode.childByFieldName(FIELD_NAME);
|
||||||
|
if (nameNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String simpleName = nameNode.text();
|
||||||
|
if (simpleName == null || simpleName.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSpan nameSpan = nameNode.span();
|
||||||
|
if (nameSpan == null || nameSpan.getByteLength() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up the symbol by simple name to get the exact symbol instance.
|
||||||
|
TypeSymbol symbol = findTypeSymbol(table, simpleName, typeNode.span());
|
||||||
|
TokenType tokenType = mapTypeNodeToTokenType(nodeType);
|
||||||
|
|
||||||
|
marks.add(Mark.semantic(
|
||||||
|
nameSpan.getStartByte(),
|
||||||
|
nameSpan.getEndByte(),
|
||||||
|
tokenType,
|
||||||
|
symbol
|
||||||
|
));
|
||||||
|
|
||||||
|
// Recurse into the body for nested type/method/field declarations.
|
||||||
|
SemanticNode body = typeNode.childByFieldName("body");
|
||||||
|
if (body != null) {
|
||||||
|
walkDeclarations(body, table, marks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a method or constructor declaration. Creates a mark for the
|
||||||
|
* method's name identifier.
|
||||||
|
*
|
||||||
|
* @param methodNode the CST node for the method/constructor declaration
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param marks the output list
|
||||||
|
*/
|
||||||
|
private static void processMethodDeclaration(SemanticNode methodNode,
|
||||||
|
SymbolTable table, List<Mark> marks) {
|
||||||
|
SemanticNode nameNode = methodNode.childByFieldName(FIELD_NAME);
|
||||||
|
if (nameNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String methodName = nameNode.text();
|
||||||
|
if (methodName == null || methodName.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSpan nameSpan = nameNode.span();
|
||||||
|
if (nameSpan == null || nameSpan.getByteLength() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MethodSymbol symbol = findMethodSymbol(table, methodName, methodNode.span());
|
||||||
|
|
||||||
|
marks.add(Mark.semantic(
|
||||||
|
nameSpan.getStartByte(),
|
||||||
|
nameSpan.getEndByte(),
|
||||||
|
TokenType.METHOD_DECL,
|
||||||
|
symbol
|
||||||
|
));
|
||||||
|
|
||||||
|
// Recurse into the method body for local declarations (e.g., anonymous classes).
|
||||||
|
SemanticNode body = methodNode.childByFieldName("body");
|
||||||
|
if (body != null) {
|
||||||
|
walkDeclarations(body, table, marks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a field declaration. Handles multi-declarator fields
|
||||||
|
* (e.g., {@code int x, y, z;}) by extracting each variable declarator's
|
||||||
|
* name and creating a separate mark for each.
|
||||||
|
*
|
||||||
|
* @param fieldNode the CST node for the field declaration
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param marks the output list
|
||||||
|
*/
|
||||||
|
private static void processFieldDeclaration(SemanticNode fieldNode,
|
||||||
|
SymbolTable table, List<Mark> marks) {
|
||||||
|
// Multi-declarator fields: "int x, y, z;"
|
||||||
|
List<SemanticNode> declarators = fieldNode.findAll(NODE_VARIABLE_DECLARATOR);
|
||||||
|
|
||||||
|
if (!declarators.isEmpty()) {
|
||||||
|
for (SemanticNode declarator : declarators) {
|
||||||
|
SemanticNode nameNode = declarator.childByFieldName(FIELD_NAME);
|
||||||
|
if (nameNode == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fieldName = nameNode.text();
|
||||||
|
if (fieldName == null || fieldName.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSpan nameSpan = nameNode.span();
|
||||||
|
if (nameSpan == null || nameSpan.getByteLength() <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldSymbol symbol = findFieldSymbol(table, fieldName, fieldNode.span());
|
||||||
|
TokenType tokenType = mapFieldSymbol(symbol);
|
||||||
|
|
||||||
|
marks.add(Mark.semantic(
|
||||||
|
nameSpan.getStartByte(),
|
||||||
|
nameSpan.getEndByte(),
|
||||||
|
tokenType,
|
||||||
|
symbol
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback: single declarator without variable_declarator wrapper.
|
||||||
|
SemanticNode nameNode = fieldNode.childByFieldName(FIELD_NAME);
|
||||||
|
if (nameNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String fieldName = nameNode.text();
|
||||||
|
if (fieldName == null || fieldName.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSpan nameSpan = nameNode.span();
|
||||||
|
if (nameSpan == null || nameSpan.getByteLength() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FieldSymbol symbol = findFieldSymbol(table, fieldName, fieldNode.span());
|
||||||
|
TokenType tokenType = mapFieldSymbol(symbol);
|
||||||
|
|
||||||
|
marks.add(Mark.semantic(
|
||||||
|
nameSpan.getStartByte(),
|
||||||
|
nameSpan.getEndByte(),
|
||||||
|
tokenType,
|
||||||
|
symbol
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes an import declaration. Extracts the last identifier segment
|
||||||
|
* (the simple class name) from the import path and creates a mark for it.
|
||||||
|
*
|
||||||
|
* <p>For a scoped identifier like {@code java.util.List}, the mark covers
|
||||||
|
* the entire scoped identifier node, matching how tree-sitter structures
|
||||||
|
* the import path. For wildcard imports ({@code java.util.*}), the entire
|
||||||
|
* scoped path is marked.</p>
|
||||||
|
*
|
||||||
|
* @param importNode the CST node for the import declaration
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param marks the output list
|
||||||
|
*/
|
||||||
|
private static void processImportDeclaration(SemanticNode importNode,
|
||||||
|
SymbolTable table, List<Mark> marks) {
|
||||||
|
// Find the scoped_identifier or identifier child — this is the import path.
|
||||||
|
SemanticNode pathNode = findImportPathNode(importNode);
|
||||||
|
if (pathNode == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextSpan pathSpan = pathNode.span();
|
||||||
|
if (pathSpan == null || pathSpan.getByteLength() <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look up the import symbol by matching the full import range.
|
||||||
|
ImportSymbol symbol = findImportSymbol(table, importNode.span());
|
||||||
|
|
||||||
|
marks.add(Mark.semantic(
|
||||||
|
pathSpan.getStartByte(),
|
||||||
|
pathSpan.getEndByte(),
|
||||||
|
TokenType.IMPORTED_CLASS,
|
||||||
|
symbol
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Symbol lookup helpers
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link TypeSymbol} in the table matching the given name and
|
||||||
|
* whose declaration range overlaps the given CST node span.
|
||||||
|
*
|
||||||
|
* <p>If multiple types share the same simple name (e.g., nested classes),
|
||||||
|
* the one whose range contains the declaration node's range wins.</p>
|
||||||
|
*
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param simpleName the type's simple name
|
||||||
|
* @param declSpan the full declaration span from the CST node
|
||||||
|
* @return the matching symbol, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
private static TypeSymbol findTypeSymbol(SymbolTable table, String simpleName,
|
||||||
|
TextSpan declSpan) {
|
||||||
|
List<TypeSymbol> candidates = table.getTypesBySimpleName(simpleName);
|
||||||
|
if (candidates.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (candidates.size() == 1) {
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
// Disambiguate by declaration range overlap.
|
||||||
|
if (declSpan != null) {
|
||||||
|
for (TypeSymbol ts : candidates) {
|
||||||
|
if (spansOverlap(ts.range(), declSpan)) {
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link MethodSymbol} in the table matching the given name and
|
||||||
|
* whose declaration range overlaps the given CST node span.
|
||||||
|
*
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param methodName the method name
|
||||||
|
* @param declSpan the full declaration span from the CST node
|
||||||
|
* @return the matching symbol, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
private static MethodSymbol findMethodSymbol(SymbolTable table, String methodName,
|
||||||
|
TextSpan declSpan) {
|
||||||
|
List<MethodSymbol> candidates = table.getMethodsByName(methodName);
|
||||||
|
if (candidates.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (candidates.size() == 1) {
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
if (declSpan != null) {
|
||||||
|
for (MethodSymbol ms : candidates) {
|
||||||
|
if (spansOverlap(ms.range(), declSpan)) {
|
||||||
|
return ms;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link FieldSymbol} in the table matching the given name and
|
||||||
|
* whose declaration range overlaps the given CST node span.
|
||||||
|
*
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param fieldName the field name
|
||||||
|
* @param declSpan the field declaration span from the CST node
|
||||||
|
* @return the matching symbol, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
private static FieldSymbol findFieldSymbol(SymbolTable table, String fieldName,
|
||||||
|
TextSpan declSpan) {
|
||||||
|
List<FieldSymbol> candidates = table.getFieldsByName(fieldName);
|
||||||
|
if (candidates.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (candidates.size() == 1) {
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
if (declSpan != null) {
|
||||||
|
for (FieldSymbol fs : candidates) {
|
||||||
|
if (spansOverlap(fs.range(), declSpan)) {
|
||||||
|
return fs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link ImportSymbol} in the table whose declaration range
|
||||||
|
* overlaps the given import node span.
|
||||||
|
*
|
||||||
|
* @param table the symbol table
|
||||||
|
* @param declSpan the import declaration span from the CST node
|
||||||
|
* @return the matching symbol, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
private static ImportSymbol findImportSymbol(SymbolTable table, TextSpan declSpan) {
|
||||||
|
List<ImportSymbol> allImports = table.getAllImports();
|
||||||
|
if (allImports.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (declSpan == null) {
|
||||||
|
return allImports.get(0);
|
||||||
|
}
|
||||||
|
for (ImportSymbol is : allImports) {
|
||||||
|
if (spansOverlap(is.range(), declSpan)) {
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// TokenType mapping
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps a tree-sitter type declaration node type to the corresponding
|
||||||
|
* {@link TokenType} for rendering.
|
||||||
|
*
|
||||||
|
* @param nodeType the CST node type (e.g., "class_declaration")
|
||||||
|
* @return the token type for coloring
|
||||||
|
*/
|
||||||
|
private static TokenType mapTypeNodeToTokenType(String nodeType) {
|
||||||
|
if (NODE_INTERFACE_DECLARATION.equals(nodeType)) {
|
||||||
|
return TokenType.INTERFACE_DECL;
|
||||||
|
}
|
||||||
|
if (NODE_ENUM_DECLARATION.equals(nodeType)) {
|
||||||
|
return TokenType.ENUM_DECL;
|
||||||
|
}
|
||||||
|
if (NODE_ANNOTATION_TYPE_DECLARATION.equals(nodeType)) {
|
||||||
|
return TokenType.JSDOC_TAG;
|
||||||
|
}
|
||||||
|
// NODE_CLASS_DECLARATION and fallback
|
||||||
|
return TokenType.CLASS_DECL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps a {@link FieldSymbol}'s modifiers to the appropriate {@link TokenType}.
|
||||||
|
*
|
||||||
|
* <p>Static final fields get {@link TokenType#STATIC_FINAL_FIELD} (magenta,
|
||||||
|
* bold+italic), matching IntelliJ's convention for constants. All other
|
||||||
|
* fields get {@link TokenType#GLOBAL_FIELD} (aqua).</p>
|
||||||
|
*
|
||||||
|
* @param symbol the field symbol (may be {@code null} if the symbol table
|
||||||
|
* lookup failed)
|
||||||
|
* @return the token type for coloring
|
||||||
|
*/
|
||||||
|
private static TokenType mapFieldSymbol(FieldSymbol symbol) {
|
||||||
|
if (symbol != null && symbol.isStatic() && symbol.isFinal()) {
|
||||||
|
return TokenType.STATIC_FINAL_FIELD;
|
||||||
|
}
|
||||||
|
return TokenType.GLOBAL_FIELD;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
// Utility
|
||||||
|
// ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the import path node (scoped_identifier or identifier) within
|
||||||
|
* an import_declaration CST node.
|
||||||
|
*
|
||||||
|
* @param importNode the import declaration node
|
||||||
|
* @return the path node, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
private static SemanticNode findImportPathNode(SemanticNode importNode) {
|
||||||
|
List<SemanticNode> children = importNode.namedChildren();
|
||||||
|
for (SemanticNode child : children) {
|
||||||
|
String type = child.nodeType();
|
||||||
|
if (NODE_SCOPED_IDENTIFIER.equals(type) || NODE_IDENTIFIER.equals(type)) {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether two {@link TextSpan}s overlap.
|
||||||
|
*
|
||||||
|
* @param a the first span (may be {@code null})
|
||||||
|
* @param b the second span (may be {@code null})
|
||||||
|
* @return {@code true} if both spans are non-null and overlap
|
||||||
|
*/
|
||||||
|
private static boolean spansOverlap(TextSpan a, TextSpan b) {
|
||||||
|
if (a == null || b == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return a.getStartByte() < b.getEndByte() && b.getStartByte() < a.getEndByte();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
package bigguy.texteditor.diagnostics;
|
||||||
|
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An immutable diagnostic (error, warning, info, or hint) anchored to a range
|
||||||
|
* in the source document. Replaces the legacy {@code DocumentError} class and
|
||||||
|
* the misused {@code AssignmentInfo}-as-error pattern.
|
||||||
|
*
|
||||||
|
* <p>Severity levels and source categories follow the Language Server Protocol
|
||||||
|
* specification to ease future LSP integration.</p>
|
||||||
|
*/
|
||||||
|
public final class Diagnostic {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Diagnostic severity, following the LSP {@code DiagnosticSeverity} enumeration.
|
||||||
|
*/
|
||||||
|
public enum Severity {
|
||||||
|
/** A problem that prevents compilation or execution. */
|
||||||
|
ERROR(1),
|
||||||
|
/** A potential issue that does not prevent compilation. */
|
||||||
|
WARNING(2),
|
||||||
|
/** Informational message (e.g. deprecation notice). */
|
||||||
|
INFO(3),
|
||||||
|
/** Subtle suggestion (e.g. unused import). */
|
||||||
|
HINT(4);
|
||||||
|
|
||||||
|
private final int lspValue;
|
||||||
|
|
||||||
|
Severity(int lspValue) {
|
||||||
|
this.lspValue = lspValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the numeric value matching the LSP specification.
|
||||||
|
*
|
||||||
|
* @return the LSP {@code DiagnosticSeverity} integer (1–4)
|
||||||
|
*/
|
||||||
|
public int lspValue() {
|
||||||
|
return lspValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifies which analysis phase produced the diagnostic, enabling
|
||||||
|
* targeted invalidation when only part of the pipeline reruns.
|
||||||
|
*/
|
||||||
|
public enum Source {
|
||||||
|
/** Syntax errors from the tree-sitter parser. */
|
||||||
|
PARSER,
|
||||||
|
/** Declaration-level issues (duplicate names, missing types). */
|
||||||
|
DECLARATION,
|
||||||
|
/** Type-checking errors (incompatible assignment, wrong argument type). */
|
||||||
|
TYPE_CHECK,
|
||||||
|
/** Import resolution issues (unresolved import, wildcard ambiguity). */
|
||||||
|
IMPORT,
|
||||||
|
/** Higher-level semantic checks (unreachable code, unused variable). */
|
||||||
|
SEMANTIC
|
||||||
|
}
|
||||||
|
|
||||||
|
private final TextSpan range;
|
||||||
|
private final Severity severity;
|
||||||
|
private final String message;
|
||||||
|
private final Source source;
|
||||||
|
private final String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param range the source range this diagnostic applies to
|
||||||
|
* @param severity the severity level
|
||||||
|
* @param message a human-readable description of the issue
|
||||||
|
* @param source the analysis phase that produced this diagnostic
|
||||||
|
* @param code an optional machine-readable error code (may be {@code null})
|
||||||
|
*/
|
||||||
|
public Diagnostic(TextSpan range, Severity severity, String message, Source source, String code) {
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
this.severity = Objects.requireNonNull(severity, "severity");
|
||||||
|
this.message = Objects.requireNonNull(message, "message");
|
||||||
|
this.source = Objects.requireNonNull(source, "source");
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience factory for diagnostics without an error code.
|
||||||
|
*
|
||||||
|
* @param range the source range
|
||||||
|
* @param severity the severity level
|
||||||
|
* @param message a human-readable description
|
||||||
|
* @param source the originating analysis phase
|
||||||
|
* @return a new diagnostic with a {@code null} error code
|
||||||
|
*/
|
||||||
|
public static Diagnostic of(TextSpan range, Severity severity, String message, Source source) {
|
||||||
|
return new Diagnostic(range, severity, message, source, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the source range this diagnostic applies to */
|
||||||
|
public TextSpan range() { return range; }
|
||||||
|
|
||||||
|
/** @return the severity level */
|
||||||
|
public Severity severity() { return severity; }
|
||||||
|
|
||||||
|
/** @return a human-readable description of the issue */
|
||||||
|
public String message() { return message; }
|
||||||
|
|
||||||
|
/** @return the analysis phase that produced this diagnostic */
|
||||||
|
public Source source() { return source; }
|
||||||
|
|
||||||
|
/** @return an optional machine-readable error code, or {@code null} */
|
||||||
|
public String code() { return code; }
|
||||||
|
|
||||||
|
/** @return {@code true} if this diagnostic represents a compilation error */
|
||||||
|
public boolean isError() {
|
||||||
|
return severity == Severity.ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return {@code true} if this diagnostic represents a warning */
|
||||||
|
public boolean isWarning() {
|
||||||
|
return severity == Severity.WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof Diagnostic)) return false;
|
||||||
|
Diagnostic that = (Diagnostic) obj;
|
||||||
|
return range.equals(that.range)
|
||||||
|
&& severity == that.severity
|
||||||
|
&& message.equals(that.message)
|
||||||
|
&& source == that.source
|
||||||
|
&& Objects.equals(code, that.code);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = range.hashCode();
|
||||||
|
result = 31 * result + severity.hashCode();
|
||||||
|
result = 31 * result + message.hashCode();
|
||||||
|
result = 31 * result + source.hashCode();
|
||||||
|
result = 31 * result + (code != null ? code.hashCode() : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String loc = range.getStartRow() + ":" + range.getStartColumn();
|
||||||
|
String codeStr = code != null ? " [" + code + "]" : "";
|
||||||
|
return severity.name().toLowerCase() + "(" + loc + "): " + message + codeStr
|
||||||
|
+ " (" + source.name().toLowerCase() + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package bigguy.texteditor.diagnostics;
|
||||||
|
|
||||||
|
import bigguy.texteditor.diagnostics.Diagnostic.Severity;
|
||||||
|
import bigguy.texteditor.diagnostics.Diagnostic.Source;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread-safe, centralized storage for diagnostics with query capabilities.
|
||||||
|
*
|
||||||
|
* <p>Diagnostics are added from background analysis threads and read from the
|
||||||
|
* UI thread. All mutation operations increment the internal {@link #version()},
|
||||||
|
* allowing consumers to detect changes cheaply via version comparison.</p>
|
||||||
|
*
|
||||||
|
* <p>All query methods return unmodifiable snapshots — callers never see
|
||||||
|
* the internal mutable list.</p>
|
||||||
|
*/
|
||||||
|
public final class DiagnosticStore {
|
||||||
|
|
||||||
|
private final CopyOnWriteArrayList<Diagnostic> diagnostics = new CopyOnWriteArrayList<>();
|
||||||
|
private final AtomicInteger version = new AtomicInteger(0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a diagnostic to the store.
|
||||||
|
*
|
||||||
|
* @param diagnostic the diagnostic to add
|
||||||
|
* @throws NullPointerException if {@code diagnostic} is null
|
||||||
|
*/
|
||||||
|
public void addDiagnostic(Diagnostic diagnostic) {
|
||||||
|
if (diagnostic == null) {
|
||||||
|
throw new NullPointerException("diagnostic must not be null");
|
||||||
|
}
|
||||||
|
diagnostics.add(diagnostic);
|
||||||
|
version.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all diagnostics whose range overlaps the given byte interval.
|
||||||
|
* Useful for rendering underlines on visible lines.
|
||||||
|
*
|
||||||
|
* @param startByte inclusive start of the query interval
|
||||||
|
* @param endByte exclusive end of the query interval
|
||||||
|
* @return an unmodifiable list of matching diagnostics
|
||||||
|
*/
|
||||||
|
public List<Diagnostic> getDiagnosticsInRange(int startByte, int endByte) {
|
||||||
|
List<Diagnostic> result = new ArrayList<>();
|
||||||
|
for (Diagnostic d : diagnostics) {
|
||||||
|
if (d.range().getStartByte() < endByte && startByte < d.range().getEndByte()) {
|
||||||
|
result.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all diagnostics produced by the given analysis phase.
|
||||||
|
*
|
||||||
|
* @param source the originating analysis phase
|
||||||
|
* @return an unmodifiable list of matching diagnostics
|
||||||
|
*/
|
||||||
|
public List<Diagnostic> getDiagnosticsBySource(Source source) {
|
||||||
|
List<Diagnostic> result = new ArrayList<>();
|
||||||
|
for (Diagnostic d : diagnostics) {
|
||||||
|
if (d.source() == source) {
|
||||||
|
result.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all diagnostics with the given severity level.
|
||||||
|
*
|
||||||
|
* @param severity the severity to filter by
|
||||||
|
* @return an unmodifiable list of matching diagnostics
|
||||||
|
*/
|
||||||
|
public List<Diagnostic> getDiagnosticsBySeverity(Severity severity) {
|
||||||
|
List<Diagnostic> result = new ArrayList<>();
|
||||||
|
for (Diagnostic d : diagnostics) {
|
||||||
|
if (d.severity() == severity) {
|
||||||
|
result.add(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an unmodifiable snapshot of all diagnostics.
|
||||||
|
*
|
||||||
|
* @return all stored diagnostics
|
||||||
|
*/
|
||||||
|
public List<Diagnostic> getAll() {
|
||||||
|
return Collections.unmodifiableList(new ArrayList<>(diagnostics));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes all diagnostics from the store. */
|
||||||
|
public void clear() {
|
||||||
|
if (!diagnostics.isEmpty()) {
|
||||||
|
diagnostics.clear();
|
||||||
|
version.incrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all diagnostics produced by the given analysis phase.
|
||||||
|
* Useful for incremental invalidation when only one phase reruns.
|
||||||
|
*
|
||||||
|
* @param source the analysis phase whose diagnostics should be removed
|
||||||
|
*/
|
||||||
|
public void clearBySource(Source source) {
|
||||||
|
boolean removed = diagnostics.removeIf(d -> d.source() == source);
|
||||||
|
if (removed) {
|
||||||
|
version.incrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the number of diagnostics with {@link Severity#ERROR} */
|
||||||
|
public int errorCount() {
|
||||||
|
int count = 0;
|
||||||
|
for (Diagnostic d : diagnostics) {
|
||||||
|
if (d.isError()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the number of diagnostics with {@link Severity#WARNING} */
|
||||||
|
public int warningCount() {
|
||||||
|
int count = 0;
|
||||||
|
for (Diagnostic d : diagnostics) {
|
||||||
|
if (d.isWarning()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the total number of stored diagnostics */
|
||||||
|
public int size() {
|
||||||
|
return diagnostics.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return {@code true} if no diagnostics are stored */
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return diagnostics.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a monotonically increasing version number that increments
|
||||||
|
* on every mutation. Consumers can compare versions to detect changes
|
||||||
|
* without re-scanning the full list.
|
||||||
|
*
|
||||||
|
* @return the current version
|
||||||
|
*/
|
||||||
|
public int version() {
|
||||||
|
return version.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DiagnosticStore{size=" + diagnostics.size()
|
||||||
|
+ ", errors=" + errorCount()
|
||||||
|
+ ", warnings=" + warningCount()
|
||||||
|
+ ", version=" + version.get() + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
package bigguy.texteditor.index;
|
||||||
|
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hierarchy representing all symbol types in the document.
|
||||||
|
* Each variant carries type-specific metadata.
|
||||||
|
*
|
||||||
|
* <p>Follows IntelliJ's {@code PsiElement} specialization pattern: a common
|
||||||
|
* interface with concrete final implementations for each symbol category.</p>
|
||||||
|
*/
|
||||||
|
public interface Symbol {
|
||||||
|
|
||||||
|
/** @return the unique key identifying this symbol */
|
||||||
|
SymbolKey key();
|
||||||
|
|
||||||
|
/** @return the source range of the symbol's declaration */
|
||||||
|
TextSpan range();
|
||||||
|
|
||||||
|
/** @return the symbol's simple name */
|
||||||
|
String name();
|
||||||
|
|
||||||
|
/** @return the classification of this symbol */
|
||||||
|
SymbolKind kind();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A type declaration (class, interface, enum, annotation).
|
||||||
|
*/
|
||||||
|
final class TypeSymbol implements Symbol {
|
||||||
|
|
||||||
|
private final SymbolKey key;
|
||||||
|
private final TextSpan range;
|
||||||
|
private final String simpleName;
|
||||||
|
private final String fullName;
|
||||||
|
private final String dotName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the unique key for this symbol
|
||||||
|
* @param range the declaration's source range
|
||||||
|
* @param simpleName the unqualified type name
|
||||||
|
* @param fullName the fully qualified name (e.g. "java.util.List")
|
||||||
|
* @param dotName the dot-path from enclosing scope (e.g. "Outer.Inner")
|
||||||
|
*/
|
||||||
|
public TypeSymbol(SymbolKey key, TextSpan range, String simpleName,
|
||||||
|
String fullName, String dotName) {
|
||||||
|
this.key = Objects.requireNonNull(key, "key");
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
this.simpleName = Objects.requireNonNull(simpleName, "simpleName");
|
||||||
|
this.fullName = Objects.requireNonNull(fullName, "fullName");
|
||||||
|
this.dotName = Objects.requireNonNull(dotName, "dotName");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public SymbolKey key() { return key; }
|
||||||
|
@Override public TextSpan range() { return range; }
|
||||||
|
@Override public String name() { return simpleName; }
|
||||||
|
@Override public SymbolKind kind() { return key.kind(); }
|
||||||
|
|
||||||
|
/** @return the fully qualified name (e.g. "java.util.List") */
|
||||||
|
public String fullName() { return fullName; }
|
||||||
|
|
||||||
|
/** @return the dot-path from enclosing scope (e.g. "Outer.Inner") */
|
||||||
|
public String dotName() { return dotName; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof TypeSymbol)) return false;
|
||||||
|
TypeSymbol that = (TypeSymbol) obj;
|
||||||
|
return key.equals(that.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return key.hashCode(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return kind().displayName() + " " + fullName + " at " + range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A method or constructor declaration.
|
||||||
|
*/
|
||||||
|
final class MethodSymbol implements Symbol {
|
||||||
|
|
||||||
|
private final SymbolKey key;
|
||||||
|
private final TextSpan range;
|
||||||
|
private final String name;
|
||||||
|
private final TextSpan bodyRange;
|
||||||
|
private final List<String> parameterNames;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the unique key for this symbol
|
||||||
|
* @param range the declaration's source range (including signature)
|
||||||
|
* @param name the method name (or {@code "<init>"} for constructors)
|
||||||
|
* @param bodyRange the range of the method body (may be {@code null} for abstract methods)
|
||||||
|
* @param parameterNames the ordered list of parameter names
|
||||||
|
*/
|
||||||
|
public MethodSymbol(SymbolKey key, TextSpan range, String name,
|
||||||
|
TextSpan bodyRange, List<String> parameterNames) {
|
||||||
|
this.key = Objects.requireNonNull(key, "key");
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
this.name = Objects.requireNonNull(name, "name");
|
||||||
|
this.bodyRange = bodyRange;
|
||||||
|
this.parameterNames = Collections.unmodifiableList(
|
||||||
|
new java.util.ArrayList<>(Objects.requireNonNull(parameterNames, "parameterNames")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public SymbolKey key() { return key; }
|
||||||
|
@Override public TextSpan range() { return range; }
|
||||||
|
@Override public String name() { return name; }
|
||||||
|
@Override public SymbolKind kind() { return key.kind(); }
|
||||||
|
|
||||||
|
/** @return the range of the method body, or {@code null} for abstract methods */
|
||||||
|
public TextSpan bodyRange() { return bodyRange; }
|
||||||
|
|
||||||
|
/** @return an unmodifiable list of parameter names in declaration order */
|
||||||
|
public List<String> parameterNames() { return parameterNames; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof MethodSymbol)) return false;
|
||||||
|
MethodSymbol that = (MethodSymbol) obj;
|
||||||
|
return key.equals(that.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return key.hashCode(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return kind().displayName() + " " + name + "(" + String.join(", ", parameterNames) + ") at " + range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A field, parameter, local variable, or enum constant declaration.
|
||||||
|
*/
|
||||||
|
final class FieldSymbol implements Symbol {
|
||||||
|
|
||||||
|
private final SymbolKey key;
|
||||||
|
private final TextSpan range;
|
||||||
|
private final String name;
|
||||||
|
private final String typeName;
|
||||||
|
private final boolean isStatic;
|
||||||
|
private final boolean isFinal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the unique key for this symbol
|
||||||
|
* @param range the declaration's source range
|
||||||
|
* @param name the field name
|
||||||
|
* @param typeName the declared type name (may be {@code null} if unresolved)
|
||||||
|
* @param isStatic whether the field is static
|
||||||
|
* @param isFinal whether the field is final
|
||||||
|
*/
|
||||||
|
public FieldSymbol(SymbolKey key, TextSpan range, String name,
|
||||||
|
String typeName, boolean isStatic, boolean isFinal) {
|
||||||
|
this.key = Objects.requireNonNull(key, "key");
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
this.name = Objects.requireNonNull(name, "name");
|
||||||
|
this.typeName = typeName;
|
||||||
|
this.isStatic = isStatic;
|
||||||
|
this.isFinal = isFinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public SymbolKey key() { return key; }
|
||||||
|
@Override public TextSpan range() { return range; }
|
||||||
|
@Override public String name() { return name; }
|
||||||
|
@Override public SymbolKind kind() { return key.kind(); }
|
||||||
|
|
||||||
|
/** @return the declared type name, or {@code null} if unresolved */
|
||||||
|
public String typeName() { return typeName; }
|
||||||
|
|
||||||
|
/** @return whether the field is static */
|
||||||
|
public boolean isStatic() { return isStatic; }
|
||||||
|
|
||||||
|
/** @return whether the field is final */
|
||||||
|
public boolean isFinal() { return isFinal; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof FieldSymbol)) return false;
|
||||||
|
FieldSymbol that = (FieldSymbol) obj;
|
||||||
|
return key.equals(that.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return key.hashCode(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String modifiers = (isStatic ? "static " : "") + (isFinal ? "final " : "");
|
||||||
|
return kind().displayName() + " " + modifiers
|
||||||
|
+ (typeName != null ? typeName + " " : "") + name + " at " + range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An import declaration.
|
||||||
|
*/
|
||||||
|
final class ImportSymbol implements Symbol {
|
||||||
|
|
||||||
|
private final SymbolKey key;
|
||||||
|
private final TextSpan range;
|
||||||
|
private final String name;
|
||||||
|
private final String fullPath;
|
||||||
|
private final boolean isWildcard;
|
||||||
|
private final boolean isStatic;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key the unique key for this symbol
|
||||||
|
* @param range the import statement's source range
|
||||||
|
* @param name the simple name (last segment of the import path)
|
||||||
|
* @param fullPath the full import path (e.g. "java.util.List")
|
||||||
|
* @param isWildcard whether this is a wildcard import (e.g. "java.util.*")
|
||||||
|
* @param isStatic whether this is a static import
|
||||||
|
*/
|
||||||
|
public ImportSymbol(SymbolKey key, TextSpan range, String name,
|
||||||
|
String fullPath, boolean isWildcard, boolean isStatic) {
|
||||||
|
this.key = Objects.requireNonNull(key, "key");
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
this.name = Objects.requireNonNull(name, "name");
|
||||||
|
this.fullPath = Objects.requireNonNull(fullPath, "fullPath");
|
||||||
|
this.isWildcard = isWildcard;
|
||||||
|
this.isStatic = isStatic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public SymbolKey key() { return key; }
|
||||||
|
@Override public TextSpan range() { return range; }
|
||||||
|
@Override public String name() { return name; }
|
||||||
|
@Override public SymbolKind kind() { return key.kind(); }
|
||||||
|
|
||||||
|
/** @return the full import path (e.g. "java.util.List") */
|
||||||
|
public String fullPath() { return fullPath; }
|
||||||
|
|
||||||
|
/** @return whether this is a wildcard import (e.g. "java.util.*") */
|
||||||
|
public boolean isWildcard() { return isWildcard; }
|
||||||
|
|
||||||
|
/** @return whether this is a static import */
|
||||||
|
public boolean isStatic() { return isStatic; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof ImportSymbol)) return false;
|
||||||
|
ImportSymbol that = (ImportSymbol) obj;
|
||||||
|
return key.equals(that.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() { return key.hashCode(); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String prefix = isStatic ? "static import " : "import ";
|
||||||
|
return prefix + fullPath + (isWildcard ? ".*" : "") + " at " + range;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package bigguy.texteditor.index;
|
||||||
|
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uniquely identifies a symbol within the document by name, kind, and range.
|
||||||
|
* Replaces magic integer offset keys used in the legacy ScriptDocument.
|
||||||
|
*
|
||||||
|
* <p>Two keys are equal if and only if they share the same name, kind, and range.
|
||||||
|
* This guarantees uniqueness even for overloaded methods or shadowed variables
|
||||||
|
* at different scopes.</p>
|
||||||
|
*/
|
||||||
|
public final class SymbolKey {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final SymbolKind kind;
|
||||||
|
private final TextSpan range;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name the symbol's simple name
|
||||||
|
* @param kind the classification of the symbol
|
||||||
|
* @param range the source range of the symbol's declaration
|
||||||
|
*/
|
||||||
|
public SymbolKey(String name, SymbolKind kind, TextSpan range) {
|
||||||
|
this.name = Objects.requireNonNull(name, "name");
|
||||||
|
this.kind = Objects.requireNonNull(kind, "kind");
|
||||||
|
this.range = Objects.requireNonNull(range, "range");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the symbol's simple name */
|
||||||
|
public String name() { return name; }
|
||||||
|
|
||||||
|
/** @return the classification of the symbol */
|
||||||
|
public SymbolKind kind() { return kind; }
|
||||||
|
|
||||||
|
/** @return the source range of the symbol's declaration */
|
||||||
|
public TextSpan range() { return range; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a dot-qualified name for nested type display (e.g. "Outer.Inner").
|
||||||
|
* For non-nested symbols this returns the simple name.
|
||||||
|
*
|
||||||
|
* @return the qualified name
|
||||||
|
*/
|
||||||
|
public String qualifiedName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof SymbolKey)) return false;
|
||||||
|
SymbolKey that = (SymbolKey) obj;
|
||||||
|
return name.equals(that.name) && kind == that.kind && range.equals(that.range);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = name.hashCode();
|
||||||
|
result = 31 * result + kind.hashCode();
|
||||||
|
result = 31 * result + range.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return kind.displayName() + " '" + name + "' at " + range;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package bigguy.texteditor.index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classifies symbols within a source document for indexing, navigation, and
|
||||||
|
* icon display.
|
||||||
|
*
|
||||||
|
* <p>Follows the LSP {@code SymbolKind} enumeration and IntelliJ IDEA's
|
||||||
|
* {@code IElementType} hierarchy, covering the Java language constructs
|
||||||
|
* relevant to the script editor.</p>
|
||||||
|
*/
|
||||||
|
public enum SymbolKind {
|
||||||
|
|
||||||
|
CLASS("Class", true, false, false),
|
||||||
|
INTERFACE("Interface", true, false, false),
|
||||||
|
ENUM("Enum", true, false, false),
|
||||||
|
ANNOTATION("Annotation", true, false, false),
|
||||||
|
METHOD("Method", false, true, false),
|
||||||
|
CONSTRUCTOR("Constructor", false, true, false),
|
||||||
|
FIELD("Field", false, false, true),
|
||||||
|
PARAMETER("Parameter", false, false, true),
|
||||||
|
LOCAL_VARIABLE("Local Variable", false, false, true),
|
||||||
|
IMPORT("Import", false, false, false),
|
||||||
|
PACKAGE("Package", false, false, false),
|
||||||
|
TYPE_PARAMETER("Type Parameter", false, false, false),
|
||||||
|
LAMBDA("Lambda", false, true, false),
|
||||||
|
ENUM_CONSTANT("Enum Constant", false, false, true),
|
||||||
|
STATIC_INITIALIZER("Static Initializer", false, false, false);
|
||||||
|
|
||||||
|
private final String displayName;
|
||||||
|
private final boolean type;
|
||||||
|
private final boolean callable;
|
||||||
|
private final boolean variable;
|
||||||
|
|
||||||
|
SymbolKind(String displayName, boolean type, boolean callable, boolean variable) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
this.type = type;
|
||||||
|
this.callable = callable;
|
||||||
|
this.variable = variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a human-readable name suitable for UI display (e.g. "Local Variable").
|
||||||
|
*
|
||||||
|
* @return the display name
|
||||||
|
*/
|
||||||
|
public String displayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} for type-declaring symbols:
|
||||||
|
* {@link #CLASS}, {@link #INTERFACE}, {@link #ENUM}, {@link #ANNOTATION}.
|
||||||
|
*
|
||||||
|
* @return whether this kind represents a type declaration
|
||||||
|
*/
|
||||||
|
public boolean isType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} for callable symbols:
|
||||||
|
* {@link #METHOD}, {@link #CONSTRUCTOR}, {@link #LAMBDA}.
|
||||||
|
*
|
||||||
|
* @return whether this kind represents something that can be invoked
|
||||||
|
*/
|
||||||
|
public boolean isCallable() {
|
||||||
|
return callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} for variable-like symbols:
|
||||||
|
* {@link #FIELD}, {@link #PARAMETER}, {@link #LOCAL_VARIABLE}, {@link #ENUM_CONSTANT}.
|
||||||
|
*
|
||||||
|
* @return whether this kind represents a named value holder
|
||||||
|
*/
|
||||||
|
public boolean isVariable() {
|
||||||
|
return variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
package bigguy.texteditor.render;
|
||||||
|
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A highlight region produced by the analysis pipeline.
|
||||||
|
* Marks bridge the gap between CST/semantic analysis and token rendering.
|
||||||
|
*
|
||||||
|
* <p>Marks are produced by:
|
||||||
|
* <ul>
|
||||||
|
* <li>Tree-sitter highlight queries (syntax marks)</li>
|
||||||
|
* <li>Semantic analysis (type resolution, scope coloring)</li>
|
||||||
|
* <li>Error detection (diagnostic marks)</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Multiple marks can overlap. {@link MarkLayer} resolves conflicts using
|
||||||
|
* {@link TokenType#getPriority()}.
|
||||||
|
*
|
||||||
|
* <p>Sorting order (used by {@link MarkLayer#merge()}):
|
||||||
|
* <ol>
|
||||||
|
* <li>By start position ascending</li>
|
||||||
|
* <li>By span length descending (longest first)</li>
|
||||||
|
* <li>By priority descending (highest first)</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
public final class Mark implements Comparable<Mark> {
|
||||||
|
|
||||||
|
/** Byte offset where this mark begins (inclusive). */
|
||||||
|
public final int start;
|
||||||
|
|
||||||
|
/** Byte offset where this mark ends (exclusive). */
|
||||||
|
public final int end;
|
||||||
|
|
||||||
|
/** The token type that determines color, priority, and style. */
|
||||||
|
public final TokenType type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional metadata attached by the analysis pipeline.
|
||||||
|
* May be {@link noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo},
|
||||||
|
* {@link noppes.npcs.client.gui.util.script.interpreter.method.MethodCallInfo},
|
||||||
|
* {@link noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo},
|
||||||
|
* {@link noppes.npcs.client.gui.util.script.interpreter.type.ImportData},
|
||||||
|
* {@link noppes.npcs.client.gui.util.script.interpreter.token.TokenErrorMessage},
|
||||||
|
* or any other analysis artifact. Null when no metadata is available.
|
||||||
|
*/
|
||||||
|
public final Object metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a mark with no metadata (pure syntax mark).
|
||||||
|
*
|
||||||
|
* @param start byte offset where this mark begins (inclusive)
|
||||||
|
* @param end byte offset where this mark ends (exclusive)
|
||||||
|
* @param type the token type for coloring and priority
|
||||||
|
*/
|
||||||
|
public Mark(int start, int end, TokenType type) {
|
||||||
|
this(start, end, type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a mark with metadata (semantic or diagnostic mark).
|
||||||
|
*
|
||||||
|
* @param start byte offset where this mark begins (inclusive)
|
||||||
|
* @param end byte offset where this mark ends (exclusive)
|
||||||
|
* @param type the token type for coloring and priority
|
||||||
|
* @param metadata optional analysis metadata, may be null
|
||||||
|
*/
|
||||||
|
public Mark(int start, int end, TokenType type, Object metadata) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
this.type = type;
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== FACTORY METHODS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a syntax-only mark (no metadata).
|
||||||
|
*
|
||||||
|
* @param start byte offset where this mark begins (inclusive)
|
||||||
|
* @param end byte offset where this mark ends (exclusive)
|
||||||
|
* @param type the token type for coloring and priority
|
||||||
|
* @return a new Mark with no metadata
|
||||||
|
*/
|
||||||
|
public static Mark syntax(int start, int end, TokenType type) {
|
||||||
|
return new Mark(start, end, type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a semantic mark with attached metadata.
|
||||||
|
*
|
||||||
|
* @param start byte offset where this mark begins (inclusive)
|
||||||
|
* @param end byte offset where this mark ends (exclusive)
|
||||||
|
* @param type the token type for coloring and priority
|
||||||
|
* @param metadata analysis metadata (TypeInfo, MethodCallInfo, etc.)
|
||||||
|
* @return a new Mark with the given metadata
|
||||||
|
*/
|
||||||
|
public static Mark semantic(int start, int end, TokenType type, Object metadata) {
|
||||||
|
return new Mark(start, end, type, metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== QUERIES ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this mark's range overlaps with the given range.
|
||||||
|
*
|
||||||
|
* @param otherStart start of the other range (inclusive)
|
||||||
|
* @param otherEnd end of the other range (exclusive)
|
||||||
|
* @return true if the ranges overlap
|
||||||
|
*/
|
||||||
|
public boolean overlaps(int otherStart, int otherEnd) {
|
||||||
|
return this.start < otherEnd && this.end > otherStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the length of this mark in bytes.
|
||||||
|
*
|
||||||
|
* @return end - start
|
||||||
|
*/
|
||||||
|
public int length() {
|
||||||
|
return end - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this mark carries metadata.
|
||||||
|
*
|
||||||
|
* @return true if metadata is non-null
|
||||||
|
*/
|
||||||
|
public boolean hasMetadata() {
|
||||||
|
return metadata != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== Comparable ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort marks by start position ascending, then by span length descending
|
||||||
|
* (longest first), then by priority descending (highest first).
|
||||||
|
* This ordering ensures that when two marks start at the same position,
|
||||||
|
* the one covering more text (or with higher priority) is processed first.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int compareTo(Mark other) {
|
||||||
|
// Primary: start position ascending
|
||||||
|
int cmp = Integer.compare(this.start, other.start);
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
|
||||||
|
// Secondary: span length descending (longest first)
|
||||||
|
cmp = Integer.compare(other.length(), this.length());
|
||||||
|
if (cmp != 0) return cmp;
|
||||||
|
|
||||||
|
// Tertiary: priority descending (highest first)
|
||||||
|
return Integer.compare(other.type.getPriority(), this.type.getPriority());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== equals / hashCode ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof Mark)) return false;
|
||||||
|
Mark other = (Mark) obj;
|
||||||
|
return this.start == other.start
|
||||||
|
&& this.end == other.end
|
||||||
|
&& this.type == other.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = start;
|
||||||
|
result = 31 * result + end;
|
||||||
|
result = 31 * result + type.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== toString ====================
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Mark{" + type + " [" + start + "-" + end + "]"
|
||||||
|
+ (metadata != null ? " " + metadata.getClass().getSimpleName() : "")
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
package bigguy.texteditor.render;
|
||||||
|
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges three independent mark sources — syntax, semantic, and error — into
|
||||||
|
* a single non-overlapping list resolved by {@link TokenType#getPriority()}.
|
||||||
|
*
|
||||||
|
* <p>Thread safety: syntax marks are set from the UI thread while semantic marks
|
||||||
|
* arrive from a background analysis thread. All mutators are synchronized;
|
||||||
|
* {@link #merge()} produces a snapshot safe for the caller to iterate without
|
||||||
|
* holding the lock.
|
||||||
|
*
|
||||||
|
* <p>A monotonically increasing {@link #getRevision() revision} counter lets
|
||||||
|
* consumers detect stale merge results cheaply.
|
||||||
|
*/
|
||||||
|
public class MarkLayer {
|
||||||
|
|
||||||
|
private List<Mark> syntaxMarks = Collections.emptyList();
|
||||||
|
private List<Mark> semanticMarks = Collections.emptyList();
|
||||||
|
private List<Mark> errorMarks = Collections.emptyList();
|
||||||
|
private volatile int revision;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the syntax mark layer (produced by tree-sitter highlight queries).
|
||||||
|
*
|
||||||
|
* @param marks new syntax marks; must not be null
|
||||||
|
*/
|
||||||
|
public synchronized void setSyntaxMarks(List<Mark> marks) {
|
||||||
|
this.syntaxMarks = new ArrayList<>(marks);
|
||||||
|
revision++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the semantic mark layer (produced by type resolution / scope analysis).
|
||||||
|
* Typically called from a background thread.
|
||||||
|
*
|
||||||
|
* @param marks new semantic marks; must not be null
|
||||||
|
*/
|
||||||
|
public synchronized void setSemanticMarks(List<Mark> marks) {
|
||||||
|
this.semanticMarks = new ArrayList<>(marks);
|
||||||
|
revision++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace the error mark layer (diagnostic underlines).
|
||||||
|
* Error marks do not participate in color conflict resolution —
|
||||||
|
* they are kept in a separate channel and drawn as underlines.
|
||||||
|
*
|
||||||
|
* @param marks new error marks; must not be null
|
||||||
|
*/
|
||||||
|
public synchronized void setErrorMarks(List<Mark> marks) {
|
||||||
|
this.errorMarks = new ArrayList<>(marks);
|
||||||
|
revision++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the current syntax marks (defensive copy) */
|
||||||
|
public synchronized List<Mark> getSyntaxMarks() {
|
||||||
|
return new ArrayList<>(syntaxMarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the current semantic marks (defensive copy) */
|
||||||
|
public synchronized List<Mark> getSemanticMarks() {
|
||||||
|
return new ArrayList<>(semanticMarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error marks are kept in their own channel and drawn as underlines
|
||||||
|
* rather than merged into the color layer.
|
||||||
|
*
|
||||||
|
* @return the current error marks (defensive copy)
|
||||||
|
*/
|
||||||
|
public synchronized List<Mark> getErrorMarks() {
|
||||||
|
return new ArrayList<>(errorMarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monotonically increasing counter that increments on every mutation.
|
||||||
|
* Compare against a cached value to detect stale merge results.
|
||||||
|
*
|
||||||
|
* @return current revision
|
||||||
|
*/
|
||||||
|
public int getRevision() {
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merge syntax and semantic marks into a single non-overlapping list.
|
||||||
|
* Error marks are NOT included — they live in a separate rendering channel.
|
||||||
|
*
|
||||||
|
* <p>Algorithm:
|
||||||
|
* <ol>
|
||||||
|
* <li>Combine syntax + semantic marks and sort by start position</li>
|
||||||
|
* <li>Walk left-to-right through a "sweep line" over every boundary point</li>
|
||||||
|
* <li>At each boundary, the active mark with the highest
|
||||||
|
* {@link TokenType#getPriority()} wins</li>
|
||||||
|
* <li>Semantic marks override syntax marks for the same range
|
||||||
|
* (semantic priority is typically equal or higher)</li>
|
||||||
|
* <li>Output non-overlapping marks sorted by start position</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @return merged, non-overlapping mark list (safe to iterate without synchronization)
|
||||||
|
*/
|
||||||
|
public List<Mark> merge() {
|
||||||
|
List<Mark> syntax;
|
||||||
|
List<Mark> semantic;
|
||||||
|
synchronized (this) {
|
||||||
|
syntax = new ArrayList<>(syntaxMarks);
|
||||||
|
semantic = new ArrayList<>(semanticMarks);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syntax.isEmpty() && semantic.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build identity set for O(1) semantic membership checks
|
||||||
|
Set<Mark> semanticSet = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||||
|
semanticSet.addAll(semantic);
|
||||||
|
|
||||||
|
// Collect all boundary points
|
||||||
|
List<Integer> boundaries = new ArrayList<>();
|
||||||
|
for (Mark m : syntax) {
|
||||||
|
boundaries.add(m.start);
|
||||||
|
boundaries.add(m.end);
|
||||||
|
}
|
||||||
|
for (Mark m : semantic) {
|
||||||
|
boundaries.add(m.start);
|
||||||
|
boundaries.add(m.end);
|
||||||
|
}
|
||||||
|
Collections.sort(boundaries);
|
||||||
|
// Deduplicate
|
||||||
|
List<Integer> uniqueBoundaries = new ArrayList<>();
|
||||||
|
for (int i = 0; i < boundaries.size(); i++) {
|
||||||
|
if (i == 0 || !boundaries.get(i).equals(boundaries.get(i - 1))) {
|
||||||
|
uniqueBoundaries.add(boundaries.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Mark> combined = new ArrayList<>(syntax.size() + semantic.size());
|
||||||
|
combined.addAll(syntax);
|
||||||
|
combined.addAll(semantic);
|
||||||
|
|
||||||
|
List<Mark> result = new ArrayList<>();
|
||||||
|
|
||||||
|
// For each interval between consecutive boundaries, find the winning mark
|
||||||
|
for (int i = 0; i < uniqueBoundaries.size() - 1; i++) {
|
||||||
|
int intervalStart = uniqueBoundaries.get(i);
|
||||||
|
int intervalEnd = uniqueBoundaries.get(i + 1);
|
||||||
|
if (intervalStart >= intervalEnd) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mark winner = null;
|
||||||
|
boolean winnerIsSemantic = false;
|
||||||
|
|
||||||
|
for (Mark m : combined) {
|
||||||
|
// Mark must fully cover this interval to be a candidate
|
||||||
|
if (m.start > intervalStart || m.end < intervalEnd) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m.start <= intervalStart && m.end >= intervalEnd) {
|
||||||
|
boolean isSemantic = semanticSet.contains(m);
|
||||||
|
|
||||||
|
if (winner == null) {
|
||||||
|
winner = m;
|
||||||
|
winnerIsSemantic = isSemantic;
|
||||||
|
} else if (isSemantic && !winnerIsSemantic) {
|
||||||
|
// Semantic always overrides syntax for same range
|
||||||
|
winner = m;
|
||||||
|
winnerIsSemantic = true;
|
||||||
|
} else if (isSemantic == winnerIsSemantic) {
|
||||||
|
// Same source layer: higher priority wins
|
||||||
|
if (m.type.getPriority() > winner.type.getPriority()) {
|
||||||
|
winner = m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (winner != null) {
|
||||||
|
// Try to merge with previous result if same type and metadata and adjacent
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
Mark prev = result.get(result.size() - 1);
|
||||||
|
if (prev.end == intervalStart
|
||||||
|
&& prev.type == winner.type
|
||||||
|
&& prev.metadata == winner.metadata) {
|
||||||
|
result.set(result.size() - 1,
|
||||||
|
new Mark(prev.start, intervalEnd, prev.type, prev.metadata));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.add(new Mark(intervalStart, intervalEnd, winner.type, winner.metadata));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remove all marks from every layer and increment the revision. */
|
||||||
|
public synchronized void clear() {
|
||||||
|
syntaxMarks = Collections.emptyList();
|
||||||
|
semanticMarks = Collections.emptyList();
|
||||||
|
errorMarks = Collections.emptyList();
|
||||||
|
revision++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MarkLayer{syntax=" + syntaxMarks.size()
|
||||||
|
+ ", semantic=" + semanticMarks.size()
|
||||||
|
+ ", error=" + errorMarks.size()
|
||||||
|
+ ", rev=" + revision + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,486 @@
|
|||||||
|
package bigguy.texteditor.render;
|
||||||
|
|
||||||
|
import noppes.npcs.client.ClientProxy;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.Token;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenType;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.token.TokenErrorMessage;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.type.ImportData;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.field.FieldAccessInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.method.MethodInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.method.MethodCallInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.js_parser.TypeParamInfo;
|
||||||
|
import noppes.npcs.client.gui.util.script.interpreter.ErrorUnderlineRenderer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main text renderer for a single line of source code.
|
||||||
|
* Replaces {@code ScriptLine} with a decoupled design: no back-reference to
|
||||||
|
* {@code ScriptDocument}, no doubly-linked list navigation.
|
||||||
|
*
|
||||||
|
* <p>Rendering flows through two paths:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@link #drawStringHex(int, int)} — primary hex-color renderer
|
||||||
|
* using {@link ClientProxy.Font#drawString(String, int, int, int)}</li>
|
||||||
|
* <li>{@link #drawString(int, int, int)} — legacy Minecraft color-code renderer</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* <p>Tokens are immutable after {@link #buildTokensFromMarks(List, String)} completes.
|
||||||
|
* Error underlines are drawn via caller-supplied {@link DiagnosticRange} records
|
||||||
|
* rather than reaching back into a document object.
|
||||||
|
*/
|
||||||
|
public class RenderLine {
|
||||||
|
|
||||||
|
private static final char COLOR_CHAR = '\u00A7';
|
||||||
|
|
||||||
|
private final String text;
|
||||||
|
private final int globalStart;
|
||||||
|
private final int globalEnd;
|
||||||
|
private final int lineIndex;
|
||||||
|
|
||||||
|
private final List<Token> tokens = new ArrayList<>();
|
||||||
|
private final List<Integer> indentGuides = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lightweight descriptor for a single error underline region.
|
||||||
|
* Provided by the orchestrator/RenderModel so that RenderLine never
|
||||||
|
* queries a document object.
|
||||||
|
*/
|
||||||
|
public static final class DiagnosticRange {
|
||||||
|
/** Global byte offset where the error starts (inclusive). */
|
||||||
|
public final int start;
|
||||||
|
/** Global byte offset where the error ends (exclusive). */
|
||||||
|
public final int end;
|
||||||
|
/** ARGB color for the wavy underline. */
|
||||||
|
public final int color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param start global start offset (inclusive)
|
||||||
|
* @param end global end offset (exclusive)
|
||||||
|
* @param color ARGB underline color
|
||||||
|
*/
|
||||||
|
public DiagnosticRange(int start, int end, int color) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param text the raw text content of this line (no trailing newline)
|
||||||
|
* @param globalStart byte offset in the full document where this line begins
|
||||||
|
* @param globalEnd byte offset in the full document where this line ends (exclusive, includes newline position)
|
||||||
|
* @param lineIndex 0-based line number
|
||||||
|
*/
|
||||||
|
public RenderLine(String text, int globalStart, int globalEnd, int lineIndex) {
|
||||||
|
this.text = text;
|
||||||
|
this.globalStart = globalStart;
|
||||||
|
this.globalEnd = globalEnd;
|
||||||
|
this.lineIndex = lineIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== GETTERS ====================
|
||||||
|
|
||||||
|
/** Raw text content of this line (no trailing newline). */
|
||||||
|
public String getText() { return text; }
|
||||||
|
|
||||||
|
/** Byte offset in the full document where this line begins. */
|
||||||
|
public int getGlobalStart() { return globalStart; }
|
||||||
|
|
||||||
|
/** Byte offset in the full document where this line ends (exclusive). */
|
||||||
|
public int getGlobalEnd() { return globalEnd; }
|
||||||
|
|
||||||
|
/** 0-based line number. */
|
||||||
|
public int getLineIndex() { return lineIndex; }
|
||||||
|
|
||||||
|
/** Character count of the line text. */
|
||||||
|
public int getLength() { return text.length(); }
|
||||||
|
|
||||||
|
/** Unmodifiable view of the tokens on this line. */
|
||||||
|
public List<Token> getTokens() { return Collections.unmodifiableList(tokens); }
|
||||||
|
|
||||||
|
/** Unmodifiable view of indent guide column positions. */
|
||||||
|
public List<Integer> getIndentGuides() { return Collections.unmodifiableList(indentGuides); }
|
||||||
|
|
||||||
|
// ==================== TOKEN QUERIES ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the token that contains the given global position.
|
||||||
|
*
|
||||||
|
* @param globalPosition byte offset in the full document
|
||||||
|
* @return the token at that position, or null if none
|
||||||
|
*/
|
||||||
|
public Token getTokenAt(int globalPosition) {
|
||||||
|
for (Token t : tokens) {
|
||||||
|
if (globalPosition >= t.getGlobalStart() && globalPosition <= t.getGlobalEnd()) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the token at a global position that also satisfies a predicate.
|
||||||
|
*
|
||||||
|
* @param globalPosition byte offset in the full document
|
||||||
|
* @param condition additional filter
|
||||||
|
* @return the matching token, or null
|
||||||
|
*/
|
||||||
|
public Token getTokenAt(int globalPosition, Predicate<Token> condition) {
|
||||||
|
for (Token t : tokens) {
|
||||||
|
if (globalPosition >= t.getGlobalStart() && globalPosition <= t.getGlobalEnd()
|
||||||
|
&& condition.test(t)) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the first token on this line, or null if the line has no tokens */
|
||||||
|
public Token getFirstToken() {
|
||||||
|
return tokens.isEmpty() ? null : tokens.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the last token on this line, or null if the line has no tokens */
|
||||||
|
public Token getLastToken() {
|
||||||
|
return tokens.isEmpty() ? null : tokens.get(tokens.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== POSITION UTILITIES ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a global position falls within this line's range.
|
||||||
|
*
|
||||||
|
* @param globalPosition byte offset in the full document
|
||||||
|
* @return true if {@code globalStart <= globalPosition < globalEnd}
|
||||||
|
*/
|
||||||
|
public boolean containsPosition(int globalPosition) {
|
||||||
|
return globalPosition >= globalStart && globalPosition < globalEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a global position to a local column offset within this line.
|
||||||
|
*
|
||||||
|
* @param globalPosition byte offset in the full document
|
||||||
|
* @return clamped column in {@code [0, text.length()]}
|
||||||
|
*/
|
||||||
|
public int toColumn(int globalPosition) {
|
||||||
|
return Math.max(0, Math.min(globalPosition - globalStart, text.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a local column offset to a global position.
|
||||||
|
*
|
||||||
|
* @param column local offset within this line
|
||||||
|
* @return global byte offset
|
||||||
|
*/
|
||||||
|
public int toGlobal(int column) {
|
||||||
|
return globalStart + Math.max(0, Math.min(column, text.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== TOKEN BUILDING ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build tokens from a list of marks (highlight regions).
|
||||||
|
* Fills gaps between marks with {@link TokenType#DEFAULT} tokens.
|
||||||
|
* Attaches metadata from marks to the created tokens.
|
||||||
|
*
|
||||||
|
* <p>This is the decoupled replacement for
|
||||||
|
* {@code ScriptLine.buildTokensFromMarks(marks, fullText, document)}.
|
||||||
|
* No ScriptDocument parameter — removes the coupling.
|
||||||
|
*
|
||||||
|
* @param marks list of highlight marks that overlap this line, sorted by start position
|
||||||
|
* @param fullText the complete document text
|
||||||
|
*/
|
||||||
|
public void buildTokensFromMarks(List<Mark> marks, String fullText) {
|
||||||
|
tokens.clear();
|
||||||
|
int cursor = globalStart;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* globalEnd includes the newline character position
|
||||||
|
* (lineEnd = lineStart + text.length() + 1), but the line's text field
|
||||||
|
* does NOT include the newline. Clamp all token boundaries to the
|
||||||
|
* displayable text end so that '\n' never leaks into rendered token text.
|
||||||
|
*/
|
||||||
|
int displayEnd = Math.min(globalStart + text.length(), fullText.length());
|
||||||
|
|
||||||
|
for (Mark mark : marks) {
|
||||||
|
if (mark.end <= globalStart || mark.start >= displayEnd) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tokenStart = Math.max(mark.start, globalStart);
|
||||||
|
int tokenEnd = Math.min(mark.end, displayEnd);
|
||||||
|
|
||||||
|
tokenStart = Math.max(0, Math.min(tokenStart, fullText.length()));
|
||||||
|
tokenEnd = Math.max(0, Math.min(tokenEnd, fullText.length()));
|
||||||
|
|
||||||
|
if (cursor < tokenStart) {
|
||||||
|
int gapEnd = Math.min(tokenStart, fullText.length());
|
||||||
|
String gapText = fullText.substring(cursor, gapEnd);
|
||||||
|
addToken(Token.defaultToken(gapText, cursor, gapEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tokenStart < tokenEnd) {
|
||||||
|
String tokenText = fullText.substring(tokenStart, tokenEnd);
|
||||||
|
Token token = new Token(tokenText, tokenStart, tokenEnd, mark.type);
|
||||||
|
|
||||||
|
if (mark.metadata != null) {
|
||||||
|
applyTokenMetadata(token, mark.metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
addToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = tokenEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor < displayEnd) {
|
||||||
|
String trailingText = fullText.substring(cursor, displayEnd);
|
||||||
|
addToken(Token.defaultToken(trailingText, cursor, displayEnd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply analysis metadata to a token based on the metadata's runtime type.
|
||||||
|
* Handles TypeInfo, TypeParamInfo, MethodCallInfo, FieldInfo.ArgInfo,
|
||||||
|
* FieldInfo, MethodInfo, ImportData, FieldAccessInfo, and TokenErrorMessage.
|
||||||
|
*
|
||||||
|
* @param token the token to enrich
|
||||||
|
* @param metadata the analysis artifact
|
||||||
|
*/
|
||||||
|
public void applyTokenMetadata(Token token, Object metadata) {
|
||||||
|
if (metadata instanceof TypeInfo) {
|
||||||
|
token.setTypeInfo((TypeInfo) metadata);
|
||||||
|
} else if (metadata instanceof TypeParamInfo) {
|
||||||
|
TypeParamInfo typeParam = (TypeParamInfo) metadata;
|
||||||
|
token.setTypeInfo(TypeInfo.typeParameter(typeParam.getName(), typeParam));
|
||||||
|
} else if (metadata instanceof MethodCallInfo) {
|
||||||
|
MethodCallInfo callInfo = (MethodCallInfo) metadata;
|
||||||
|
if (callInfo.isConstructor()) {
|
||||||
|
token.setTypeInfo(callInfo.getReceiverType());
|
||||||
|
token.setMethodInfo(callInfo.getResolvedMethod());
|
||||||
|
}
|
||||||
|
token.setMethodCallInfo(callInfo);
|
||||||
|
} else if (metadata instanceof FieldInfo.ArgInfo) {
|
||||||
|
FieldInfo.ArgInfo ctx = (FieldInfo.ArgInfo) metadata;
|
||||||
|
token.setFieldInfo(ctx.fieldInfo);
|
||||||
|
token.setMethodCallInfo(ctx.methodCallInfo);
|
||||||
|
} else if (metadata instanceof FieldInfo) {
|
||||||
|
token.setFieldInfo((FieldInfo) metadata);
|
||||||
|
} else if (metadata instanceof MethodInfo) {
|
||||||
|
token.setMethodInfo((MethodInfo) metadata);
|
||||||
|
} else if (metadata instanceof ImportData) {
|
||||||
|
token.setImportData((ImportData) metadata);
|
||||||
|
} else if (metadata instanceof FieldAccessInfo) {
|
||||||
|
FieldAccessInfo accessInfo = (FieldAccessInfo) metadata;
|
||||||
|
token.setFieldAccessInfo(accessInfo);
|
||||||
|
token.setFieldInfo(accessInfo.getResolvedField());
|
||||||
|
} else if (metadata instanceof TokenErrorMessage) {
|
||||||
|
token.setErrorMessage((TokenErrorMessage) metadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a token to this line and wire up intra-line navigation links.
|
||||||
|
*/
|
||||||
|
private void addToken(Token token) {
|
||||||
|
if (!tokens.isEmpty()) {
|
||||||
|
Token last = tokens.get(tokens.size() - 1);
|
||||||
|
last.setNext(token);
|
||||||
|
token.setPrev(last);
|
||||||
|
}
|
||||||
|
token.setParentLine(null);
|
||||||
|
tokens.add(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== INDENT GUIDES ====================
|
||||||
|
|
||||||
|
/** Remove all indent guides from this line. */
|
||||||
|
public void clearIndentGuides() {
|
||||||
|
indentGuides.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an indent guide at the specified column if not already present.
|
||||||
|
*
|
||||||
|
* @param column the column position for the guide
|
||||||
|
*/
|
||||||
|
public void addIndentGuide(int column) {
|
||||||
|
if (!indentGuides.contains(column)) {
|
||||||
|
indentGuides.add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== RENDERING ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the rendered pixel width of a substring of this line, accounting for
|
||||||
|
* bold/italic token styles. Characters covered by bold or italic tokens are
|
||||||
|
* measured with the appropriate font style via
|
||||||
|
* {@link ClientProxy.Font#width(String, int)}, producing the same widths as the
|
||||||
|
* actual rendered output.
|
||||||
|
*
|
||||||
|
* <p>Critical for cursor positioning and error underline alignment.
|
||||||
|
*
|
||||||
|
* @param localStart start index within the line text (inclusive)
|
||||||
|
* @param localEnd end index within the line text (exclusive)
|
||||||
|
* @return pixel width matching the rendered output
|
||||||
|
*/
|
||||||
|
public int getRenderedWidth(int localStart, int localEnd) {
|
||||||
|
localStart = Math.max(0, Math.min(localStart, text.length()));
|
||||||
|
localEnd = Math.max(localStart, Math.min(localEnd, text.length()));
|
||||||
|
if (localStart >= localEnd) return 0;
|
||||||
|
|
||||||
|
int width = 0;
|
||||||
|
int cursor = localStart;
|
||||||
|
|
||||||
|
for (Token t : tokens) {
|
||||||
|
if (cursor >= localEnd) break;
|
||||||
|
|
||||||
|
int tokenLocalStart = t.getGlobalStart() - globalStart;
|
||||||
|
int tokenLocalEnd = tokenLocalStart + t.getText().length();
|
||||||
|
|
||||||
|
// Gap before this token (rendered as plain text)
|
||||||
|
if (cursor < tokenLocalStart) {
|
||||||
|
int gapEnd = Math.min(tokenLocalStart, localEnd);
|
||||||
|
if (gapEnd > cursor) {
|
||||||
|
width += ClientProxy.Font.width(text.substring(cursor, gapEnd));
|
||||||
|
cursor = gapEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor >= localEnd) break;
|
||||||
|
|
||||||
|
// Token overlap with [localStart, localEnd)
|
||||||
|
int overlapStart = Math.max(cursor, tokenLocalStart);
|
||||||
|
int overlapEnd = Math.min(tokenLocalEnd, localEnd);
|
||||||
|
if (overlapEnd > overlapStart) {
|
||||||
|
String substr = text.substring(overlapStart, overlapEnd);
|
||||||
|
width += ClientProxy.Font.width(substr, t.getFontStyle());
|
||||||
|
cursor = overlapEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trailing text after last token (plain)
|
||||||
|
if (cursor < localEnd) {
|
||||||
|
width += ClientProxy.Font.width(text.substring(cursor, localEnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw this line with hex colors. THE PRIMARY RENDERER.
|
||||||
|
* Builds {@link RenderSegment}s from the token list, then renders each one
|
||||||
|
* at the correct pixel offset via
|
||||||
|
* {@link ClientProxy.Font#drawString(String, int, int, int)}.
|
||||||
|
*
|
||||||
|
* <p>Does NOT draw error underlines — call
|
||||||
|
* {@link #drawErrorUnderlines(int, int, List)} separately with
|
||||||
|
* caller-supplied diagnostics.
|
||||||
|
*
|
||||||
|
* @param x left pixel coordinate
|
||||||
|
* @param y top pixel coordinate
|
||||||
|
*/
|
||||||
|
public void drawStringHex(int x, int y) {
|
||||||
|
int lastIndex = 0;
|
||||||
|
List<RenderSegment> segments = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Token t : tokens) {
|
||||||
|
int tokenStart = t.getGlobalStart() - globalStart;
|
||||||
|
|
||||||
|
if (tokenStart > lastIndex && tokenStart <= text.length()) {
|
||||||
|
String gap = text.substring(lastIndex, tokenStart);
|
||||||
|
segments.add(new RenderSegment(lastIndex, gap, 0xFFFFFFFF, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
String styledText = t.getStylePrefix() + t.getText();
|
||||||
|
segments.add(new RenderSegment(tokenStart, styledText, t.getHexColor(), true));
|
||||||
|
|
||||||
|
lastIndex = tokenStart + t.getText().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastIndex < text.length()) {
|
||||||
|
String remaining = text.substring(lastIndex);
|
||||||
|
segments.add(new RenderSegment(lastIndex, remaining, 0xFFFFFFFF, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (RenderSegment seg : segments) {
|
||||||
|
if (!seg.text.isEmpty()) {
|
||||||
|
int prefixWidth = getRenderedWidth(0, seg.startPosition);
|
||||||
|
ClientProxy.Font.drawString(seg.text, x + prefixWidth, y, seg.hexColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw this line with legacy Minecraft color codes.
|
||||||
|
* Backup rendering path that uses §-prefixed color codes.
|
||||||
|
* Also draws error underlines via the supplied diagnostic list.
|
||||||
|
*
|
||||||
|
* @param x left pixel coordinate
|
||||||
|
* @param y top pixel coordinate
|
||||||
|
* @param defaultColor fallback color for non-token text
|
||||||
|
*/
|
||||||
|
public void drawString(int x, int y, int defaultColor) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
int lastIndex = 0;
|
||||||
|
|
||||||
|
for (Token t : tokens) {
|
||||||
|
int tokenStart = t.getGlobalStart() - globalStart;
|
||||||
|
|
||||||
|
if (tokenStart > lastIndex && tokenStart <= text.length()) {
|
||||||
|
String gapText = text.substring(lastIndex, tokenStart);
|
||||||
|
builder.append(gapText);
|
||||||
|
}
|
||||||
|
|
||||||
|
String stylePrefix = t.getStylePrefix();
|
||||||
|
builder.append(COLOR_CHAR)
|
||||||
|
.append(t.getColorCode())
|
||||||
|
.append(stylePrefix)
|
||||||
|
.append(t.getText())
|
||||||
|
.append(COLOR_CHAR)
|
||||||
|
.append('r');
|
||||||
|
|
||||||
|
lastIndex = tokenStart + t.getText().length();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastIndex < text.length()) {
|
||||||
|
builder.append(text.substring(lastIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientProxy.Font.drawString(builder.toString(), x, y, defaultColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw wavy error underlines for all diagnostic ranges that intersect this line.
|
||||||
|
* Replaces the old {@code ScriptLine.drawErrorUnderlines()} that reached
|
||||||
|
* into {@code ScriptDocument} — this version receives diagnostics as arguments.
|
||||||
|
*
|
||||||
|
* @param lineStartX left pixel coordinate where the line starts rendering
|
||||||
|
* @param baselineY Y coordinate for the underline (typically {@code y + fontHeight - 1})
|
||||||
|
* @param errors diagnostic ranges to underline; may be empty but not null
|
||||||
|
*/
|
||||||
|
public void drawErrorUnderlines(int lineStartX, int baselineY, List<DiagnosticRange> errors) {
|
||||||
|
for (DiagnosticRange diag : errors) {
|
||||||
|
ErrorUnderlineRenderer.drawUnderlineForSpan(
|
||||||
|
diag.start, diag.end,
|
||||||
|
lineStartX, baselineY,
|
||||||
|
text, globalStart, globalEnd,
|
||||||
|
diag.color
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RenderLine{" + lineIndex + ": '" + text + "' [" + globalStart + "-" + globalEnd
|
||||||
|
+ "], " + tokens.size() + " tokens}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
package bigguy.texteditor.render;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Layout manager that owns the flat list of {@link RenderLine}s and provides
|
||||||
|
* viewport calculations for scrolled rendering.
|
||||||
|
*
|
||||||
|
* <p>Replaces the layout fields previously scattered across {@code ScriptDocument}:
|
||||||
|
* {@code lineHeight}, {@code totalHeight}, {@code visibleLines}, {@code linesCount}.
|
||||||
|
*
|
||||||
|
* <p>Thread safety: the {@code lines} reference is volatile so that a background
|
||||||
|
* rebuild can publish a new list that the render thread picks up on the next frame.
|
||||||
|
* Individual reads through the accessors are safe without external synchronization.
|
||||||
|
*/
|
||||||
|
public class RenderModel {
|
||||||
|
|
||||||
|
private volatile List<RenderLine> lines = Collections.emptyList();
|
||||||
|
private volatile int lineHeight = 10;
|
||||||
|
|
||||||
|
// ==================== LINE ACCESS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return total number of render lines
|
||||||
|
*/
|
||||||
|
public int getLineCount() {
|
||||||
|
return lines.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return total pixel height of all lines ({@code lineCount * lineHeight})
|
||||||
|
*/
|
||||||
|
public int getTotalHeight() {
|
||||||
|
return lines.size() * lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute how many lines fit in the given viewport height.
|
||||||
|
*
|
||||||
|
* @param viewportHeight pixel height of the visible area
|
||||||
|
* @return number of fully visible lines
|
||||||
|
*/
|
||||||
|
public int getVisibleLineCount(int viewportHeight) {
|
||||||
|
return lineHeight > 0 ? viewportHeight / lineHeight : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bounds-checked access to a single render line.
|
||||||
|
*
|
||||||
|
* @param index 0-based line index
|
||||||
|
* @return the RenderLine at the given index
|
||||||
|
* @throws IndexOutOfBoundsException if index is out of range
|
||||||
|
*/
|
||||||
|
public RenderLine getLine(int index) {
|
||||||
|
return lines.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sub-list of lines visible for the current scroll position.
|
||||||
|
*
|
||||||
|
* @param scrollOffset pixel offset from the top of the document
|
||||||
|
* @param viewportHeight pixel height of the visible area
|
||||||
|
* @return unmodifiable sublist of visible lines (may be empty)
|
||||||
|
*/
|
||||||
|
public List<RenderLine> getVisibleLines(int scrollOffset, int viewportHeight) {
|
||||||
|
List<RenderLine> snapshot = lines;
|
||||||
|
if (snapshot.isEmpty() || lineHeight <= 0) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
int firstLine = Math.max(0, scrollOffset / lineHeight);
|
||||||
|
int visibleCount = (viewportHeight / lineHeight) + 2;
|
||||||
|
int lastLine = Math.min(snapshot.size(), firstLine + visibleCount);
|
||||||
|
|
||||||
|
if (firstLine >= snapshot.size()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.unmodifiableList(snapshot.subList(firstLine, lastLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the line that contains the given global byte offset using binary search.
|
||||||
|
*
|
||||||
|
* @param globalOffset byte offset in the full document
|
||||||
|
* @return the RenderLine containing that offset, or null if not found
|
||||||
|
*/
|
||||||
|
public RenderLine getLineAtOffset(int globalOffset) {
|
||||||
|
List<RenderLine> snapshot = lines;
|
||||||
|
int idx = getLineIndexForOffset(globalOffset);
|
||||||
|
if (idx >= 0 && idx < snapshot.size()) {
|
||||||
|
return snapshot.get(idx);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binary search for the line index containing the given global byte offset.
|
||||||
|
*
|
||||||
|
* @param offset byte offset in the full document
|
||||||
|
* @return 0-based line index, or -1 if no line contains the offset
|
||||||
|
*/
|
||||||
|
public int getLineIndexForOffset(int offset) {
|
||||||
|
List<RenderLine> snapshot = lines;
|
||||||
|
int lo = 0;
|
||||||
|
int hi = snapshot.size() - 1;
|
||||||
|
|
||||||
|
while (lo <= hi) {
|
||||||
|
int mid = (lo + hi) >>> 1;
|
||||||
|
RenderLine line = snapshot.get(mid);
|
||||||
|
|
||||||
|
if (offset < line.getGlobalStart()) {
|
||||||
|
hi = mid - 1;
|
||||||
|
} else if (offset >= line.getGlobalEnd()) {
|
||||||
|
lo = mid + 1;
|
||||||
|
} else {
|
||||||
|
return mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return unmodifiable view of all render lines
|
||||||
|
*/
|
||||||
|
public List<RenderLine> getLines() {
|
||||||
|
return Collections.unmodifiableList(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return current pixel height per line
|
||||||
|
*/
|
||||||
|
public int getLineHeight() {
|
||||||
|
return lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param lineHeight new pixel height per line
|
||||||
|
*/
|
||||||
|
public void setLineHeight(int lineHeight) {
|
||||||
|
this.lineHeight = lineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== REBUILD ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuild the entire line model from source text and merged marks.
|
||||||
|
*
|
||||||
|
* <ol>
|
||||||
|
* <li>Splits {@code sourceText} by newlines into logical lines</li>
|
||||||
|
* <li>Creates a {@link RenderLine} for each with correct
|
||||||
|
* globalStart/globalEnd/lineIndex</li>
|
||||||
|
* <li>Calls {@link RenderLine#buildTokensFromMarks(List, String)}
|
||||||
|
* with the marks that overlap each line</li>
|
||||||
|
* <li>Computes indent guides per line</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param sourceText the complete document text
|
||||||
|
* @param mergedMarks merged marks from {@link MarkLayer#merge()}, sorted by start
|
||||||
|
* @param lineHeight pixel height per line
|
||||||
|
*/
|
||||||
|
public void rebuild(String sourceText, List<Mark> mergedMarks, int lineHeight) {
|
||||||
|
this.lineHeight = lineHeight;
|
||||||
|
|
||||||
|
List<RenderLine> newLines = new ArrayList<>();
|
||||||
|
|
||||||
|
if (sourceText.isEmpty()) {
|
||||||
|
RenderLine empty = new RenderLine("", 0, 0, 0);
|
||||||
|
empty.buildTokensFromMarks(Collections.<Mark>emptyList(), sourceText);
|
||||||
|
newLines.add(empty);
|
||||||
|
this.lines = newLines;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lineIdx = 0;
|
||||||
|
int pos = 0;
|
||||||
|
int textLen = sourceText.length();
|
||||||
|
|
||||||
|
while (pos <= textLen) {
|
||||||
|
int nlPos = sourceText.indexOf('\n', pos);
|
||||||
|
int lineEnd;
|
||||||
|
int globalEnd;
|
||||||
|
|
||||||
|
if (nlPos == -1) {
|
||||||
|
lineEnd = textLen;
|
||||||
|
globalEnd = textLen;
|
||||||
|
} else {
|
||||||
|
lineEnd = nlPos;
|
||||||
|
globalEnd = nlPos + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lineText = sourceText.substring(pos, lineEnd);
|
||||||
|
RenderLine renderLine = new RenderLine(lineText, pos, globalEnd, lineIdx);
|
||||||
|
|
||||||
|
List<Mark> lineMarks = collectMarksForRange(mergedMarks, pos, globalEnd);
|
||||||
|
renderLine.buildTokensFromMarks(lineMarks, sourceText);
|
||||||
|
|
||||||
|
computeIndentGuides(renderLine, lineText);
|
||||||
|
|
||||||
|
newLines.add(renderLine);
|
||||||
|
lineIdx++;
|
||||||
|
|
||||||
|
if (nlPos == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pos = nlPos + 1;
|
||||||
|
|
||||||
|
if (pos == textLen) {
|
||||||
|
RenderLine trailing = new RenderLine("", pos, pos, lineIdx);
|
||||||
|
trailing.buildTokensFromMarks(Collections.<Mark>emptyList(), sourceText);
|
||||||
|
newLines.add(trailing);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.lines = newLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect marks that overlap the range {@code [rangeStart, rangeEnd)}.
|
||||||
|
* Assumes {@code allMarks} is sorted by start position and uses a linear scan
|
||||||
|
* with early exit.
|
||||||
|
*/
|
||||||
|
private static List<Mark> collectMarksForRange(List<Mark> allMarks, int rangeStart, int rangeEnd) {
|
||||||
|
List<Mark> result = new ArrayList<>();
|
||||||
|
for (Mark m : allMarks) {
|
||||||
|
if (m.start >= rangeEnd) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (m.end > rangeStart) {
|
||||||
|
result.add(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute indent guides for a line based on its leading whitespace.
|
||||||
|
* Adds a guide at each tab-stop column (every 4 characters) within the indentation.
|
||||||
|
*/
|
||||||
|
private static void computeIndentGuides(RenderLine line, String text) {
|
||||||
|
int indent = 0;
|
||||||
|
for (int i = 0; i < text.length(); i++) {
|
||||||
|
char c = text.charAt(i);
|
||||||
|
if (c == ' ') {
|
||||||
|
indent++;
|
||||||
|
} else if (c == '\t') {
|
||||||
|
indent = ((indent / 4) + 1) * 4;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int tabSize = 4;
|
||||||
|
for (int col = tabSize; col <= indent; col += tabSize) {
|
||||||
|
line.addIndentGuide(col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RenderModel{lines=" + lines.size()
|
||||||
|
+ ", lineHeight=" + lineHeight
|
||||||
|
+ ", totalHeight=" + getTotalHeight() + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package bigguy.texteditor.render;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An individual renderable text chunk within a {@link RenderLine}.
|
||||||
|
* Each segment represents either a styled token or an unstyled gap between tokens.
|
||||||
|
*
|
||||||
|
* <p>Immutable value type consumed during {@link RenderLine#drawStringHex(int, int)}
|
||||||
|
* rendering. Segments are built on each draw call from the line's token list and
|
||||||
|
* are not cached.
|
||||||
|
*/
|
||||||
|
public final class RenderSegment {
|
||||||
|
|
||||||
|
/** Local offset within the line text where this segment starts. */
|
||||||
|
public final int startPosition;
|
||||||
|
|
||||||
|
/** The displayable text content (may include style prefix codes for tokens). */
|
||||||
|
public final String text;
|
||||||
|
|
||||||
|
/** ARGB hex color for rendering (e.g. 0xFFFF5555 for red). */
|
||||||
|
public final int hexColor;
|
||||||
|
|
||||||
|
/** True if this segment was produced from a Token; false for gap/trailing text. */
|
||||||
|
public final boolean isToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param startPosition local offset within the line text
|
||||||
|
* @param text displayable text content
|
||||||
|
* @param hexColor ARGB hex color
|
||||||
|
* @param isToken true when this segment originates from a Token
|
||||||
|
*/
|
||||||
|
public RenderSegment(int startPosition, String text, int hexColor, boolean isToken) {
|
||||||
|
this.startPosition = startPosition;
|
||||||
|
this.text = text;
|
||||||
|
this.hexColor = hexColor;
|
||||||
|
this.isToken = isToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "RenderSegment{pos=" + startPosition
|
||||||
|
+ ", text='" + text + "'"
|
||||||
|
+ ", color=0x" + Integer.toHexString(hexColor)
|
||||||
|
+ (isToken ? ", token" : ", gap")
|
||||||
|
+ "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,530 @@
|
|||||||
|
package bigguy.texteditor.semantics;
|
||||||
|
|
||||||
|
import bigguy.texteditor.treesitter.java.TextSpan;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unified import resolution index for a single script document.
|
||||||
|
*
|
||||||
|
* <p>Replaces the four separate import-tracking fields that previously lived in
|
||||||
|
* {@code ScriptDocument} ({@code imports}, {@code wildcardPackages},
|
||||||
|
* {@code importsBySimpleName}, {@code implicitImports}) with a single source of
|
||||||
|
* truth backed by a list of {@link ImportEntry} objects.</p>
|
||||||
|
*
|
||||||
|
* <h3>Lazy derived indexes</h3>
|
||||||
|
* <p>Two derived lookup maps ({@code bySimpleName} and {@code byFullPath}) are
|
||||||
|
* computed lazily on first access after any mutation, and cached until the next
|
||||||
|
* mutation invalidates them. This gives O(1) lookups without paying rebuild
|
||||||
|
* cost on every add.</p>
|
||||||
|
*
|
||||||
|
* <h3>Version tracking</h3>
|
||||||
|
* <p>A monotonically increasing version counter is bumped on every mutation.
|
||||||
|
* External code can call {@link #version()} to detect whether the index has
|
||||||
|
* changed since its last snapshot.</p>
|
||||||
|
*
|
||||||
|
* <h3>Thread safety</h3>
|
||||||
|
* <p>All mutation methods are {@code synchronized}. All query methods return
|
||||||
|
* defensive copies or unmodifiable snapshots, so callers never observe
|
||||||
|
* partially-mutated state.</p>
|
||||||
|
*
|
||||||
|
* @since Phase 2 — CST editor architecture
|
||||||
|
*/
|
||||||
|
public final class ImportIndex {
|
||||||
|
|
||||||
|
// ── Primary store ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/** The authoritative list of all import entries (explicit + implicit). */
|
||||||
|
private final List<ImportEntry> entries;
|
||||||
|
|
||||||
|
// ── Derived indexes (lazily rebuilt) ────────────────────────────────
|
||||||
|
|
||||||
|
/** Quick lookup by unqualified simple name (e.g. "List" → entry). */
|
||||||
|
private Map<String, ImportEntry> bySimpleName;
|
||||||
|
|
||||||
|
/** Quick lookup by fully qualified path (e.g. "java.util.List" → entry). */
|
||||||
|
private Map<String, ImportEntry> byFullPath;
|
||||||
|
|
||||||
|
/** Whether the derived indexes need rebuilding. */
|
||||||
|
private boolean dirty;
|
||||||
|
|
||||||
|
/** Monotonically increasing version counter, bumped on every mutation. */
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
// ── Construction ───────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new, empty {@code ImportIndex}.
|
||||||
|
*/
|
||||||
|
public ImportIndex() {
|
||||||
|
this.entries = new ArrayList<ImportEntry>();
|
||||||
|
this.bySimpleName = Collections.emptyMap();
|
||||||
|
this.byFullPath = Collections.emptyMap();
|
||||||
|
this.dirty = false;
|
||||||
|
this.version = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Inner class ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An individual import declaration (explicit or implicit).
|
||||||
|
*
|
||||||
|
* <p>Instances are immutable. Two entries are equal if and only if they
|
||||||
|
* share the same {@code fullPath} and {@code isImplicit} flag — the
|
||||||
|
* source range is deliberately excluded from equality so that
|
||||||
|
* re-parsing the same import at a different offset does not produce
|
||||||
|
* a spurious "changed" signal.</p>
|
||||||
|
*/
|
||||||
|
public static final class ImportEntry {
|
||||||
|
|
||||||
|
private final String fullPath;
|
||||||
|
private final String simpleName;
|
||||||
|
private final boolean isWildcard;
|
||||||
|
private final boolean isStatic;
|
||||||
|
private final boolean isImplicit;
|
||||||
|
private final TextSpan range;
|
||||||
|
private final String packagePath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@code ImportEntry}.
|
||||||
|
*
|
||||||
|
* @param fullPath the fully qualified import path, e.g. {@code "java.util.List"}
|
||||||
|
* or {@code "java.util.*"}
|
||||||
|
* @param simpleName the unqualified name, e.g. {@code "List"} or {@code "*"}
|
||||||
|
* @param isWildcard {@code true} for wildcard imports ({@code import pkg.*})
|
||||||
|
* @param isStatic {@code true} for static imports ({@code import static ...})
|
||||||
|
* @param isImplicit {@code true} for auto-injected imports (e.g. {@code java.lang.*})
|
||||||
|
* @param range source location of the import statement; may be {@code null}
|
||||||
|
* for implicit imports
|
||||||
|
* @param packagePath the package portion, e.g. {@code "java.util"}
|
||||||
|
*/
|
||||||
|
public ImportEntry(String fullPath, String simpleName, boolean isWildcard,
|
||||||
|
boolean isStatic, boolean isImplicit, TextSpan range,
|
||||||
|
String packagePath) {
|
||||||
|
if (fullPath == null) {
|
||||||
|
throw new IllegalArgumentException("fullPath must not be null");
|
||||||
|
}
|
||||||
|
if (simpleName == null) {
|
||||||
|
throw new IllegalArgumentException("simpleName must not be null");
|
||||||
|
}
|
||||||
|
if (packagePath == null) {
|
||||||
|
throw new IllegalArgumentException("packagePath must not be null");
|
||||||
|
}
|
||||||
|
this.fullPath = fullPath;
|
||||||
|
this.simpleName = simpleName;
|
||||||
|
this.isWildcard = isWildcard;
|
||||||
|
this.isStatic = isStatic;
|
||||||
|
this.isImplicit = isImplicit;
|
||||||
|
this.range = range;
|
||||||
|
this.packagePath = packagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory for creating an {@code ImportEntry} from a fully qualified path string.
|
||||||
|
*
|
||||||
|
* <p>Automatically derives {@code simpleName}, {@code isWildcard}, and
|
||||||
|
* {@code packagePath} from the path.</p>
|
||||||
|
*
|
||||||
|
* @param fullPath the fully qualified import path
|
||||||
|
* @param isStatic whether this is a static import
|
||||||
|
* @param isImplicit whether this is an implicit (auto-injected) import
|
||||||
|
* @param range source location, or {@code null} for implicit imports
|
||||||
|
* @return a new {@code ImportEntry}
|
||||||
|
*/
|
||||||
|
public static ImportEntry fromFullPath(String fullPath, boolean isStatic,
|
||||||
|
boolean isImplicit, TextSpan range) {
|
||||||
|
boolean isWildcard = fullPath.endsWith(".*");
|
||||||
|
String simpleName;
|
||||||
|
String packagePath;
|
||||||
|
int lastDot = fullPath.lastIndexOf('.');
|
||||||
|
if (lastDot >= 0) {
|
||||||
|
simpleName = fullPath.substring(lastDot + 1);
|
||||||
|
packagePath = fullPath.substring(0, lastDot);
|
||||||
|
} else {
|
||||||
|
simpleName = fullPath;
|
||||||
|
packagePath = "";
|
||||||
|
}
|
||||||
|
return new ImportEntry(fullPath, simpleName, isWildcard, isStatic,
|
||||||
|
isImplicit, range, packagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the fully qualified import path (e.g. {@code "java.util.List"}) */
|
||||||
|
public String getFullPath() { return fullPath; }
|
||||||
|
|
||||||
|
/** @return the unqualified name (e.g. {@code "List"} or {@code "*"}) */
|
||||||
|
public String getSimpleName() { return simpleName; }
|
||||||
|
|
||||||
|
/** @return {@code true} for wildcard imports ({@code import pkg.*}) */
|
||||||
|
public boolean isWildcard() { return isWildcard; }
|
||||||
|
|
||||||
|
/** @return {@code true} for static imports */
|
||||||
|
public boolean isStatic() { return isStatic; }
|
||||||
|
|
||||||
|
/** @return {@code true} for auto-injected imports */
|
||||||
|
public boolean isImplicit() { return isImplicit; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the source location of the import statement, or {@code null}
|
||||||
|
* for implicit imports
|
||||||
|
*/
|
||||||
|
public TextSpan getRange() { return range; }
|
||||||
|
|
||||||
|
/** @return the package portion (e.g. {@code "java.util"}) */
|
||||||
|
public String getPackagePath() { return packagePath; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (!(obj instanceof ImportEntry)) return false;
|
||||||
|
ImportEntry that = (ImportEntry) obj;
|
||||||
|
return this.isImplicit == that.isImplicit
|
||||||
|
&& this.fullPath.equals(that.fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = fullPath.hashCode();
|
||||||
|
result = 31 * result + (isImplicit ? 1 : 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (isImplicit) sb.append("[implicit] ");
|
||||||
|
if (isStatic) sb.append("static ");
|
||||||
|
sb.append("import ").append(fullPath);
|
||||||
|
if (range != null) {
|
||||||
|
sb.append(" at ").append(range);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Building (mutators) ────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all import entries and resets the version counter.
|
||||||
|
*/
|
||||||
|
public synchronized void clear() {
|
||||||
|
entries.clear();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a single import entry.
|
||||||
|
*
|
||||||
|
* @param entry the entry to add; must not be {@code null}
|
||||||
|
* @throws IllegalArgumentException if {@code entry} is {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized void addImport(ImportEntry entry) {
|
||||||
|
if (entry == null) {
|
||||||
|
throw new IllegalArgumentException("entry must not be null");
|
||||||
|
}
|
||||||
|
entries.add(entry);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an implicit (auto-injected) import from a fully qualified path.
|
||||||
|
*
|
||||||
|
* <p>The entry is created with {@code isImplicit=true}, {@code isStatic=false},
|
||||||
|
* and {@code range=null}.</p>
|
||||||
|
*
|
||||||
|
* @param fullPath the fully qualified path (e.g. {@code "java.lang.*"})
|
||||||
|
*/
|
||||||
|
public synchronized void addImplicitImport(String fullPath) {
|
||||||
|
ImportEntry entry = ImportEntry.fromFullPath(fullPath, false, true, null);
|
||||||
|
entries.add(entry);
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Atomically replaces all entries with the given list.
|
||||||
|
*
|
||||||
|
* <p>The previous contents are discarded. This is the preferred method
|
||||||
|
* when rebuilding imports from a fresh parse — it avoids intermediate
|
||||||
|
* states visible to concurrent readers.</p>
|
||||||
|
*
|
||||||
|
* @param newEntries the replacement entries; the list is defensively copied
|
||||||
|
*/
|
||||||
|
public synchronized void replaceAll(List<ImportEntry> newEntries) {
|
||||||
|
entries.clear();
|
||||||
|
if (newEntries != null) {
|
||||||
|
entries.addAll(newEntries);
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Resolution (queries) ───────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves an import by its unqualified simple name.
|
||||||
|
*
|
||||||
|
* <p>Resolution order:</p>
|
||||||
|
* <ol>
|
||||||
|
* <li>Exact match in explicit (non-wildcard) imports by simple name.</li>
|
||||||
|
* <li>If no exact match, returns the first wildcard import entry whose
|
||||||
|
* package could contain the type. (Full resolution would require a
|
||||||
|
* {@code TypeResolver} callback — for now the wildcard entry itself
|
||||||
|
* is returned so callers can perform the lookup.)</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param simpleName the unqualified name to resolve (e.g. {@code "List"})
|
||||||
|
* @return the matching entry, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
public synchronized ImportEntry resolveBySimpleName(String simpleName) {
|
||||||
|
if (simpleName == null || simpleName.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ensureIndexes();
|
||||||
|
ImportEntry exact = bySimpleName.get(simpleName);
|
||||||
|
if (exact != null) {
|
||||||
|
return exact;
|
||||||
|
}
|
||||||
|
// Fall back to wildcard entries — return the first wildcard that could
|
||||||
|
// potentially provide the type (caller must verify via TypeResolver).
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
if (entry.isWildcard) {
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves an import by its fully qualified path.
|
||||||
|
*
|
||||||
|
* @param fullPath the fully qualified path (e.g. {@code "java.util.List"})
|
||||||
|
* @return the matching entry, or {@code null} if not found
|
||||||
|
*/
|
||||||
|
public synchronized ImportEntry resolveByFullPath(String fullPath) {
|
||||||
|
if (fullPath == null || fullPath.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ensureIndexes();
|
||||||
|
return byFullPath.get(fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quick check whether a simple name is covered by any import
|
||||||
|
* (explicit, wildcard, or implicit).
|
||||||
|
*
|
||||||
|
* @param simpleName the unqualified name to check
|
||||||
|
* @return {@code true} if any import covers this name
|
||||||
|
*/
|
||||||
|
public synchronized boolean isImported(String simpleName) {
|
||||||
|
return resolveBySimpleName(simpleName) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a fully qualified name is covered by an implicit import.
|
||||||
|
*
|
||||||
|
* <p>This checks both exact matches (e.g. an implicit import of
|
||||||
|
* {@code "java.lang.String"}) and wildcard matches (e.g. an implicit
|
||||||
|
* import of {@code "java.lang.*"} covers {@code "java.lang.String"}).</p>
|
||||||
|
*
|
||||||
|
* @param fqn the fully qualified name to check
|
||||||
|
* @return {@code true} if an implicit import covers this FQN
|
||||||
|
*/
|
||||||
|
public synchronized boolean isImplicitlyImported(String fqn) {
|
||||||
|
if (fqn == null || fqn.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
if (!entry.isImplicit) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (entry.fullPath.equals(fqn)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Check wildcard coverage: "java.lang.*" covers "java.lang.String"
|
||||||
|
if (entry.isWildcard) {
|
||||||
|
String pkg = entry.packagePath;
|
||||||
|
if (fqn.startsWith(pkg + ".") && fqn.indexOf('.', pkg.length() + 1) < 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Wildcard package queries ───────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all wildcard package paths (e.g. {@code "java.util"} from
|
||||||
|
* {@code import java.util.*}).
|
||||||
|
*
|
||||||
|
* @return an unmodifiable set of package paths; never {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized Set<String> getWildcardPackages() {
|
||||||
|
Set<String> result = new HashSet<String>();
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
if (entry.isWildcard) {
|
||||||
|
result.add(entry.packagePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableSet(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Iteration ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a snapshot of all import entries (both explicit and implicit).
|
||||||
|
*
|
||||||
|
* @return an unmodifiable list of all entries; never {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized List<ImportEntry> getAllImports() {
|
||||||
|
return Collections.unmodifiableList(new ArrayList<ImportEntry>(entries));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a snapshot of only the implicit (auto-injected) imports.
|
||||||
|
*
|
||||||
|
* @return an unmodifiable list; never {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized List<ImportEntry> getImplicitImports() {
|
||||||
|
List<ImportEntry> result = new ArrayList<ImportEntry>();
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
if (entry.isImplicit) {
|
||||||
|
result.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a snapshot of only the explicit (non-implicit) imports.
|
||||||
|
*
|
||||||
|
* @return an unmodifiable list; never {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized List<ImportEntry> getExplicitImports() {
|
||||||
|
List<ImportEntry> result = new ArrayList<ImportEntry>();
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
if (!entry.isImplicit) {
|
||||||
|
result.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Collections.unmodifiableList(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Pruning ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes implicit imports whose simple name is not in the given set
|
||||||
|
* of used names.
|
||||||
|
*
|
||||||
|
* <p>Wildcard implicit imports are never removed by this method, since
|
||||||
|
* they cannot be matched by simple name alone.</p>
|
||||||
|
*
|
||||||
|
* <p>This is typically called after the token-build pass to discard
|
||||||
|
* implicit imports that turned out to be unused.</p>
|
||||||
|
*
|
||||||
|
* @param usedSimpleNames the set of simple names actually referenced
|
||||||
|
* in the source; must not be {@code null}
|
||||||
|
*/
|
||||||
|
public synchronized void removeUnusedImplicitImports(Set<String> usedSimpleNames) {
|
||||||
|
if (usedSimpleNames == null) {
|
||||||
|
throw new IllegalArgumentException("usedSimpleNames must not be null");
|
||||||
|
}
|
||||||
|
boolean changed = false;
|
||||||
|
Iterator<ImportEntry> it = entries.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
ImportEntry entry = it.next();
|
||||||
|
if (entry.isImplicit && !entry.isWildcard
|
||||||
|
&& !usedSimpleNames.contains(entry.simpleName)) {
|
||||||
|
it.remove();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Utilities ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total number of import entries (explicit + implicit).
|
||||||
|
*
|
||||||
|
* @return the entry count
|
||||||
|
*/
|
||||||
|
public synchronized int size() {
|
||||||
|
return entries.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if there are no import entries.
|
||||||
|
*
|
||||||
|
* @return {@code true} when empty
|
||||||
|
*/
|
||||||
|
public synchronized boolean isEmpty() {
|
||||||
|
return entries.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current version counter.
|
||||||
|
*
|
||||||
|
* <p>The version is bumped on every mutation. External code can snapshot
|
||||||
|
* this value and later compare to detect whether the index has changed.</p>
|
||||||
|
*
|
||||||
|
* @return the current version (starts at 0, increments monotonically)
|
||||||
|
*/
|
||||||
|
public synchronized int version() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Internals ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the derived indexes as stale and increments the version counter.
|
||||||
|
* Must be called under the instance lock.
|
||||||
|
*/
|
||||||
|
private void markDirty() {
|
||||||
|
dirty = true;
|
||||||
|
version++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rebuilds the derived indexes if they are stale. Must be called under
|
||||||
|
* the instance lock.
|
||||||
|
*/
|
||||||
|
private void ensureIndexes() {
|
||||||
|
if (!dirty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Map<String, ImportEntry> newBySimpleName = new HashMap<String, ImportEntry>();
|
||||||
|
Map<String, ImportEntry> newByFullPath = new HashMap<String, ImportEntry>();
|
||||||
|
for (int i = 0, size = entries.size(); i < size; i++) {
|
||||||
|
ImportEntry entry = entries.get(i);
|
||||||
|
newByFullPath.put(entry.fullPath, entry);
|
||||||
|
// Only index non-wildcard entries by simple name; wildcard entries
|
||||||
|
// are handled by the fallback scan in resolveBySimpleName().
|
||||||
|
if (!entry.isWildcard) {
|
||||||
|
// Later entries with the same simple name win (last-import-wins
|
||||||
|
// semantics, matching javac behavior for duplicate imports).
|
||||||
|
newBySimpleName.put(entry.simpleName, entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.bySimpleName = newBySimpleName;
|
||||||
|
this.byFullPath = newByFullPath;
|
||||||
|
this.dirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ImportIndex{size=" + entries.size() + ", version=" + version + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||