Skip to content

Add UsePredicateNot to replace cast-and-negate with Predicate.not(..)#1072

Merged
timtebeek merged 3 commits intomainfrom
tim/predicate-not
Apr 24, 2026
Merged

Add UsePredicateNot to replace cast-and-negate with Predicate.not(..)#1072
timtebeek merged 3 commits intomainfrom
tim/predicate-not

Conversation

@timtebeek
Copy link
Copy Markdown
Member

Summary

  • Adds UsePredicateNot, a Java 11+ recipe that rewrites ((Predicate<T>) lambdaOrMethodRef).negate() to Predicate.not(lambdaOrMethodRef).
  • Handles both method references and lambdas; leaves already-typed Predicate variables untouched.
  • Registers the recipe in java-util-apis.yml and java-version-11.yml.

Test plan

  • ./gradlew test --tests "*.UsePredicateNotTest" (5 tests pass)
  • Full ./gradlew test stays green

…..)`

Targets Java 11+ code like `((Predicate<T>) lambdaOrMethodRef).negate()` and
rewrites to `Predicate.not(lambdaOrMethodRef)`.
@timtebeek timtebeek marked this pull request as ready for review April 24, 2026 06:58
@timtebeek timtebeek merged commit 95028a5 into main Apr 24, 2026
1 check passed
@timtebeek timtebeek deleted the tim/predicate-not branch April 24, 2026 07:10
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant