Repository navigation
A7 + B6 follow-up: side effects, comments and formatting scope - #1123
Merged
Merged
Conversation
…s not taken for the local Refs #1116 (B6)
… running `RemoveUnusedLocalVariables` file-wide Refs #1116 (A7)
…Super`, `RemoveUnusedPrivateMethods` and `UseLambdaForFunctionalInterface` They ran `RemoveUnusedImports` over the whole file, removing unrelated unused imports too. Refs #1116 (A7)
…uldNotBeNested` produce Both ran `RemoveUnneededBlock` over the whole file, flattening unrelated blocks too. Refs #1116 (A7)
It ran `SimplifyBooleanExpressionVisitor` over the whole file. Refs #1116 (A7)
…` call It ran `EqualsAvoidsNull` over the whole file to flip its own invocations, which flipped unrelated ones too. Refs #1116 (A7)
…g the cast expression alone Refs #1116 (A7)
It ran `EmptyBlock` over the whole file, deleting unrelated empty blocks and statements. An `if` whose condition may have side effects is now kept rather than reduced to its condition. Refs #1116 (A7)
…eters` replaced It ran `SimplifyBooleanExpression` and `SimplifyConstantIfBranchExecution` over the whole file. Refs #1116 (A7)
…mpound-assigns in `RemoveUnusedLocalVariables` Refs #1116 (B6)
…dLocalVariables` Refs #1116 (B6)
…d of auto-formatting the whole block Refs #1116 (A7)
…aryPrimitiveAnnotations` instead of auto-formatting the whole method Refs #1116 (A7)
…n `SimplifyConstantIfBranchExecution` It ran `RemoveUnneededBlock` and `EmptyBlock` over every block enclosing a change, flattening and deleting unrelated blocks in the same method. Refs #1116 (A7)
15 of 41 tasks
# Conflicts: # src/main/java/org/openrewrite/staticanalysis/SimplifyConstantIfBranchExecution.java # src/test/java/org/openrewrite/staticanalysis/RemoveUnusedLocalVariablesTest.java
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.
Follow-up to #1122 for items A7 and B6 of #1116, split off for a closer review; it is stacked on #1122 and should be retargeted to
mainonce that merges.B6:
RemoveUnusedLocalVariablesremoved unused locals whose initializer or reassignment had a++,--or compound-assignment side effect, e.g.int unused = counter++;. It also parked the comments of a removed declaration on the enclosing class, where they landed on the next member, and threw when there was no class (Groovy scripts). Comments now stay in their own block.A7: three more recipes reformatted or cleaned up more than they changed.
SimplifyConstantIfBranchExecutionranRemoveUnneededBlockandEmptyBlockover every block enclosing a change. It now inlines or removes only the statement a simplifiedifleaves behind, keeps comment-only blocks, and drops anelseemptied by a simplifiedelse if.UnwrapElseAfterReturnauto-formatted the whole block. It now shifts the unwrapped statements withShiftFormat, so they keep their own formatting. This may conflict with UnwrapElseAfterReturn: only unwrap when else declarations do not collide #979.UnnecessaryPrimitiveAnnotationsauto-formatted the whole method. It now hands the removed annotation's prefix to the next element.Each commit adds a test that failed before the fix.
./gradlew testpasses locally on this branch.