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

Append items to annotation attribute array #4667

Conversation

nielsdebruin
Copy link
Contributor

@nielsdebruin nielsdebruin commented Nov 13, 2024

What's changed?

This PR enhances the functionality of the AddOrUpdateAnnotationAttribute recipe, allowing not only to override but also to append to array values. A new option, arrayAppend, has been introduced, enabling users to append to attributes with an array type. When used in conjunction with the addOnly option, users can control whether a value will be appended only if it is not already present, thereby avoiding duplication.

What's your motivation?

Anyone you would like to review specifically?

@timtebeek @Laurens-W

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@nielsdebruin nielsdebruin linked an issue Nov 13, 2024 that may be closed by this pull request
@nielsdebruin nielsdebruin self-assigned this Nov 13, 2024
@nielsdebruin nielsdebruin added the enhancement New feature or request label Nov 13, 2024
@nielsdebruin nielsdebruin changed the title 4157 Initial test for adding items to array 4157 Initial test for appending items to annotation array attribute Nov 13, 2024
@nielsdebruin nielsdebruin changed the title 4157 Initial test for appending items to annotation array attribute Initial test for appending items to annotation array attribute Nov 13, 2024
@nielsdebruin nielsdebruin changed the title Initial test for appending items to annotation array attribute Append items to annotation attribute array Nov 13, 2024
@Laurens-W
Copy link
Contributor

Laurens-W commented Nov 13, 2024

I think your first proposed option is the way to go. You'd want to separately be able to specify whether you only want to add a property value when it's missing but also be able to specify whether you want to replace or append the new value(s)

@nielsdebruin nielsdebruin force-pushed the 4157-allow-addorupdateannotationattribute-to-add-values-to-an-array branch from f49737c to 268f576 Compare November 14, 2024 11:06
@nielsdebruin nielsdebruin marked this pull request as ready for review November 15, 2024 09:09
Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved aside from the last suggestion; let me know then we can merge right after.

…otationAttribute.java

Co-authored-by: Tim te Beek <tim@moderne.io>
@timtebeek timtebeek merged commit e206376 into main Nov 19, 2024
2 checks passed
@timtebeek timtebeek deleted the 4157-allow-addorupdateannotationattribute-to-add-values-to-an-array branch November 19, 2024 13:54
MBoegers pushed a commit to MBoegers/rewrite that referenced this pull request Dec 18, 2024
* Add some initial tests

* Add append functionality

* Add markers

* Fix constructor after merge

* Polish code

* Verify default behavior retained for declarative recipes through use of `null` in tests

* Add test that fails due to unexpected second cycle

* Adopt Markers.findFirst

* Add newline to indicate Marker is on assignment

* Fix test and polish

* Update rewrite-java/src/main/java/org/openrewrite/java/AddOrUpdateAnnotationAttribute.java

Co-authored-by: Tim te Beek <tim@moderne.io>

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow AddOrUpdateAnnotationAttribute to add values to an array
3 participants