Skip to content

Drop rewrite-analysis from ReplaceCollectionToArrayArgWithEmptyArray - #1029

Merged
timtebeek merged 1 commit into
mainfrom
tim/rewrite-analysis-dependency
Aug 25, 2026
Merged

Drop rewrite-analysis from ReplaceCollectionToArrayArgWithEmptyArray#1029
timtebeek merged 1 commit into
mainfrom
tim/rewrite-analysis-dependency

Conversation

@timtebeek

Copy link
Copy Markdown
Member

This recipe was the only user of rewrite-analysis that did not need its dataflow engine, so it can rely on rewrite-java alone.

UsesInvocation is swapped for UsesMethod — its own Javadoc calls it "equivalent to UsesMethod but for any InvocationMatcher", and its @implNote says it only exists because MethodMatcher has no base interface; since the matcher here is a plain MethodMatcher, UsesMethod applies directly and is faster, using the indexed TypesInUse.hasMethodUse(..) instead of iterating getUsedMethods(). InvocationMatcher.advanced().isFirstArgument(..) is inlined to the cursor walk it expands to (parent tree cursor is a MethodCall, first argument is identity-equal to the array), matched with MethodMatcher.matches(MethodCall), which delegates to matches(getMethodType()) exactly as the InvocationMatcher default did.

No behavior change, and the existing ReplaceCollectionToArrayArgWithEmptyArrayTest (4 tests) passes unchanged. The rewrite-analysis dependency stays in build.gradle.kts for ReplaceStackWithDeque, ReplaceLegacyCollection, and FindNewExceptionWithoutCause, which do use its dataflow and taint analysis.

`UsesInvocation` documents itself as equivalent to `UsesMethod` and only
exists because `MethodMatcher` has no base interface; since the matcher
here is a plain `MethodMatcher`, `UsesMethod` applies directly and uses
the indexed `TypesInUse.hasMethodUse(..)` rather than iterating every
used method.

`InvocationMatcher.advanced().isFirstArgument(..)` expands to a cursor
walk to the enclosing `MethodCall` plus an identity check on its first
argument, so it is inlined against `MethodMatcher.matches(MethodCall)`,
which is identical to the `InvocationMatcher` default it replaced.

The dependency remains for the recipes that use its dataflow engine.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Aug 25, 2026
@timtebeek
timtebeek merged commit 8b57f68 into main Aug 25, 2026
1 check passed
@timtebeek
timtebeek deleted the tim/rewrite-analysis-dependency branch August 25, 2026 22:26
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Aug 25, 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