@mmerterden/multi-agent-pipeline 23.3.0 → 23.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +44 -0
- package/README.md +25 -6
- package/README.tr.md +26 -7
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +5 -5
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/claude.mjs +28 -2
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +223 -155
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +49 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +28 -15
- package/pipeline/contract/types/index.d.ts +55 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +614 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
- package/pipeline/multi-agent-refs/features/remote-control.md +252 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +252 -24
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1207 -233
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +84 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +21 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +1 -0
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +317 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +188 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +21 -17
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file go.mjs - Go profile for the call-edge scanner.
|
|
3
|
+
*
|
|
4
|
+
* Methods hang off their receiver type, struct embedding promotes the embedded
|
|
5
|
+
* type's methods, an interface is satisfied structurally (a type with every
|
|
6
|
+
* method name of the interface is an implementer), and a package is a
|
|
7
|
+
* directory. Not modelled: generics constraints, method values, function-typed
|
|
8
|
+
* variables, and which of two same-named imports a build tag selects.
|
|
9
|
+
*
|
|
10
|
+
* @module pipeline/scripts/call-graph/lang/go
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { isIdent, readType, splitTop, tick } from "../lex.mjs";
|
|
14
|
+
|
|
15
|
+
const KEYWORDS = new Set(
|
|
16
|
+
`if for switch select case default return go defer func type struct interface map chan var const
|
|
17
|
+
range break continue fallthrough goto package import else nil true false iota make new len cap
|
|
18
|
+
append copy delete panic recover print println`.split(/\s+/),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
function readParams(tk, open) {
|
|
22
|
+
const params = [];
|
|
23
|
+
let min = 0;
|
|
24
|
+
let max = 0;
|
|
25
|
+
const parts = splitTop(tk, open);
|
|
26
|
+
const named = parts.some(
|
|
27
|
+
([a, b]) => isIdent(tk.t[a]) && b - a > 1 && tk.t[a + 1] !== "." && tk.t[a + 1] !== "[",
|
|
28
|
+
);
|
|
29
|
+
let pendingNames = [];
|
|
30
|
+
for (const [a, b] of parts) {
|
|
31
|
+
let k = a;
|
|
32
|
+
let variadic = false;
|
|
33
|
+
if (named && isIdent(tk.t[k]) && b - a === 1) {
|
|
34
|
+
pendingNames.push(tk.t[k]);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let name = null;
|
|
38
|
+
if (named && isIdent(tk.t[k])) {
|
|
39
|
+
name = tk.t[k];
|
|
40
|
+
k++;
|
|
41
|
+
}
|
|
42
|
+
if (tk.t[k] === "...") {
|
|
43
|
+
variadic = true;
|
|
44
|
+
k++;
|
|
45
|
+
}
|
|
46
|
+
const r = readType(tk, k, { limit: b });
|
|
47
|
+
const names = name ? [...pendingNames, name] : [null];
|
|
48
|
+
pendingNames = [];
|
|
49
|
+
for (const nm of names) {
|
|
50
|
+
params.push([nm, nm || "_", variadic && r.name ? `[${r.name}]` : r.name]);
|
|
51
|
+
if (variadic) max = Infinity;
|
|
52
|
+
else if (max !== Infinity) max++;
|
|
53
|
+
if (!variadic) min++;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { params, min, max };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readResult(tk, j, to) {
|
|
60
|
+
const t = tk.t;
|
|
61
|
+
if (t[j] === "(" && tk.m[j] > j) {
|
|
62
|
+
const parts = splitTop(tk, j);
|
|
63
|
+
if (!parts.length) return { ret: null, next: tk.m[j] + 1 };
|
|
64
|
+
const [first, b] = parts[0];
|
|
65
|
+
const named =
|
|
66
|
+
isIdent(t[first]) && b - first > 1 && t[first + 1] !== "." && t[first + 1] !== "[";
|
|
67
|
+
return { ret: readType(tk, named ? first + 1 : first, { limit: b }).name, next: tk.m[j] + 1 };
|
|
68
|
+
}
|
|
69
|
+
if (isIdent(t[j]) || t[j] === "*" || t[j] === "[") {
|
|
70
|
+
const r = readType(tk, j, { limit: to });
|
|
71
|
+
return { ret: r.name, next: r.next };
|
|
72
|
+
}
|
|
73
|
+
return { ret: null, next: j };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function parse(tk) {
|
|
77
|
+
const t = tk.t;
|
|
78
|
+
const types = [];
|
|
79
|
+
const fns = [];
|
|
80
|
+
|
|
81
|
+
const typeSpec = (i, to) => {
|
|
82
|
+
const name = t[i];
|
|
83
|
+
let j = i + 1;
|
|
84
|
+
if (t[j] === "[" && tk.m[j] > j) j = tk.m[j] + 1;
|
|
85
|
+
if (t[j] === "=") j++;
|
|
86
|
+
const kw = t[j];
|
|
87
|
+
if ((kw === "struct" || kw === "interface") && t[j + 1] === "{" && tk.m[j + 1] > j + 1) {
|
|
88
|
+
const open = j + 1;
|
|
89
|
+
const close = tk.m[open];
|
|
90
|
+
const sup = [];
|
|
91
|
+
const f = {};
|
|
92
|
+
let k = open + 1;
|
|
93
|
+
while (k < close) {
|
|
94
|
+
const lineEnd = (() => {
|
|
95
|
+
let e = k;
|
|
96
|
+
while (e < close && !(tk.first[e] === 1 && e > k)) e++;
|
|
97
|
+
return e;
|
|
98
|
+
})();
|
|
99
|
+
if (kw === "struct") {
|
|
100
|
+
if (isIdent(t[k]) && lineEnd - k >= 2 && t[k + 1] !== ".") {
|
|
101
|
+
const names = [];
|
|
102
|
+
let q = k;
|
|
103
|
+
while (isIdent(t[q]) && t[q + 1] === ",") {
|
|
104
|
+
names.push(t[q]);
|
|
105
|
+
q += 2;
|
|
106
|
+
}
|
|
107
|
+
if (isIdent(t[q])) {
|
|
108
|
+
names.push(t[q]);
|
|
109
|
+
const r = readType(tk, q + 1, { limit: lineEnd });
|
|
110
|
+
for (const nm of names) if (r.name) f[nm] = r.name;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const r = readType(tk, k, { skip: new Set(["*"]), limit: lineEnd });
|
|
114
|
+
if (r.name) sup.push(r.name);
|
|
115
|
+
}
|
|
116
|
+
} else if (isIdent(t[k]) && t[k + 1] === "(" && tk.m[k + 1] > k + 1) {
|
|
117
|
+
const sig = readParams(tk, k + 1);
|
|
118
|
+
const res = readResult(tk, tk.m[k + 1] + 1, lineEnd);
|
|
119
|
+
fns.push({
|
|
120
|
+
n: t[k],
|
|
121
|
+
o: name,
|
|
122
|
+
a: [sig.min, sig.max],
|
|
123
|
+
p: sig.params,
|
|
124
|
+
r: res.ret,
|
|
125
|
+
l: tk.line[k],
|
|
126
|
+
e: tk.line[k],
|
|
127
|
+
ab: 1,
|
|
128
|
+
body: null,
|
|
129
|
+
});
|
|
130
|
+
} else if (isIdent(t[k]) && lineEnd - k === 1) sup.push(t[k]);
|
|
131
|
+
k = Math.max(lineEnd, k + 1);
|
|
132
|
+
}
|
|
133
|
+
types.push({ n: name, k: kw, line: tk.line[i], end: tk.line[close], sup, f });
|
|
134
|
+
return tk.m[open] + 1;
|
|
135
|
+
}
|
|
136
|
+
const r = readType(tk, j, { limit: to });
|
|
137
|
+
types.push({
|
|
138
|
+
n: name,
|
|
139
|
+
k: "type",
|
|
140
|
+
line: tk.line[i],
|
|
141
|
+
end: tk.line[i],
|
|
142
|
+
sup: r.name ? [r.name] : [],
|
|
143
|
+
f: {},
|
|
144
|
+
});
|
|
145
|
+
return r.next;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
let i = 0;
|
|
149
|
+
while (i < tk.n) {
|
|
150
|
+
tick(tk);
|
|
151
|
+
const s = t[i];
|
|
152
|
+
if (s === "type" && tk.dep[i] === 0) {
|
|
153
|
+
if (t[i + 1] === "(" && tk.m[i + 1] > i + 1) {
|
|
154
|
+
let k = i + 2;
|
|
155
|
+
while (k < tk.m[i + 1]) {
|
|
156
|
+
if (isIdent(t[k]) && tk.first[k] === 1) k = typeSpec(k, tk.m[i + 1]);
|
|
157
|
+
else k++;
|
|
158
|
+
}
|
|
159
|
+
i = tk.m[i + 1] + 1;
|
|
160
|
+
} else if (isIdent(t[i + 1])) i = typeSpec(i + 1, tk.n);
|
|
161
|
+
else i++;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (s === "func" && tk.dep[i] === 0) {
|
|
165
|
+
let j = i + 1;
|
|
166
|
+
let owner = null;
|
|
167
|
+
let recvName = null;
|
|
168
|
+
let recvType = null;
|
|
169
|
+
if (t[j] === "(" && tk.m[j] > j) {
|
|
170
|
+
const parts = splitTop(tk, j);
|
|
171
|
+
if (parts.length) {
|
|
172
|
+
const [a, b] = parts[0];
|
|
173
|
+
let q = a;
|
|
174
|
+
if (isIdent(t[q]) && b - a > 1 && t[q + 1] !== ".") {
|
|
175
|
+
recvName = t[q];
|
|
176
|
+
q++;
|
|
177
|
+
}
|
|
178
|
+
recvType = readType(tk, q, { limit: b }).name;
|
|
179
|
+
owner = recvType;
|
|
180
|
+
}
|
|
181
|
+
j = tk.m[j] + 1;
|
|
182
|
+
}
|
|
183
|
+
if (isIdent(t[j])) {
|
|
184
|
+
const name = t[j];
|
|
185
|
+
j++;
|
|
186
|
+
if (t[j] === "[" && tk.m[j] > j) j = tk.m[j] + 1;
|
|
187
|
+
if (t[j] === "(" && tk.m[j] > j) {
|
|
188
|
+
const sig = readParams(tk, j);
|
|
189
|
+
const res = readResult(tk, tk.m[j] + 1, tk.n);
|
|
190
|
+
let k = res.next;
|
|
191
|
+
while (k < tk.n && t[k] !== "{" && !(tk.first[k] === 1)) k++;
|
|
192
|
+
const body = t[k] === "{" && tk.m[k] > k ? [k + 1, tk.m[k]] : null;
|
|
193
|
+
const params = recvName ? [[null, recvName, recvType], ...sig.params] : sig.params;
|
|
194
|
+
fns.push({
|
|
195
|
+
n: name,
|
|
196
|
+
o: owner,
|
|
197
|
+
a: [sig.min, sig.max],
|
|
198
|
+
p: params,
|
|
199
|
+
r: res.ret,
|
|
200
|
+
l: tk.line[i],
|
|
201
|
+
e: tk.line[body ? body[1] : i],
|
|
202
|
+
...(body ? {} : { ab: 1 }),
|
|
203
|
+
body,
|
|
204
|
+
});
|
|
205
|
+
i = body ? body[1] + 1 : k;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
i++;
|
|
211
|
+
}
|
|
212
|
+
return { types, fns, binds: [] };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function localDecl(tk, i, end) {
|
|
216
|
+
const t = tk.t;
|
|
217
|
+
const s = t[i];
|
|
218
|
+
if (s === "var" && isIdent(t[i + 1])) {
|
|
219
|
+
const name = t[i + 1];
|
|
220
|
+
let j = i + 2;
|
|
221
|
+
let type = null;
|
|
222
|
+
if (t[j] !== "=") {
|
|
223
|
+
const r = readType(tk, j, { limit: end });
|
|
224
|
+
type = r.name;
|
|
225
|
+
j = r.next;
|
|
226
|
+
}
|
|
227
|
+
if (t[j] === "=") return { name, type, init: j + 1, next: j + 1 };
|
|
228
|
+
return type ? { name, type, init: null, next: j } : null;
|
|
229
|
+
}
|
|
230
|
+
if (s === "for") {
|
|
231
|
+
let k = i + 1;
|
|
232
|
+
const names = [];
|
|
233
|
+
while (k < end && isIdent(t[k]) && (t[k + 1] === "," || t[k + 1] === ":=")) {
|
|
234
|
+
if (t[k] !== "_") names.push(t[k]);
|
|
235
|
+
k += 2;
|
|
236
|
+
}
|
|
237
|
+
if (names.length && t[k - 1] === ":=")
|
|
238
|
+
return { name: names[0], also: names.slice(1), type: null, init: null, next: k };
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
if (!isIdent(s) || KEYWORDS.has(s) || tk.first[i] !== 1) {
|
|
242
|
+
if (!(
|
|
243
|
+
isIdent(s) &&
|
|
244
|
+
(t[i - 1] === ";" || t[i - 1] === "{" || t[i - 1] === "if" || t[i - 1] === "switch")
|
|
245
|
+
))
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
const names = [];
|
|
249
|
+
let k = i;
|
|
250
|
+
while (isIdent(t[k]) && t[k + 1] === ",") {
|
|
251
|
+
names.push(t[k]);
|
|
252
|
+
k += 2;
|
|
253
|
+
}
|
|
254
|
+
if (!isIdent(t[k])) return null;
|
|
255
|
+
names.push(t[k]);
|
|
256
|
+
if (t[k + 1] !== ":=") return null;
|
|
257
|
+
const first = names[0] === "_" ? "_" : names[0];
|
|
258
|
+
return { name: first, also: names.slice(1), type: null, init: k + 2, next: k + 2 };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function binds(text) {
|
|
262
|
+
const out = [];
|
|
263
|
+
const add = (alias, path) => {
|
|
264
|
+
if (path.startsWith("C")) return;
|
|
265
|
+
const last = path.split("/").pop();
|
|
266
|
+
const l = alias || (/^v\d+$/.test(last) ? path.split("/").slice(-2)[0] : last);
|
|
267
|
+
if (l !== "_" && l !== ".") out.push({ l: l.replace(/-/g, "_"), m: path, x: null });
|
|
268
|
+
};
|
|
269
|
+
for (const m of text.matchAll(/^[ \t]*import\s+(?:([\w.]+)\s+)?"([^"]+)"/gm)) add(m[1], m[2]);
|
|
270
|
+
for (const block of text.matchAll(/^[ \t]*import[ \t]{0,4}\(([^)]{0,6000})\)/gm)) {
|
|
271
|
+
for (const m of block[1].matchAll(/^[ \t]*(?:([\w.]+)\s+)?"([^"]+)"/gm)) add(m[1], m[2]);
|
|
272
|
+
}
|
|
273
|
+
return out;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function moduleSuffixes(path) {
|
|
277
|
+
const segs = path.split("/");
|
|
278
|
+
const out = [];
|
|
279
|
+
for (let n = Math.min(3, segs.length); n >= 1; n--) out.push(`${segs.slice(-n).join("/")}/`);
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export default {
|
|
284
|
+
id: "go",
|
|
285
|
+
stringType: "string",
|
|
286
|
+
exts: [".go"],
|
|
287
|
+
implicitSelf: false,
|
|
288
|
+
initName: "New",
|
|
289
|
+
selfWords: new Set(),
|
|
290
|
+
superWords: new Set(),
|
|
291
|
+
newKeyword: null,
|
|
292
|
+
memberOps: new Set(["."]),
|
|
293
|
+
labelOps: [":"],
|
|
294
|
+
keywords: KEYWORDS,
|
|
295
|
+
declWords: new Set(["func", "type", "var", "const", "package", "import"]),
|
|
296
|
+
condWords: new Set(["if", "switch", "for"]),
|
|
297
|
+
structuralInterfaces: true,
|
|
298
|
+
keepStrings: true,
|
|
299
|
+
parse,
|
|
300
|
+
localDecl,
|
|
301
|
+
binds,
|
|
302
|
+
moduleSuffixes,
|
|
303
|
+
};
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file java.mjs - Java profile for the call-edge scanner.
|
|
3
|
+
*
|
|
4
|
+
* Also read for C# through the same member grammar (see csharp.mjs): a member is
|
|
5
|
+
* a run of modifiers, a type, a name, and either a parameter list or a field
|
|
6
|
+
* initialiser. Types resolve by simple name and the nearest package; two classes
|
|
7
|
+
* with one simple name in distant packages stay ambiguous. Not modelled:
|
|
8
|
+
* overloads that differ only by parameter type, lambdas' inferred parameter
|
|
9
|
+
* types, generics' bound methods and reflection.
|
|
10
|
+
*
|
|
11
|
+
* @module pipeline/scripts/call-graph/lang/java
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { isIdent, readType, skipAngles, tick, MAX_HEADER_TOKENS } from "../lex.mjs";
|
|
15
|
+
import { genericNames, skipAnnotations, typeList, paramsTypeFirst } from "./shared.mjs";
|
|
16
|
+
|
|
17
|
+
export const JAVA_MODS = new Set(
|
|
18
|
+
`public private protected static final abstract native synchronized transient volatile strictfp
|
|
19
|
+
default sealed non-sealed`.split(/\s+/),
|
|
20
|
+
);
|
|
21
|
+
const TYPE_KW = new Set(["class", "interface", "enum", "record", "@interface"]);
|
|
22
|
+
const KEYWORDS = new Set(
|
|
23
|
+
`if else for while do switch case default return throw throws try catch finally new instanceof
|
|
24
|
+
break continue class interface enum extends implements import package static public private
|
|
25
|
+
protected final abstract synchronized volatile transient native void int long short byte char
|
|
26
|
+
boolean double float true false null assert var`.split(/\s+/),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Member grammar shared by the C-family object languages.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} cfg
|
|
33
|
+
* @param {Set<string>} cfg.mods
|
|
34
|
+
* @param {Set<string>} cfg.typeKw
|
|
35
|
+
*/
|
|
36
|
+
export function makeParse(cfg) {
|
|
37
|
+
return function parse(tk) {
|
|
38
|
+
const t = tk.t;
|
|
39
|
+
const types = [];
|
|
40
|
+
const fns = [];
|
|
41
|
+
|
|
42
|
+
const lastTypeNamed = (name) => {
|
|
43
|
+
for (let n = types.length - 1; n >= 0; n--) if (types[n].n === name) return types[n];
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const walk = (from, to, owner, ownerKind) => {
|
|
48
|
+
let i = from;
|
|
49
|
+
let isStatic = false;
|
|
50
|
+
let isAbstract = false;
|
|
51
|
+
const thisParamExt = false;
|
|
52
|
+
void thisParamExt;
|
|
53
|
+
while (i < to) {
|
|
54
|
+
tick(tk);
|
|
55
|
+
i = skipAnnotations(tk, i);
|
|
56
|
+
if (cfg.skipAttributes) i = cfg.skipAttributes(tk, i);
|
|
57
|
+
const s = t[i];
|
|
58
|
+
if (s === undefined || i >= to) break;
|
|
59
|
+
if (s === "@") {
|
|
60
|
+
i++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (cfg.mods.has(s) && !cfg.typeKw.has(s)) {
|
|
64
|
+
if (s === "static") isStatic = true;
|
|
65
|
+
if (s === "abstract") isAbstract = true;
|
|
66
|
+
i++;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (cfg.namespaces && s === "namespace" && isIdent(t[i + 1])) {
|
|
70
|
+
let j = i + 2;
|
|
71
|
+
while (t[j] === "." && isIdent(t[j + 1])) j += 2;
|
|
72
|
+
if (t[j] === "{" && tk.m[j] > j) {
|
|
73
|
+
walk(j + 1, tk.m[j], null, null);
|
|
74
|
+
i = tk.m[j] + 1;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
i = j + 1;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (cfg.typeKw.has(s) && isIdent(t[i + 1])) {
|
|
81
|
+
i = typeDecl(i, to, owner, isAbstract, cfg.partialOf?.(tk, from, i));
|
|
82
|
+
isStatic = false;
|
|
83
|
+
isAbstract = false;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (owner && (isIdent(s) || s === "<" || s === "~")) {
|
|
87
|
+
const next = member(i, to, owner, ownerKind, isStatic, isAbstract);
|
|
88
|
+
if (next > i) {
|
|
89
|
+
i = next;
|
|
90
|
+
isStatic = false;
|
|
91
|
+
isAbstract = false;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (s === "{" && tk.m[i] > i) {
|
|
96
|
+
i = tk.m[i] + 1;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
isStatic = false;
|
|
100
|
+
isAbstract = false;
|
|
101
|
+
i++;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const typeDecl = (i, to, outer, isAbstract, partial) => {
|
|
106
|
+
const kw = t[i];
|
|
107
|
+
const name = t[i + 1];
|
|
108
|
+
let j = i + 2;
|
|
109
|
+
const g = genericNames(tk, j);
|
|
110
|
+
j = g.next;
|
|
111
|
+
const f = {};
|
|
112
|
+
let ctorSig = null;
|
|
113
|
+
if (kw === "record" && t[j] === "(" && tk.m[j] > j) {
|
|
114
|
+
ctorSig = paramsTypeFirst(tk, j);
|
|
115
|
+
for (const p of ctorSig.params) if (p[2] && p[1]) f[p[1]] = p[2];
|
|
116
|
+
j = tk.m[j] + 1;
|
|
117
|
+
}
|
|
118
|
+
const sup = [];
|
|
119
|
+
const lim = Math.min(to, j + MAX_HEADER_TOKENS);
|
|
120
|
+
while (j < lim && t[j] !== "{" && t[j] !== ";") {
|
|
121
|
+
if (t[j] === "extends" || t[j] === "implements" || t[j] === ":" || t[j] === "permits") {
|
|
122
|
+
let k = j + 1;
|
|
123
|
+
while (
|
|
124
|
+
k < lim &&
|
|
125
|
+
t[k] !== "{" &&
|
|
126
|
+
t[k] !== "implements" &&
|
|
127
|
+
t[k] !== "permits" &&
|
|
128
|
+
t[k] !== "where"
|
|
129
|
+
) {
|
|
130
|
+
k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
131
|
+
}
|
|
132
|
+
if (t[j] !== "permits") sup.push(...typeList(tk, j + 1, k, new Set(["new"])));
|
|
133
|
+
j = k;
|
|
134
|
+
} else if (t[j] === "where") {
|
|
135
|
+
while (j < lim && t[j] !== "{") j++;
|
|
136
|
+
} else j = tk.m[j] > j ? tk.m[j] + 1 : j + 1;
|
|
137
|
+
}
|
|
138
|
+
if (t[j] !== "{" || tk.m[j] < 0) return i + 2;
|
|
139
|
+
types.push({
|
|
140
|
+
n: name,
|
|
141
|
+
k: kw === "@interface" ? "interface" : kw === "record" ? "class" : kw,
|
|
142
|
+
line: tk.line[i],
|
|
143
|
+
end: tk.line[tk.m[j]],
|
|
144
|
+
sup,
|
|
145
|
+
...(outer ? { outer } : {}),
|
|
146
|
+
...(g.gen.length ? { gen: g.gen } : {}),
|
|
147
|
+
...(isAbstract && kw === "class" ? { abs: 1 } : {}),
|
|
148
|
+
...(partial ? { partial: 1 } : {}),
|
|
149
|
+
f,
|
|
150
|
+
});
|
|
151
|
+
if (ctorSig) {
|
|
152
|
+
fns.push({
|
|
153
|
+
n: "constructor",
|
|
154
|
+
o: name,
|
|
155
|
+
a: [ctorSig.min, ctorSig.max],
|
|
156
|
+
p: ctorSig.params,
|
|
157
|
+
r: name,
|
|
158
|
+
l: tk.line[i],
|
|
159
|
+
e: tk.line[i],
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
let from = j + 1;
|
|
163
|
+
if (kw === "enum") {
|
|
164
|
+
let k = from;
|
|
165
|
+
while (k < tk.m[j] && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
166
|
+
from = t[k] === ";" ? k + 1 : tk.m[j];
|
|
167
|
+
}
|
|
168
|
+
walk(from, tk.m[j], name, kw);
|
|
169
|
+
return tk.m[j] + 1;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const member = (i, to, owner, ownerKind, isStatic, isAbstract) => {
|
|
173
|
+
let j = i;
|
|
174
|
+
const g = genericNames(tk, j);
|
|
175
|
+
j = g.next;
|
|
176
|
+
if (cfg.ctorWord && t[j] === "~") j++;
|
|
177
|
+
const start = j;
|
|
178
|
+
// constructor: Name(
|
|
179
|
+
if (t[j] === owner && t[j + 1] === "(" && tk.m[j + 1] > j + 1) {
|
|
180
|
+
const sig = (cfg.params || paramsTypeFirst)(tk, j + 1, { mods: cfg.paramMods });
|
|
181
|
+
let k = tk.m[j + 1] + 1;
|
|
182
|
+
while (k < to && t[k] !== "{" && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
183
|
+
const body = t[k] === "{" && tk.m[k] > k ? [k + 1, tk.m[k]] : null;
|
|
184
|
+
fns.push({
|
|
185
|
+
n: "constructor",
|
|
186
|
+
o: owner,
|
|
187
|
+
a: [sig.min, sig.max],
|
|
188
|
+
p: sig.params,
|
|
189
|
+
r: owner,
|
|
190
|
+
l: tk.line[i],
|
|
191
|
+
e: tk.line[body ? body[1] : i],
|
|
192
|
+
body,
|
|
193
|
+
});
|
|
194
|
+
return body ? body[1] + 1 : k + 1;
|
|
195
|
+
}
|
|
196
|
+
const r = readType(tk, j, { skip: cfg.typeSkip });
|
|
197
|
+
if (!r.name && r.next === j) return i;
|
|
198
|
+
j = r.next;
|
|
199
|
+
while (t[j] === "[" && tk.m[j] === j + 1) j += 2;
|
|
200
|
+
if (!isIdent(t[j])) return i;
|
|
201
|
+
let name = t[j];
|
|
202
|
+
j++;
|
|
203
|
+
if (cfg.explicitImpl && t[j] === "." && isIdent(t[j + 1])) {
|
|
204
|
+
name = t[j + 1];
|
|
205
|
+
j += 2;
|
|
206
|
+
}
|
|
207
|
+
const g2 = genericNames(tk, j);
|
|
208
|
+
j = g2.next;
|
|
209
|
+
if (t[j] === "(" && tk.m[j] > j) {
|
|
210
|
+
const sig = (cfg.params || paramsTypeFirst)(tk, j, { mods: cfg.paramMods });
|
|
211
|
+
let k = tk.m[j] + 1;
|
|
212
|
+
while (k < to && t[k] !== "{" && t[k] !== ";" && t[k] !== "=>") {
|
|
213
|
+
if (t[k] === "where" || t[k] === "throws") {
|
|
214
|
+
k++;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
218
|
+
}
|
|
219
|
+
let body = null;
|
|
220
|
+
let next = k + 1;
|
|
221
|
+
if (t[k] === "{" && tk.m[k] > k) {
|
|
222
|
+
body = [k + 1, tk.m[k]];
|
|
223
|
+
next = tk.m[k] + 1;
|
|
224
|
+
} else if (t[k] === "=>") {
|
|
225
|
+
let e = k + 1;
|
|
226
|
+
while (e < to && t[e] !== ";") e = tk.m[e] > e ? tk.m[e] + 1 : e + 1;
|
|
227
|
+
body = [k + 1, e];
|
|
228
|
+
next = e + 1;
|
|
229
|
+
}
|
|
230
|
+
const thisExt = cfg.extensionThis && t[tk.m[j] > j ? j + 1 : j] === "this";
|
|
231
|
+
const extOwner = thisExt ? sig.params[0]?.[2] : null;
|
|
232
|
+
fns.push({
|
|
233
|
+
n: name,
|
|
234
|
+
o: extOwner || owner,
|
|
235
|
+
a: thisExt ? [Math.max(0, sig.min - 1), sig.max - 1] : [sig.min, sig.max],
|
|
236
|
+
p: thisExt ? sig.params.slice(1) : sig.params,
|
|
237
|
+
r: r.name,
|
|
238
|
+
l: tk.line[i],
|
|
239
|
+
e: tk.line[body ? Math.max(body[1], body[0]) : i],
|
|
240
|
+
...(isStatic && !thisExt ? { s: 1 } : {}),
|
|
241
|
+
...(!body || isAbstract ? { ab: 1 } : {}),
|
|
242
|
+
...(g.gen.length || g2.gen.length ? { g: [...g.gen, ...g2.gen] } : {}),
|
|
243
|
+
body,
|
|
244
|
+
});
|
|
245
|
+
return next;
|
|
246
|
+
}
|
|
247
|
+
const rec = lastTypeNamed(owner);
|
|
248
|
+
let fieldType = r.name;
|
|
249
|
+
if (rec && cfg.propertyBraces && t[j] === "{" && tk.m[j] > j) {
|
|
250
|
+
if (fieldType && fieldType !== "var") rec.f[name] = fieldType;
|
|
251
|
+
let k = tk.m[j] + 1;
|
|
252
|
+
if (t[k] === "=") while (k < to && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
253
|
+
return k + 1;
|
|
254
|
+
}
|
|
255
|
+
let k = j;
|
|
256
|
+
let init = null;
|
|
257
|
+
if (t[k] === "=") init = k + 1;
|
|
258
|
+
while (k < to && t[k] !== ";") k = tk.m[k] > k ? tk.m[k] + 1 : k + 1;
|
|
259
|
+
if (rec && name) {
|
|
260
|
+
if (
|
|
261
|
+
(!fieldType || fieldType === "var") &&
|
|
262
|
+
init &&
|
|
263
|
+
t[init] === "new" &&
|
|
264
|
+
isIdent(t[init + 1])
|
|
265
|
+
) {
|
|
266
|
+
fieldType = readType(tk, init + 1).name;
|
|
267
|
+
}
|
|
268
|
+
if (fieldType && fieldType !== "var") rec.f[name] = fieldType;
|
|
269
|
+
}
|
|
270
|
+
void start;
|
|
271
|
+
return k + 1;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
walk(0, tk.n, null, null);
|
|
275
|
+
return { types, fns, binds: [] };
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function localDecl(tk, i, end) {
|
|
280
|
+
const t = tk.t;
|
|
281
|
+
const s = t[i];
|
|
282
|
+
if (
|
|
283
|
+
KEYWORDS.has(s) &&
|
|
284
|
+
!["var", "final"].includes(s) &&
|
|
285
|
+
!["int", "long", "short", "byte", "char", "boolean", "double", "float"].includes(s)
|
|
286
|
+
)
|
|
287
|
+
return null;
|
|
288
|
+
let j = i;
|
|
289
|
+
while (t[j] === "final" || t[j] === "@") {
|
|
290
|
+
j = t[j] === "@" ? j + 2 : j + 1;
|
|
291
|
+
}
|
|
292
|
+
const r = readType(tk, j, { limit: end });
|
|
293
|
+
if (!r.name && r.next === j) return null;
|
|
294
|
+
let k = r.next;
|
|
295
|
+
while (t[k] === "[" && tk.m[k] === k + 1) k += 2;
|
|
296
|
+
if (!isIdent(t[k]) || KEYWORDS.has(t[k])) return null;
|
|
297
|
+
const name = t[k];
|
|
298
|
+
const nx = t[k + 1];
|
|
299
|
+
if (nx === "=") {
|
|
300
|
+
return { name, type: r.name === "var" ? null : r.name, init: k + 2, next: k + 2 };
|
|
301
|
+
}
|
|
302
|
+
if (nx === ";" || nx === "," || nx === ":")
|
|
303
|
+
return { name, type: r.name === "var" ? null : r.name, init: null, next: k + 1 };
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function lambdaParams(tk, i) {
|
|
308
|
+
const t = tk.t;
|
|
309
|
+
if (t[i] === "(" && tk.m[i] > i && t[tk.m[i] + 1] === "->") {
|
|
310
|
+
const params = [];
|
|
311
|
+
for (let k = i + 1; k < tk.m[i]; k++)
|
|
312
|
+
if (isIdent(t[k]) && (t[k + 1] === "," || k + 1 === tk.m[i])) params.push([t[k], null]);
|
|
313
|
+
return params.length ? { params } : null;
|
|
314
|
+
}
|
|
315
|
+
if (isIdent(t[i]) && t[i + 1] === "->") return { params: [[t[i], null]] };
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function castType(tk, open) {
|
|
320
|
+
const close = tk.m[open];
|
|
321
|
+
if (tk.t[open + 1] === "(" && tk.m[open + 1] > open + 1) {
|
|
322
|
+
return readType(tk, open + 2, { limit: tk.m[open + 1] }).name;
|
|
323
|
+
}
|
|
324
|
+
void close;
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function binds(text) {
|
|
329
|
+
const out = [];
|
|
330
|
+
for (const m of text.matchAll(/^[ \t]*import\s+(?:static\s+)?([\w.]+)(\.\*)?\s*;/gm)) {
|
|
331
|
+
const fqn = m[1];
|
|
332
|
+
const last = fqn.split(".").pop();
|
|
333
|
+
if (!m[2]) out.push({ l: last, m: fqn, x: null });
|
|
334
|
+
}
|
|
335
|
+
return out;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export default {
|
|
339
|
+
id: "java",
|
|
340
|
+
stringType: "String",
|
|
341
|
+
exts: [".java"],
|
|
342
|
+
implicitSelf: true,
|
|
343
|
+
initName: "constructor",
|
|
344
|
+
selfWords: new Set(["this"]),
|
|
345
|
+
superWords: new Set(["super"]),
|
|
346
|
+
newKeyword: "new",
|
|
347
|
+
memberOps: new Set(["."]),
|
|
348
|
+
labelOps: [],
|
|
349
|
+
keywords: KEYWORDS,
|
|
350
|
+
declWords: new Set([
|
|
351
|
+
"class",
|
|
352
|
+
"interface",
|
|
353
|
+
"enum",
|
|
354
|
+
"record",
|
|
355
|
+
"new",
|
|
356
|
+
"import",
|
|
357
|
+
"package",
|
|
358
|
+
"extends",
|
|
359
|
+
"implements",
|
|
360
|
+
"throws",
|
|
361
|
+
"instanceof",
|
|
362
|
+
]),
|
|
363
|
+
condWords: new Set(["for", "catch", "try", "("]),
|
|
364
|
+
castFn: castType,
|
|
365
|
+
parse: makeParse({ mods: JAVA_MODS, typeKw: TYPE_KW, paramMods: new Set(["final"]) }),
|
|
366
|
+
localDecl,
|
|
367
|
+
lambdaParams,
|
|
368
|
+
binds,
|
|
369
|
+
};
|
|
370
|
+
export { skipAngles };
|