feat(java): Phase 1.5 — tree-sitter Java frontend, package-aware mv, e2e fixtures
This commit is contained in:
parent
55670030c3
commit
603f916ee9
25 changed files with 1288 additions and 366 deletions
|
|
@ -76,6 +76,33 @@ jmove never overwrites: free the destination (or pick another name) and
|
|||
retry. A missing source reports `SOURCE_NOT_FOUND` the same way, and a
|
||||
file nobody imports simply moves with zero rewrites.
|
||||
|
||||
### Java: package + imports + move in one step
|
||||
|
||||
Java couples the `package` declaration to the directory layout, so a move
|
||||
is three coordinated edits — jmove makes all of them:
|
||||
|
||||
```console
|
||||
$ jmove mv src/main/java/com/example/util/Text.java src/main/java/com/example/core/Text.java --dry-run
|
||||
--- src/main/java/com/example/app/App.java
|
||||
+++ src/main/java/com/example/app/App.java
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.example.app;
|
||||
|
||||
-import com.example.util.Text;
|
||||
-import static com.example.util.Text.shout;
|
||||
+import com.example.core.Text;
|
||||
+import static com.example.core.Text.shout;
|
||||
...
|
||||
move src/main/java/com/example/util/Text.java -> src/main/java/com/example/core/Text.java
|
||||
$ jmove mv src/main/java/com/example/util/Text.java src/main/java/com/example/core/Text.java
|
||||
moved src/main/java/com/example/util/Text.java -> src/main/java/com/example/core/Text.java, updated 4 imports in 3 files
|
||||
```
|
||||
|
||||
The `3 files` include the moved file itself: its `package` line is the
|
||||
fourth rewrite. Targets outside the source root, non-`.java` targets and
|
||||
cross-directory moves of default-package classes are rejected with
|
||||
`PLAN_REJECTED` (exit 1) and change nothing.
|
||||
|
||||
## AI-agent usage (`--json`)
|
||||
|
||||
Every `--json` response is a flat envelope: `status` (`"ok"` | `"dry_run"`
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
Moves or renames source files inside a project and updates every import
|
||||
statement referencing them. Never breaks imports. Supported: TypeScript,
|
||||
JavaScript; Java/Python/Go on the roadmap. Single binary, no LSP needed.
|
||||
JavaScript, Java (package declaration + all importers + the file move are
|
||||
kept in sync); Python/Go on the roadmap. Single binary, no LSP needed.
|
||||
|
||||
## When to use
|
||||
|
||||
|
|
@ -32,6 +33,20 @@ jmove check [--root DIR] [--json]
|
|||
|
||||
Run after any move (or any edit) to validate project consistency.
|
||||
|
||||
## Java specifics
|
||||
|
||||
- Moving a `.java` file rewrites three coordinated edits: its own
|
||||
`package` declaration, every `import <fqn>` naming the class (static
|
||||
member imports keep their member suffix) and the physical move.
|
||||
- The target must be a `.java` path under the same source root
|
||||
(`src/main/java`, `src`, …) and its directory maps to the new package.
|
||||
Anything else exits `1` with code `PLAN_REJECTED`.
|
||||
- A class in the default package (no `package` declaration) can only be
|
||||
renamed inside its directory.
|
||||
- `check` never reports unresolved Java imports (jdk, third-party,
|
||||
`pkg.*`) as broken — they are external by design, like TS bare
|
||||
specifiers.
|
||||
|
||||
## Recommended agent workflow
|
||||
|
||||
1. `jmove mv <src> <target> --dry-run --json` — preview.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue