Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,15 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
the new `fixtures/writer-conformance/` corpus. No shipped generator uses the writer yet, so
generated output does not change in this release.

- **A code writer for Java generators: `CodeWriter` and `JavaWriter` in `metaobjects-codegen-base`**
(ADR-0063). The same contract as the TypeScript writer: `JavaWriter` collects imports while the
body is written (`use("java.util.List")` returns the name to write), skips `java.lang` and
same-package types, prints static imports first, writes Javadoc, and breaks a call that does not
fit 120 columns with no trailing comma. `block` is a `try`-with-resources scope. It runs the
shared `core` cases and nine new `java` cases, and a layout ratchet (a `javac` parse-tree test
with a written, shrink-only allowlist) now holds Java generator source to it. No shipped Java
generator uses the writer yet, so generated output does not change in this release.

- **Select objects to regenerate in every port.** C# `dotnet meta gen --entities A,B` (and
`verify --codegen --entities`) and, for Java and Kotlin, `mvn metaobjects:generate
-Dmeta.entities=A,B` regenerate only the named objects' files, like TypeScript's
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/codegen-skip-conformance/`](../fixtures/codegen-skip-conformance/) (when `gen` may skip and what a local `verify --codegen` may answer, ADR-0064) | one case table in `cases.json`, plus the manifest layout vectors in `manifests.json` (ADR-0064 Amendment 1) | ✓ | ✓ | ✓ (through the Java runner) | ✓ | ✓ |
| [`fixtures/codegen-noop/`](../fixtures/codegen-noop/) (vocabulary with no lowering yet: FR-044 reporting, what is lowered and what stays inert; ADR-0066 business rules, inert everywhere) | 2 model pairs (`reporting/` and `rules/`, each `with` vs `without`) | ✓ (codegen + migrate) | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/cube-model/`](../fixtures/cube-model/) (FR-044 Plan 4 — the `cube-model` generator's golden Cube files, plus the canonical model's golden) | 46 cases (36 trees + 10 errors) + 1 canonical golden | ✓ (the exporter is TypeScript-only, spec R6; its `cube` lane also loads the files into a real Cube) | — | — | — | — |
| [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 41 cases (31 core + 10 TypeScript) | ✓ (the first writer; core and TypeScript dialect) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) |
| [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 50 cases (31 core + 10 TypeScript + 9 Java) | ✓ (the first writer; core and TypeScript dialect) | ✓ (core and Java dialect; `JavaWriter` in `codegen-base`) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) |
| [`fixtures/contract-conformance/`](../fixtures/contract-conformance/) (FR-022 — the `contract-schema` and `openapi` generators' golden trees and refusals) | 19 cases (14 trees + 5 errors) | ✓ (one neutral engine, ADR-0034 Amendment 10; the generated API lanes also hold real traffic to the documents) | — | — | — | — |
| [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the `explorer.json` data spine: `meta export --effective` + `meta verify --format json` + the generated-file manifest in, one explorer document out) | 1 case (`shop`) | ✓ (the builder is TypeScript, and reads only port-neutral inputs) | — | — | — | — |

Expand Down
16 changes: 11 additions & 5 deletions fixtures/writer-conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ format are in [`spec/code-writer.md`](../../spec/code-writer.md).
- `cases/*.json` with `"dialect": "core"` pin the language-neutral core: indentation, blocks,
blank-line requests, snippets, fit-or-break lists, line endings and the error codes. Every
port's writer runs them with the options the case states.
- Cases with a language dialect (`"dialect": "typescript"`) pin that language's writer: import
collection and ordering, doc comments and its defaults.
- Cases with a language dialect (`"dialect": "typescript"`, `"dialect": "java"`) pin that
language's writer: import collection and ordering, doc comments and its defaults. A runner
skips the dialects that are not its own.

Runner: TypeScript, `server/typescript/packages/codegen-ts/test/writer-conformance.test.ts`.
The other ports run the `core` cases when their writers land, and add cases for their own
dialect beside these.
Runners:

- TypeScript, `server/typescript/packages/codegen-ts/test/writer-conformance.test.ts` (`core` and `typescript`).
- Java, `server/java/codegen-base/src/test/java/com/metaobjects/generator/writer/WriterConformanceTest.java` (`core` and `java`).
- Rust, `server/rust/metaobjects-codegen/tests/writer_conformance.rs` (`core`).

The ports without a writer yet (C#, Kotlin, Python) run the `core` cases when their writers
land, and add cases for their own dialect beside these.
61 changes: 61 additions & 0 deletions fixtures/writer-conformance/cases/java-defaults.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"description": "The Java dialect indents four spaces, breaks at 120 columns and puts no comma after the last item of a broken list.",
"dialect": "java",
"ops": [
[
"open",
"class A {"
],
[
"line",
"static final List<String> NAMES = ",
{
"list": {
"open": "List.of(",
"items": [
"\"n00\"",
"\"n01\"",
"\"n02\"",
"\"n03\"",
"\"n04\"",
"\"n05\"",
"\"n06\"",
"\"n07\"",
"\"n08\"",
"\"n09\"",
"\"n10\"",
"\"n11\"",
"\"n12\"",
"\"n13\""
],
"close": ")"
}
},
";"
],
[
"close",
"}"
]
],
"expected": [
"class A {",
" static final List<String> NAMES = List.of(",
" \"n00\",",
" \"n01\",",
" \"n02\",",
" \"n03\",",
" \"n04\",",
" \"n05\",",
" \"n06\",",
" \"n07\",",
" \"n08\",",
" \"n09\",",
" \"n10\",",
" \"n11\",",
" \"n12\",",
" \"n13\"",
" );",
"}"
]
}
44 changes: 44 additions & 0 deletions fixtures/writer-conformance/cases/java-doc-comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"description": "A one-entry doc comment that fits is one line; more entries, or one that does not fit, make a block. An empty entry is a bare ` *` line, and a comment terminator inside the text is neutralised.",
"dialect": "java",
"ops": [
[
"doc",
"The user."
],
[
"line",
"a();"
],
[
"doc",
"First line.",
"",
"@see other"
],
[
"line",
"b();"
],
[
"doc",
"ends */ here"
],
[
"line",
"c();"
]
],
"expected": [
"/** The user. */",
"a();",
"/**",
" * First line.",
" *",
" * @see other",
" */",
"b();",
"/** ends *&#47; here */",
"c();"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"description": "Header lines print first, then a blank line, the package line, a blank line, the imports, a blank line and the body. A file with no imports has no import block.",
"dialect": "java",
"ops": [
[
"header",
"// Generated by MetaObjects. Do not edit."
],
[
"package",
"com.acme.api"
],
[
"use",
"java.util.List"
],
[
"open",
"interface A {"
],
[
"line",
"List<String> names();"
],
[
"close",
"}"
]
],
"expected": [
"// Generated by MetaObjects. Do not edit.",
"",
"package com.acme.api;",
"",
"import java.util.List;",
"",
"interface A {",
" List<String> names();",
"}"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"description": "Imports print in code-unit order, one per line, after the package line. Static imports come first, then a blank line, then the others. A name used twice is imported once.",
"dialect": "java",
"ops": [
[
"package",
"com.acme"
],
[
"use",
"java.util.Map"
],
[
"use",
"com.acme.other.Zed"
],
[
"useStatic",
"org.junit.Assert.assertEquals"
],
[
"use",
"java.util.List"
],
[
"use",
"java.util.List"
],
[
"useStatic",
"java.util.Objects.requireNonNull"
],
[
"line",
"class A {}"
]
],
"expected": [
"package com.acme;",
"",
"import static java.util.Objects.requireNonNull;",
"import static org.junit.Assert.assertEquals;",
"",
"import com.acme.other.Zed;",
"import java.util.List;",
"import java.util.Map;",
"",
"class A {}"
]
}
15 changes: 15 additions & 0 deletions fixtures/writer-conformance/cases/java-imports-conflict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"description": "One simple name imported from two types is an error, not a silent shadow.",
"dialect": "java",
"ops": [
[
"use",
"java.util.Date"
],
[
"use",
"java.sql.Date"
]
],
"error": "ERR_WRITER_IMPORT_CONFLICT"
}
19 changes: 19 additions & 0 deletions fixtures/writer-conformance/cases/java-imports-nested-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "A nested type is imported as written and used by its last segment.",
"dialect": "java",
"ops": [
[
"use",
"java.util.Map.Entry"
],
[
"line",
"class A {}"
]
],
"expected": [
"import java.util.Map.Entry;",
"",
"class A {}"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"description": "A type in java.lang or in the file's own package is written by its simple name and imports nothing, whichever order the package and the types were named in.",
"dialect": "java",
"ops": [
[
"use",
"java.lang.String"
],
[
"use",
"com.acme.Sibling"
],
[
"use",
"java.util.UUID"
],
[
"package",
"com.acme"
],
[
"line",
"class A {}"
]
],
"expected": [
"package com.acme;",
"",
"import java.util.UUID;",
"",
"class A {}"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"description": "A file with a package line and no imports has no import block.",
"dialect": "java",
"ops": [
[
"package",
"com.acme.api"
],
[
"line",
"interface A {}"
]
],
"expected": [
"package com.acme.api;",
"",
"interface A {}"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"description": "One static member name imported from two types is an error.",
"dialect": "java",
"ops": [
[
"useStatic",
"a.A.of"
],
[
"useStatic",
"b.B.of"
]
],
"error": "ERR_WRITER_IMPORT_CONFLICT"
}
Loading
Loading