Fix: Keep acronyms uppercase in Java enum constants (#2850)#2851
Conversation
Enum constants containing known acronyms (like "SPA") were being incorrectly converted when using --acronym-style=camel, e.g. "MULTI_SPA_IN_GROUP_REJECTED" became "MULTI_Spa_IN_GROUP_REJECTED". For Java enum constants (UPPER_UNDERSCORE style), acronyms should always remain uppercase regardless of the --acronym-style setting. - Modified javaNameStyle() to use allUpperWordStyle for acronyms in enum constants - Added test case for enum with "SPA" acronym
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…#2851 - Revert the re-indentation of the neighboring ternary in Java/utils.ts; keep only the semantic one-line fix (it failed biome check). - Remove test/inputs/json/priority/enum-spa.json: as a JSON sample it ran through every language with default options and never exercised the acronym-style bug. - Remove the hand-written MessageCode.java fixture file, which was never compared against generated output. A real regression check follows in the next commit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The fixture harness cannot catch this bug: mangled enum constants are
self-consistent identifiers (the generated code compiles) and
(de)serialization uses the raw JSON names (round-tripping succeeds).
test/check-java-acronym-names.ts generates Java for an enum containing
the known acronym "SPA" under all four --acronym-style settings and
asserts on the emitted enum constant *identifier* (extracted from the
toValue() switch, since the raw JSON name always appears in string
literals even when the identifier is wrong). It runs standalone via
ts-node and as a pre-fixture check in test/test.ts, like
check-no-node-imports.ts.
Verified to fail on unfixed code:
acronym-style=camel: got "MULTI_Spa_IN_GROUP_REJECTED"
acronym-style=lowerCase: got "MULTI_spa_IN_GROUP_REJECTED"
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Thanks for the fix — the one-line change in 1. Merged current 2. Replaced the test artifacts (
The replacement is Verified both ways: with your fix temporarily reverted, the check fails with and with the fix present it passes for all four styles. 3. Reverted the unrelated re-indentation of the neighboring ternary in 🤖 Generated with Claude Code |
Enum constants containing known acronyms (like "SPA") were being incorrectly converted when using --acronym-style=camel, e.g. "MULTI_SPA_IN_GROUP_REJECTED" became "MULTI_Spa_IN_GROUP_REJECTED".
For Java enum constants (UPPER_UNDERSCORE style), acronyms should always remain uppercase regardless of the --acronym-style setting.
Description
Related Issue
Motivation and Context
Previous Behaviour / Output
New Behaviour / Output
How Has This Been Tested?
Screenshots (if appropriate):