I’ve been using Checkstyle with Eclipse, with a rule for making all local variables final. This rule is enforced when saving, so if a file containing a local variable without a final modifier is saved, final is automatically added to the variable declaration.
Now I’ve switched to IntelliJ IDEA, and i’m using Checkstyle to enforce this same rule here. But, instead of automatically adding the final modifier when saving, the variables are marked as erroneous, and I have to press ALT+enter enter to get the final modifier added, once for each variable. This is quite impractical, as I am doing further development on a quite large code base, where no variables have been marked as final.
Is there a way to set up Checkstyle with IDEA, in order to get it to add the final modifier to local variables automatically upon saving, as it does with Eclipse?
There is a way to avoid having to make each and every variable final.
Just alt+enter on one, then right-arrow and select “Fix all ‘Local variable..”.
Will fix all finals in the file.
It also works for other checks, have found it useful after migrating to Java7, to change to the diamond-format when instantiating parameterized objects.