Skip to content

Hoist PowerMock Whitebox calls used in expression position#1015

Draft
MBoegers wants to merge 1 commit into
MBoegers/powermock-whitebox-reflection-coveragefrom
MBoegers/powermock-whitebox-reflection-hoisting
Draft

Hoist PowerMock Whitebox calls used in expression position#1015
MBoegers wants to merge 1 commit into
MBoegers/powermock-whitebox-reflection-coveragefrom
MBoegers/powermock-whitebox-reflection-hoisting

Conversation

@MBoegers

@MBoegers MBoegers commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Adds a second pass to PowerMockWhiteboxToJavaReflection that handles Whitebox result calls nested inside an enclosing statement (return, method arguments, if-conditions, …), which the statement/variable-declaration pass cannot rewrite in place because reflection needs a multi-statement preamble.

For each such call, the reflection preamble and a temp local are hoisted before the enclosing statement, and the call is replaced by a reference to the temp. Calls in short-circuit (&&/||) right operands or ternary branches are left untouched, since hoisting would change whether the reflective call executes.

Adds 6 unit tests: in a return, in a method-call argument, in an if condition, inside a for-loop body (hoisted into the loop body, not the method block), two nested calls in one statement (preserved order), and a short-circuit-guarded call left unchanged.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 8, 2026
@MBoegers MBoegers marked this pull request as draft June 8, 2026 13:57
@MBoegers MBoegers force-pushed the MBoegers/powermock-whitebox-reflection-coverage branch 2 times, most recently from 5fc96ec to 4ad8941 Compare June 8, 2026 15:29
@MBoegers MBoegers force-pushed the MBoegers/powermock-whitebox-reflection-hoisting branch from 6296e0a to bc38b91 Compare June 8, 2026 15:31
@MBoegers MBoegers force-pushed the MBoegers/powermock-whitebox-reflection-coverage branch from 4ad8941 to dfdc2d0 Compare June 12, 2026 10:35
Adds a second pass to PowerMockWhiteboxToJavaReflection that handles
Whitebox result calls nested inside an enclosing statement (return,
method arguments, if-conditions, ...): the reflection preamble and a
temp local are hoisted before the statement and the call is replaced by
a reference to the temp. Calls in short-circuit (&&/||) or ternary
positions are left untouched to preserve evaluation semantics.
@MBoegers MBoegers force-pushed the MBoegers/powermock-whitebox-reflection-hoisting branch from bc38b91 to a2f486c Compare June 12, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant