fix(java): java codegen versioned namespace - #204
Conversation
Signed-off-by: ospreyboi <akshaosprey460@gmail.com>
Signed-off-by: ospreyboi <akshaosprey460@gmail.com>
|
Thanks for fixing this! Before we merge, can you confirm the generated output compiles successfully with Javac? This comment was generated by AI on behalf of @mttrbrts. |
|
@copilot resolve the merge conflicts in this pull request |
Merges upstream main into fix/java-codegen-versioned-namespace. Resolves conflicts in javavisitor.js by combining main's shouldImportType guard with the PR's versioned-namespace logic. Updates writeImport to preserve version in the import path. Snapshot file regenerated against main's test naming convention. Signed-off-by: mttrbrts <code@rbrts.uk>
|
Thank you for taking the time to dig into this, @ospreyboi — the issue is a real one and the instinct to use Unfortunately the approach hits a hard constraint in the Java language spec: package names and import statements may only contain valid Java identifiers separated by dots. The package concerto.decorator@1.0.0;
import concerto@1.0.0.Concept;causes There is no simple escaping mechanism that would work cleanly here — the most obvious alternatives (e.g. The version is intentionally dropped in the current codegen to produce idiomatic, compilable Java. Closing this PR and the linked issue #159 as won't fix — this is a language-level limitation rather than a bug. |
Closes #159
Hello!!
I was exploring the Accord Project codebase
and stumbled across this bug. I tried generating Java code
from a versioned Concerto model and noticed the version was just
silently dropped from the package name
which makes the output
incorrect and breaks downstream consumers.
Turns out
parseNamespace()already returns the version, it justwas not being used! The fixing was surprisingly small — just two lines
changed to destructure
versionalongsidenameand include itin the namespace string when present.
I also added a dedicated test case for versioned namespaces and
updated the snapshots so everything is consistent.
lib/codegen/fromcto/java/javavisitor.js— fixedstartClassFileand import generation to include version in namespace when present
test/codegen/fromcto/java/javavisitor.js— added test for versioned namespace