-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Support Java file merge #1344
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
Support Java file merge #1344
Conversation
- Add JavaFileMergerJavaParser class for standalone Java file merging using JavaParser - Modify DefaultShellCallback to support Java file merging by default - Support merging based on @mbg.generated JavaDoc tags and @generated annotations (javax/jakarta) - Preserve custom methods while updating generated methods - Add comprehensive tests and demo for the merge functionality - Update JavaParser dependency scope to make it available for main code This enables automatic merging of Java Mapper files during regeneration, similar to the existing XML merge functionality.
…ctices - Rewrite mergeImports method to sort imports according to Java best practices: 1. java.* packages (alphabetically) 2. javax.* packages (alphabetically) 3. jakarta.* packages (alphabetically) 4. Third-party and project packages (alphabetically) 5. Static imports (alphabetically, at the end) - Add ImportInfo helper class to handle import deduplication and comparison - Implement compareImports method with proper priority-based sorting - Update existing test expectations to match new sorted import order - Add comprehensive test shouldSortImportsAccordingToBestPractices to verify: * Correct ordering of different package types * Proper handling of static imports * Alphabetical sorting within each category - All 10 tests pass successfully - Import output is now predictable and follows industry standards
|
@DanielLiu1123 thanks for the contribution! I'm going to work on this a bit more before I merge it. |
|
We're going to call this an experimental feature for now, and it must be explicitely requested by a user. I will also add more tests from the Eclipse plugin. But this is an awesome start - thanks @DanielLiu1123! |
|
@jeffgbutler I just realized the code after the merge might not have been formatted. Could you please double-check? |
|
There are a small number of our repos such as this one that do not have auto formatting currently enabled. Given large changes to the generator it is probably best we let that slide until after release then if we don't have immediate patches to do say over a month or two, we could enable auto formatting then and cut a no op release so it's not harming diff points.
Sent from my Verizon, Samsung Galaxy smartphone
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Freeman Liu ***@***.***>
Sent: Wednesday, January 28, 2026 8:54:32 PM
To: mybatis/generator ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [mybatis/generator] Support Java file merge (PR #1344)
[https://avatars.githubusercontent.com/u/62151295?s=20&v=4]DanielLiu1123 left a comment (mybatis/generator#1344)<#1344 (comment)>
@jeffgbutler<https://github.com/jeffgbutler> I just realized the code after the merge might not have been formatted. Could you please double-check?
—
Reply to this email directly, view it on GitHub<#1344 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAHODI3ES7QZYBEWFSCYZST4JFR5RAVCNFSM6AAAAACGORLUG6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTQMJUHEYDONZZGI>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
|
Sorry for the confusion. What I meant was that the code generated by the generator did not go through JavaFormatter, which can cause formatting differences when the code is regenerated compared to previous versions. I was not referring to the code submitted in this PR being unformatted. |
|
@DanielLiu1123 thanks for bringing this up. I'll be bringing in my big test framework so we can exercise this new feature more fully - so we can address this later. I do think we'll need to add some method of configuring the formatter |
|
BTW - I looked in the code. You call |
JavaFileMergerclass for standalone Java file merging usingJavaParserDefaultShellCallbackto support Java file merging by default@mbg.generatedJavaDoc tags and@Generatedannotations (javax/jakarta)JavaParserdependency scope to make it available for main codeThis enables automatic merging of Java Mapper files during regeneration, similar to the existing XML merge functionality.
Close #595