Skip to content
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

fix: Don't alter the AST node positions of original code. #3800

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

amishra-u
Copy link

@amishra-u amishra-u commented Dec 21, 2024

fixes: #3799

Changes:

Deep Copy for Annotations:

  1. Replaced the usage of the clone method (which performed a shallow copy) with TreeCopier. This ensures a deep copy of annotations, preventing updates to copied annotations from affecting the original ones.
  2. Updated instances in the codebase (e.g., this location) where annotations were not being copied, ensuring the use of copyAnnotations.

Testing

Added a unit test using Delombok to verify that AST node positions remain unchanged before and after the Lombok annotation processor is applied, across all existing test files.

  1. Introduced a preLombokProcessors (purely for testing purpose) field in Delombok to run processors before Lombok annotation processing. List is empty by default except for RunTestViaDelombok unit tests.
  2. Created a NodePositionMapper processor within preLombokProcessors to capture the original AST node positions before Lombok processing.
  3. Updated the existing ValidatePositionProcessor to validate node positions before and after Lombok processing.
  4. Ignored validation for positions of nodes generated by Lombok, to handles cases like:
  • @nonnull on record fields, where Lombok replaces GENERATEDCONSTR and modifies node positions. Also the GENERATEDCONSTR was never part of original code.

Note: Without this change, 43 tests under test/transform/resource/before failed for the above unit test.

@amishra-u amishra-u marked this pull request as ready for review December 27, 2024 23:21
@amishra-u
Copy link
Author

@Rawi01 Can you please review it.

@amishra-u
Copy link
Author

@Rawi01 In last run, the one check failed due to timeout. can you please rerun the check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Lombok Annotation Processor incorrectly alters AST node positions for original code
1 participant