Merged
Conversation
This commit refactors the AddFinalIntention action for improved behavior and adds comprehensive tests.
Key changes:
- The `isAvailable` method is now more context-aware, only enabling the
intention when the caret is on a variable (parameter, local variable)
or within a method scope suitable for adding 'final' modifiers.
- The `invoke` method has been rewritten to:
- Prioritize making a specific variable final if the caret is on it.
- Fall back to making all eligible parameters and local variables final
if the caret is within a method but not on a specific variable.
- Avoid adding the 'final' modifier if it's already present on an element.
- A comprehensive test suite (`AddFinalIntentionTest.java`) has been added,
utilizing `LightJavaCodeInsightFixtureTestCase`. The tests cover:
- Adding 'final' to single parameters and local variables.
- Adding 'final' to all applicable elements in a method scope.
- Ensuring no changes occur for already 'final' elements.
- Verifying the intention is not available in irrelevant contexts
(e.g., class declarations, import statements).
- Basic checks for field variables (though full field support might be a future enhancement).
These changes make the intention more robust, predictable, and maintainable.
Updated the intention logic to better handle final modifier additions for fields, variables, and parameters. Improved test coverage and added assertions for caret presence to ensure test reliability. Enhanced code readability with consistent use of `final` in method parameters and local variables.
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.
This commit refactors the AddFinalIntention action for improved behavior and adds comprehensive tests.
Key changes:
isAvailablemethod is now more context-aware, only enabling the intention when the caret is on a variable (parameter, local variable) or within a method scope suitable for adding 'final' modifiers.invokemethod has been rewritten to:AddFinalIntentionTest.java) has been added, utilizingLightJavaCodeInsightFixtureTestCase. The tests cover:These changes make the intention more robust, predictable, and maintainable.