Fix Root class name conflict in JDOM writer generator #520
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.
Problem
When using
Root
as a class name for the root element in a model definition, the JDOM writer generator would produce code that failed to compile due to a variable naming conflict.The generated
updateRoot()
method would declare both:Root root
(from uncapitalizing the class name "Root")Element root
(for the XML element being created)This resulted in a compilation error:
Solution
Renamed the local
Element
variable fromroot
torootElement
throughout theJDOMWriterGenerator.updateClass()
method. This makes the generated code use distinct names:root
- the model object parameterrootElement
- the XML Element being createdBefore (would not compile):
After (compiles successfully):
Testing
root-classname.mdo
test model withRoot
as the class nameRootClassnameJDOMGeneratorTest
to verify generated code compiles successfullyFixes the issue where models with a root class named "Root" would generate non-compilable JDOM writer code.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.