@kaluchi/jdtbridge 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ import { get } from "../client.mjs";
2
+ import { parseFlags } from "../args.mjs";
3
+ import { stripProject, toWsPath } from "../paths.mjs";
4
+ import { red, yellow } from "../color.mjs";
5
+
6
+ export async function errors(args) {
7
+ const flags = parseFlags(args);
8
+ const params = [];
9
+ if (flags.file) params.push(`file=${encodeURIComponent(toWsPath(flags.file))}`);
10
+ if (flags.project) params.push(`project=${encodeURIComponent(flags.project)}`);
11
+ if (flags.warnings) params.push("warnings");
12
+ if (flags.all) params.push("all");
13
+
14
+ let url = "/errors";
15
+ if (params.length > 0) url += "?" + params.join("&");
16
+ const results = await get(url, 180_000);
17
+ if (results.error) {
18
+ console.error(results.error);
19
+ process.exit(1);
20
+ }
21
+ if (results.length === 0) {
22
+ console.log("(no errors)");
23
+ return;
24
+ }
25
+
26
+ for (const r of results) {
27
+ const sev = r.severity === "ERROR" ? red("ERROR") : yellow("WARN ");
28
+ const src = r.source ? `[${r.source}] ` : "";
29
+ console.log(`${sev} ${src}${stripProject(r.file)}:${r.line} ${r.message}`);
30
+ }
31
+ }
32
+
33
+ export const help = `Check compilation errors and diagnostics.
34
+
35
+ Usage: jdt errors [--file <path>] [--project <name>]
36
+ [--warnings] [--all]
37
+
38
+ Scope (pick one or omit for entire workspace):
39
+ --file <path> single file (workspace-relative)
40
+ --project <name> entire project
41
+
42
+ Options:
43
+ --warnings include warnings (default: errors only)
44
+ --all all marker types (jdt + checkstyle + maven + ...)
45
+
46
+ Refreshes from disk and waits for auto-build before reading markers.
47
+ Use 'jdt build' to trigger explicit builds.
48
+
49
+ Examples:
50
+ jdt errors --project m8-server
51
+ jdt errors --file m8-server/src/main/java/.../Foo.java
52
+ jdt errors --project m8-server --all --warnings`;
@@ -0,0 +1,41 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional } from "../args.mjs";
3
+ import { stripProject } from "../paths.mjs";
4
+
5
+ export async function find(args) {
6
+ const pos = extractPositional(args);
7
+ const name = pos[0];
8
+ if (!name) {
9
+ console.error("Usage: find <Name|Pattern> [--source-only]");
10
+ process.exit(1);
11
+ }
12
+ let url = `/find?name=${encodeURIComponent(name)}`;
13
+ if (args.includes("--source-only")) url += "&source";
14
+ const results = await get(url, 30_000);
15
+ if (results.error) {
16
+ console.error(results.error);
17
+ process.exit(1);
18
+ }
19
+ if (results.length === 0) {
20
+ console.log("(no results)");
21
+ return;
22
+ }
23
+ for (const r of results) {
24
+ console.log(`${r.fqn} ${stripProject(r.file)}`);
25
+ }
26
+ }
27
+
28
+ export const help = `Find type declarations by name or wildcard pattern.
29
+
30
+ Usage: jdt find <Name|*Pattern*> [--source-only]
31
+
32
+ Arguments:
33
+ Name exact type name (e.g. DataSourceUtils)
34
+ *Pattern* wildcard pattern (e.g. *Controller*, Find*)
35
+
36
+ Flags:
37
+ --source-only exclude binary/library types, show only workspace sources
38
+
39
+ Examples:
40
+ jdt find DataSourceUtils
41
+ jdt find *Controller* --source-only`;
@@ -0,0 +1,48 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional } from "../args.mjs";
3
+ import { stripProject } from "../paths.mjs";
4
+ import { bold } from "../color.mjs";
5
+
6
+ export async function hierarchy(args) {
7
+ const pos = extractPositional(args);
8
+ const fqn = pos[0];
9
+ if (!fqn) {
10
+ console.error("Usage: hierarchy <FQN>");
11
+ process.exit(1);
12
+ }
13
+ const result = await get(
14
+ `/hierarchy?class=${encodeURIComponent(fqn)}`,
15
+ 30_000,
16
+ );
17
+ if (result.error) {
18
+ console.error(result.error);
19
+ process.exit(1);
20
+ }
21
+ if (result.supers.length > 0) {
22
+ console.log(bold("Superclasses:"));
23
+ for (const s of result.supers) {
24
+ const loc = s.binary ? "(binary)" : stripProject(s.file);
25
+ console.log(` ${s.fqn} ${loc}`);
26
+ }
27
+ }
28
+ if (result.interfaces.length > 0) {
29
+ console.log(bold("Interfaces:"));
30
+ for (const s of result.interfaces) {
31
+ const loc = s.binary ? "(binary)" : stripProject(s.file);
32
+ console.log(` ${s.fqn} ${loc}`);
33
+ }
34
+ }
35
+ if (result.subtypes.length > 0) {
36
+ console.log(bold("Subtypes:"));
37
+ for (const s of result.subtypes) {
38
+ const loc = s.binary ? "(binary)" : stripProject(s.file);
39
+ console.log(` ${s.fqn} ${loc}`);
40
+ }
41
+ }
42
+ }
43
+
44
+ export const help = `Show full type hierarchy: superclasses, interfaces, and subtypes.
45
+
46
+ Usage: jdt hierarchy <FQN>
47
+
48
+ Example: jdt hierarchy app.m8.web.client.AGMEntryPoint`;
@@ -0,0 +1,34 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional, parseFlags } from "../args.mjs";
3
+ import { stripProject } from "../paths.mjs";
4
+
5
+ export async function implementors(args) {
6
+ const pos = extractPositional(args);
7
+ const flags = parseFlags(args);
8
+ const [fqn, method] = pos;
9
+ if (!fqn || !method) {
10
+ console.error("Usage: implementors <FQN> <method> [--arity n]");
11
+ process.exit(1);
12
+ }
13
+ let url = `/implementors?class=${encodeURIComponent(fqn)}&method=${encodeURIComponent(method)}`;
14
+ if (flags.arity !== undefined && flags.arity !== true)
15
+ url += `&arity=${flags.arity}`;
16
+ const results = await get(url, 30_000);
17
+ if (results.error) {
18
+ console.error(results.error);
19
+ process.exit(1);
20
+ }
21
+ if (results.length === 0) {
22
+ console.log("(no implementors)");
23
+ return;
24
+ }
25
+ for (const r of results) {
26
+ console.log(`${r.fqn} ${stripProject(r.file)}:${r.line}`);
27
+ }
28
+ }
29
+
30
+ export const help = `Find implementations of an interface method across all implementing classes.
31
+
32
+ Usage: jdt implementors <FQN> <method> [--arity <n>]
33
+
34
+ Example: jdt implementors app.m8.web.shared.core.HasId getId`;
@@ -0,0 +1,45 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional, parseFlags } from "../args.mjs";
3
+ import { formatProjectInfo } from "../format/project-info.mjs";
4
+
5
+ export async function projectInfo(args) {
6
+ const pos = extractPositional(args);
7
+ const flags = parseFlags(args);
8
+ const name = pos[0];
9
+ if (!name) {
10
+ console.error(
11
+ "Usage: project-info <name> [--lines N] [--members-threshold N]",
12
+ );
13
+ process.exit(1);
14
+ }
15
+ let url = `/project-info?project=${encodeURIComponent(name)}`;
16
+ if (flags["members-threshold"])
17
+ url += `&members-threshold=${flags["members-threshold"]}`;
18
+ const result = await get(url, 30_000);
19
+ if (result.error) {
20
+ console.error(result.error);
21
+ process.exit(1);
22
+ }
23
+ const maxLines = parseInt(flags.lines) || 50;
24
+ console.log(formatProjectInfo(result, maxLines));
25
+ }
26
+
27
+ export const help = `Show project overview with adaptive detail level.
28
+
29
+ Usage: jdt project-info <name> [--lines N] [--members-threshold N]
30
+
31
+ Arguments:
32
+ name Eclipse project name (e.g. m8-server, io.github.kaluchi.jdtbridge)
33
+
34
+ Flags:
35
+ --lines <N> max output lines (default: 50)
36
+ --members-threshold <N> include method signatures when totalTypes <= N (default: 200)
37
+
38
+ Detail adapts to --lines budget:
39
+ - Small budget: location + source roots + dependencies + package list
40
+ - Medium budget: + type names per package
41
+ - Large budget: + method signatures per type (if server included them)
42
+
43
+ Examples:
44
+ jdt project-info m8-server
45
+ jdt project-info m8-server --lines 100`;
@@ -0,0 +1,16 @@
1
+ import { get } from "../client.mjs";
2
+
3
+ export async function projects() {
4
+ const results = await get("/projects");
5
+ if (results.error) {
6
+ console.error(results.error);
7
+ process.exit(1);
8
+ }
9
+ for (const p of results) console.log(p);
10
+ }
11
+
12
+ export const help = `List all Java projects in the Eclipse workspace.
13
+
14
+ Usage: jdt projects
15
+
16
+ Output: one project name per line.`;
@@ -0,0 +1,116 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional, parseFlags } from "../args.mjs";
3
+ import { toWsPath } from "../paths.mjs";
4
+ import { green, yellow } from "../color.mjs";
5
+
6
+ export async function organizeImports(args) {
7
+ const pos = extractPositional(args);
8
+ const filePath = pos[0];
9
+ if (!filePath) {
10
+ console.error("Usage: organize-imports <workspace-relative-path>");
11
+ process.exit(1);
12
+ }
13
+ const result = await get(
14
+ `/organize-imports?file=${encodeURIComponent(toWsPath(filePath))}`,
15
+ 30_000,
16
+ );
17
+ if (result.error) {
18
+ console.error(result.error);
19
+ process.exit(1);
20
+ }
21
+ console.log(`Imports: +${result.added} -${result.removed}`);
22
+ }
23
+
24
+ export async function format(args) {
25
+ const pos = extractPositional(args);
26
+ const filePath = pos[0];
27
+ if (!filePath) {
28
+ console.error("Usage: format <workspace-relative-path>");
29
+ process.exit(1);
30
+ }
31
+ const result = await get(
32
+ `/format?file=${encodeURIComponent(toWsPath(filePath))}`,
33
+ 30_000,
34
+ );
35
+ if (result.error) {
36
+ console.error(result.error);
37
+ process.exit(1);
38
+ }
39
+ if (result.modified) {
40
+ console.log(green("Formatted"));
41
+ } else {
42
+ console.log(`No changes${result.reason ? ": " + result.reason : ""}`);
43
+ }
44
+ }
45
+
46
+ export async function rename(args) {
47
+ const pos = extractPositional(args);
48
+ const flags = parseFlags(args);
49
+ const fqn = pos[0];
50
+ const newName = pos[1];
51
+ if (!fqn || !newName) {
52
+ console.error(
53
+ "Usage: rename <FQN> <newName> [--field name] [--method name] [--arity n]",
54
+ );
55
+ process.exit(1);
56
+ }
57
+ let url = `/rename?class=${encodeURIComponent(fqn)}&newName=${encodeURIComponent(newName)}`;
58
+ if (flags.field) url += `&field=${encodeURIComponent(flags.field)}`;
59
+ if (flags.method) url += `&method=${encodeURIComponent(flags.method)}`;
60
+ if (flags.arity !== undefined && flags.arity !== true)
61
+ url += `&arity=${flags.arity}`;
62
+ const result = await get(url, 30_000);
63
+ if (result.error) {
64
+ console.error(result.error);
65
+ process.exit(1);
66
+ }
67
+ console.log(green("Renamed"));
68
+ if (result.warnings) {
69
+ for (const w of result.warnings) console.log(yellow(` warning: ${w}`));
70
+ }
71
+ }
72
+
73
+ export async function move(args) {
74
+ const pos = extractPositional(args);
75
+ const [fqn, target] = pos;
76
+ if (!fqn || !target) {
77
+ console.error("Usage: move <FQN> <target.package>");
78
+ process.exit(1);
79
+ }
80
+ const url = `/move?class=${encodeURIComponent(fqn)}&target=${encodeURIComponent(target)}`;
81
+ const result = await get(url, 30_000);
82
+ if (result.error) {
83
+ console.error(result.error);
84
+ process.exit(1);
85
+ }
86
+ console.log(green("Moved"));
87
+ if (result.warnings) {
88
+ for (const w of result.warnings) console.log(yellow(` warning: ${w}`));
89
+ }
90
+ }
91
+
92
+ export const organizeImportsHelp = `Organize imports in a Java file.
93
+
94
+ Usage: jdt organize-imports <file>
95
+
96
+ Example: jdt organize-imports m8-server/src/main/java/.../Foo.java`;
97
+
98
+ export const formatHelp = `Format a Java file using Eclipse project settings.
99
+
100
+ Usage: jdt format <file>
101
+
102
+ Example: jdt format m8-server/src/main/java/.../Foo.java`;
103
+
104
+ export const renameHelp = `Rename a type, method, or field (updates all references).
105
+
106
+ Usage: jdt rename <FQN> <newName> [--method <old>] [--field <old>] [--arity <n>]
107
+
108
+ Examples:
109
+ jdt rename app.m8.dto.Foo Bar
110
+ jdt rename app.m8.dto.Foo getBar --method getFoo`;
111
+
112
+ export const moveHelp = `Move a type to another package (updates all references).
113
+
114
+ Usage: jdt move <FQN> <target.package>
115
+
116
+ Example: jdt move app.m8.dto.Foo app.m8.dto.shared`;
@@ -0,0 +1,51 @@
1
+ import { get } from "../client.mjs";
2
+ import { extractPositional, parseFlags } from "../args.mjs";
3
+ import { formatReferences } from "../format/references.mjs";
4
+
5
+ export async function references(args) {
6
+ const pos = extractPositional(args);
7
+ const flags = parseFlags(args);
8
+ const fqn = pos[0];
9
+ if (!fqn) {
10
+ console.error("Usage: references <FQN> [method] [--field name] [--arity n]");
11
+ process.exit(1);
12
+ }
13
+ let url = `/references?class=${encodeURIComponent(fqn)}`;
14
+ if (flags.field) {
15
+ url += `&field=${encodeURIComponent(flags.field)}`;
16
+ } else {
17
+ const method = pos[1];
18
+ if (method) url += `&method=${encodeURIComponent(method)}`;
19
+ }
20
+ if (flags.arity !== undefined && flags.arity !== true)
21
+ url += `&arity=${flags.arity}`;
22
+ const results = await get(url, 30_000);
23
+ if (results.error) {
24
+ console.error(results.error);
25
+ process.exit(1);
26
+ }
27
+ if (results.length === 0) {
28
+ console.log("(no references)");
29
+ return;
30
+ }
31
+ formatReferences(results);
32
+ }
33
+
34
+ export const help = `Find all references to a type, method, or field across the workspace.
35
+
36
+ Usage: jdt references <FQN> [method]
37
+ jdt references <FQN> --field <name>
38
+ jdt references <FQN> [method] --arity <n>
39
+
40
+ Arguments:
41
+ FQN fully qualified class name
42
+ method method name (optional)
43
+
44
+ Flags:
45
+ --field <name> find references to a field
46
+ --arity <n> disambiguate overloaded methods by parameter count
47
+
48
+ Examples:
49
+ jdt references app.m8.dto.web.core.IdOrgRoot
50
+ jdt references app.m8.dao.StaffDaoImpl getStaff
51
+ jdt references app.m8.dao.StaffDaoImpl --field staffCache`;