Reputation: 4535
I would like to setup my IntelliJ IDEA 14 for automatic final
keyword adding in all possible places (parameters, fields, etc.) to the existing Java class. I found some solutions with macros and shortcuts but I would like setup IntelliJ to add the final
keyword when it saves the file. Does anyone know a good solution for this? Maybe can you recommend some plugin or combination of plugins?
Upvotes: 34
Views: 18420
Reputation: 5909
Since the 2018.3 version we can enable the checkbox:
Preferences/Settings > Editor > Inspections > Java > Code style issues > Local variable or parameter can be final
Then perform the reformat code action.
If the Code cleanup checkbox is enabled then IDEA will automatically add final where possible.
Upvotes: 34
Reputation: 4220
Use Save Actions
plugin: https://plugins.jetbrains.com/plugin/7642-save-actions
You can enable adding of final
keywords in:
Settings -> Other Settings -> Save Actions -> Add final to field/local variable`.
Upvotes: 10
Reputation: 8202
Open the "Configure inspections" view (click on the person in the hat icon). Search on "final" and you'll find various options in the code style section that you can enable to enable highlighting of candidates for final
. You can then use alt-return to apply the suggestion within a given file.
I wouldn't recommend you do it automatically on saving!
Upvotes: 14