Hoist PowerMock Whitebox calls used in expression position#1015
Draft
MBoegers wants to merge 1 commit into
Draft
Conversation
5fc96ec to
4ad8941
Compare
6296e0a to
bc38b91
Compare
4ad8941 to
dfdc2d0
Compare
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.
bc38b91 to
a2f486c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a second pass to
PowerMockWhiteboxToJavaReflectionthat handlesWhiteboxresult 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 anifcondition, inside afor-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.