-
Notifications
You must be signed in to change notification settings - Fork 0
Add json-java21-jdt module for JSON Document Transforms #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3faec69
Issue #136 Document experimental JTD ESM codegen CLI
cursoragent 7b71cc5
Issue #136 Add jtd-esm-codegen module and CLI generator
cursoragent 82d8ddd
Issue #136 Fix JTD AST packaging to avoid javac warnings
cursoragent 5975aab
Issue #136 Add nightly release workflow for jtd-esm-codegen
cursoragent be9c170
Issue #136 Make generated ESM output deterministic
cursoragent 9c9d5e2
exhaustive tests
simbo1905 b19a9f7
Replace bun with junit-js for JS tests; fix inline validator generati…
simbo1905 52f92e1
Update CI test count to reflect new junit-js tests (639 total, 5 skip…
simbo1905 d058788
Refactor JtdToEsmCodegenTest to use GraalVM Polyglot instead of bun
simbo1905 c1805a9
JTD bytecode codegen via ClassFile API + RFC 8927 conformance
simbo1905 4364b0f
son-java21-transforms
simbo1905 a80cc68
Rename json-java21-transforms to json-java21-jdt (JSON Document Trans…
simbo1905 4f8e79f
Update CI test count to 673 tests, 0 skipped (added 33 JDT tests, 1 j…
simbo1905 a6195f0
Add .DS_Store to .gitignore and create README.md and AGENTS.md for js…
simbo1905 5be3a28
Clarify JDT means JSON Document Transforms, not Eclipse JDT
simbo1905 f629733
Merge origin/jtd-gen into jdt-transforms (resolve pom.xml module list…
simbo1905 3ca2b83
Add json-java21-jsonpath-codegen module: bytecode-generated JsonPath …
simbo1905 91cabac
Fix CI: exclude Java 24+ codegen modules from Java 21 build, fix logg…
simbo1905 8f8f5a3
Update CI test count to 1018 (JTD property tests expand in surefire XML)
simbo1905 c0452aa
Make JDT path resolution pluggable for compiled JsonPath support
simbo1905 40dd65c
Add JDT AST sealed interface hierarchy and parser
simbo1905 f39d837
Add JsonPath ESM renderer: AST to ES2020 module codegen
simbo1905 b96335a
Add JDT ESM renderer: AST to ES2020 module codegen
simbo1905 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| name: JTD-ESM-Codegen Nightly | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 3 * * *' # 3 AM UTC daily | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| build-uber-jar: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-java@v4 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
| cache: 'maven' | ||
| - name: Build uber JAR | ||
| run: | | ||
| ./mvnw -pl jtd-esm-codegen -am package | ||
| cp jtd-esm-codegen/target/jtd-esm-codegen.jar jtd-esm-codegen.jar | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: uber-jar | ||
| path: jtd-esm-codegen.jar | ||
|
|
||
| native-linux: | ||
| needs: build-uber-jar | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: uber-jar | ||
| path: . | ||
| - uses: graalvm/setup-graalvm@v1 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'graalvm' | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| components: 'native-image' | ||
| cache: 'maven' | ||
| - name: Build native image | ||
| run: | | ||
| native-image --no-fallback -jar jtd-esm-codegen.jar jtd-esm-codegen-linux-amd64 | ||
| chmod +x jtd-esm-codegen-linux-amd64 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: native-linux-amd64 | ||
| path: jtd-esm-codegen-linux-amd64 | ||
|
|
||
| native-windows: | ||
| needs: build-uber-jar | ||
| runs-on: windows-latest | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: uber-jar | ||
| path: . | ||
| - uses: graalvm/setup-graalvm@v1 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'graalvm' | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| components: 'native-image' | ||
| cache: 'maven' | ||
| - name: Build native image | ||
| run: | | ||
| native-image --no-fallback -jar jtd-esm-codegen.jar jtd-esm-codegen-windows-amd64 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: native-windows-amd64 | ||
| path: jtd-esm-codegen-windows-amd64.exe | ||
|
|
||
| native-macos-intel: | ||
| needs: build-uber-jar | ||
| runs-on: macos-13 # Intel | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: uber-jar | ||
| path: . | ||
| - uses: graalvm/setup-graalvm@v1 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'graalvm' | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| components: 'native-image' | ||
| cache: 'maven' | ||
| - name: Build native image | ||
| run: | | ||
| native-image --no-fallback -jar jtd-esm-codegen.jar jtd-esm-codegen-macos-amd64 | ||
| chmod +x jtd-esm-codegen-macos-amd64 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: native-macos-amd64 | ||
| path: jtd-esm-codegen-macos-amd64 | ||
|
|
||
| native-macos-arm: | ||
| needs: build-uber-jar | ||
| runs-on: macos-14 # Apple Silicon | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| name: uber-jar | ||
| path: . | ||
| - uses: graalvm/setup-graalvm@v1 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'graalvm' | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| components: 'native-image' | ||
| cache: 'maven' | ||
| - name: Build native image | ||
| run: | | ||
| native-image --no-fallback -jar jtd-esm-codegen.jar jtd-esm-codegen-macos-arm64 | ||
| chmod +x jtd-esm-codegen-macos-arm64 | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: native-macos-arm64 | ||
| path: jtd-esm-codegen-macos-arm64 | ||
|
|
||
| release: | ||
| needs: [native-linux, native-windows, native-macos-intel, native-macos-arm] | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| - name: Create nightly release | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| tag_name: nightly-${{ github.run_number }} | ||
| name: Nightly Build ${{ github.run_number }} | ||
| prerelease: true | ||
| files: | | ||
| native-linux-amd64/jtd-esm-codegen-linux-amd64 | ||
| native-windows-amd64/jtd-esm-codegen-windows-amd64.exe | ||
| native-macos-amd64/jtd-esm-codegen-macos-amd64 | ||
| native-macos-arm64/jtd-esm-codegen-macos-arm64 | ||
| uber-jar/jtd-esm-codegen.jar | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,7 @@ pom.xml.versionsBackup | |
| # Local JTD debug logs | ||
| jtd*.log | ||
| **/jtd*.log | ||
|
|
||
| # macOS metadata | ||
| .DS_Store | ||
| **/.DS_Store | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # json-java21-jdt/AGENTS.md | ||
|
|
||
| This file is for contributor/agent operational notes. Read `json-java21-jdt/README.md` for purpose, supported syntax, and user-facing examples. | ||
|
|
||
| ## CRITICAL: What "JDT" Means in This Project | ||
|
|
||
| **JDT stands for "JSON Document Transforms"** -- a C# technology from Microsoft that we are porting to Java. It has NOTHING to do with Eclipse JDT (Java Development Tools). There are NO Eclipse files in this module. Do not confuse `json-java21-jdt` with Eclipse tooling. Every file in this module relates exclusively to JSON Document Transforms. | ||
|
|
||
| - User docs MUST recommend only `./mvnw`. | ||
| - The `$(command -v mvnd || command -v mvn || command -v ./mvnw)` wrapper is for local developer speed only; do not put it in user-facing docs. | ||
|
|
||
| ## Stable Code Entry Points | ||
|
|
||
| - `json-java21-jdt/src/main/java/json/java21/jdt/Jdt.java` -- Public API: `Jdt.transform(source, transform)` | ||
| - `json-java21-jdt/src/main/java/json/java21/jdt/JdtException.java` -- Exception for invalid transforms | ||
|
|
||
| ## Dependencies | ||
|
|
||
| - **`json-java21`** (core): The `JsonValue` sealed type hierarchy (`jdk.sandbox.java.util.json.*`) | ||
| - **`json-java21-jsonpath`**: `JsonPath.parse(path).query(source)` for `@jdt.path`-based operations | ||
|
|
||
| Both are compile-time dependencies. Changes to either module's public API may require updates here. | ||
|
|
||
| ## Architecture Notes | ||
|
|
||
| ### Current Implementation (Static Walker) | ||
|
|
||
| The engine currently has **no AST**. It works directly on `JsonValue` trees, interpreting `@jdt.*` keys on-the-fly via a recursive static-method walker: | ||
|
|
||
| 1. `Jdt.transform(source, transform)` -- public entry point | ||
| 2. `applyTransform(source, transform)` -- dispatches: non-object replaces, object checks for `@jdt.*` directives | ||
| 3. `applyJdtDirectives(source, transformObj)` -- applies verbs in order: Rename -> Remove -> Merge -> Replace | ||
| 4. Non-JDT keys in the transform object are processed as recursive default-merge operations | ||
|
|
||
| ### Path-Based Operations | ||
|
|
||
| Path operations follow the pattern: | ||
| 1. Parse JSONPath string: `JsonPath.parse(pathString)` | ||
| 2. Query source: `jsonPath.query(source)` returns `List<JsonValue>` | ||
| 3. Transform matched nodes using reference identity (`node == match`) to find and replace | ||
|
|
||
| **Known limitation**: Reference identity matching is fragile. It works only because JsonPath returns the exact same object instances from the source tree (not copies). | ||
|
|
||
| ### Incomplete Features | ||
|
|
||
| - **Path-based rename**: `applyRenameWithPath` is a stub (returns source unchanged). The TODO is at `Jdt.java:234`. | ||
| - **~20 skipped Microsoft fixtures**: All path-based operation fixtures are in `Skipped/` subdirectories. | ||
|
|
||
| ## Transform Verb Processing | ||
|
|
||
| Directive | Method | Notes | ||
| ---|---|--- | ||
| `@jdt.rename` | `applyRename` -> `applyRenameMapping` / `applyRenameWithPath` | Path-based is a stub | ||
| `@jdt.remove` | `applyRemove` -> `removeKey` / `applyRemoveWithPath` | Path-based uses `removeMatchedNodes` | ||
| `@jdt.merge` | `applyMerge` -> `mergeObjects` / `applyMergeWithPath` | Supports double-bracket arrays | ||
| `@jdt.replace` | `applyReplace` -> `applyReplaceWithPath` | Supports double-bracket arrays | ||
|
|
||
| ## Test Fixtures | ||
|
|
||
| Microsoft JDT fixtures are vendored into: | ||
| ``` | ||
| json-java21-jdt/src/test/resources/microsoft-json-document-transforms/Inputs/ | ||
| ``` | ||
|
|
||
| Convention: `{Category}.Source.json` + `{TestName}.Transform.json` + `{TestName}.Expected.json` | ||
|
|
||
| Fixtures in `Skipped/` subdirectories are excluded by `MicrosoftJdtFixturesTest` (line 42 filter). Move fixtures out of `Skipped/` as path-based operations are implemented. | ||
|
|
||
| ## When Changing Transform Behavior | ||
|
|
||
| - Update `Jdt.java` (the engine). | ||
| - Add unit tests in `JdtTest.java` for the new behavior. | ||
| - Move applicable fixtures from `Skipped/` to the active directory if path-based operations are now supported. | ||
| - New tests MUST extend `JdtLoggingConfig`. | ||
| - Verify the full build passes: test counts in `.github/workflows/ci.yml` must match. | ||
|
|
||
| ## Future Direction: AST and Code Generation | ||
|
|
||
| The planned evolution follows the same pattern as `jtd-esm-codegen`: | ||
|
|
||
| 1. **Parse** the transform JSON into a sealed JDT AST (algebraic data types) | ||
| 2. **Walk the AST** with exhaustive switch expressions to generate code | ||
| 3. **Bytecode codegen**: Compile JDT transforms into generated Java classes | ||
| 4. **ESM codegen**: Generate ES2020 JavaScript modules from the JDT AST | ||
| 5. **Compiled JSONPath**: Replace the static JsonPath walker with compiled functions | ||
|
|
||
| This aligns with the project-wide "AST -> codegen" metaprogramming pattern. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation in the
jtd-esm-codegenmodule appears to be more capable than what is described here. TheJtdParserandEsmRendererclasses include logic for handlingelements,values,discriminator, andref, which are listed here as being rejected. It would be good to update the documentation to reflect the actual capabilities of the tool, or if these features are not fully supported, clarify their status.