I'm running Luna 4.4.2 and thought I had the same issue, but it seems that "Quick Fix" isn't available for all reported problems. It took me a moment to realize, because I right clicked on the file previously and did a "Apply Checkstyle Fixes", so the only items remaining are the ones check style doesn't fix automatically.
Answer from James Oravec on Stack OverflowIf you are using IntelliJ, you can install the CheckStyle IDEA plugin.
Then import the CheckStyle settings into the editor, and Reformat like normal (Ctrl+Alt+L is default shortcut key).
If you're using Eclipse, yes. You can't correct all problems though. There are two ways:
- Right click on the java file in Package Explorer or whatever, and select 'Apply Checkstyle Corrections'.
- Click on the error in the problems view, and select 'Quick fix'. This corrects the problem.
Eclipse Checkstyle Plug-in / Discussion / Help (readonly - use Github): Apply Checkstyle fixes not working in RSA
java - How can I apply multiple quick fixes for Checkstyle problems of the same type? - Stack Overflow
Eclipse CheckStyle - Stack Overflow
Checkstyle-Plugin 8.5.1 does not work with Eclipse Oxygen 4.7.2
Eclipse has since the version 3.3 a cleanup wizard that could help doing part of the job. But in my opinion, the question is asked in the wrong way:
- Checkstyle does check a lot of different things, and some of them could be automatically corrected. So by using the automatic format of Eclipse, and tweaking the format that it complies to Checkstyle, these warnings will go away automatically.
- Some of the warnings indicate that something is missing which is not known. Most prominent are here comments everywhere, but there could be other warnings as well. Eclipse may here help partially, but it is not a good idea to generate JavaDoc by eclipse with its standard templates, because then the indication that something is wrong is gone, but the cause exists further.
- Some of the warnings indicate something for which multiple solutions could exist. So it is not possible for Eclipse to automatically change the code. There sometimes a quick fix exists that may be appropriate, but each has to be selected by the user.
So you should do the following:
- Have a look at the Cleanup Wizard in Eclipse
Window > Preferences > Java > Code Style > Clean Up, create there a new profile from an existing one, and tweak it to the rules you want to use in Checkstyle. - If you have selected
Code Organizing > Format Source Codein your profile, tweak the code formatter for Java as well. Go toWindow > Preferences > Java > Code Style > Formatter, create here as well a new profile as well, and tweak it according to your checkstyle rules. The rule of thumb should be that after writing any code and formatting it with the formatter, no checkstyle warning should exist that could be corrected by only inserting or removing spaces, blanks, newlines, and parantheses. - Ensure that this configuration is used by everyone in your project, and of course everyone should use Eclipse.
I found a link at http://www.ibm.com/developerworks/library/os-eclipse-clean/ which answers this question.
Just a guess here, but I think the answer is to file a bug/feature request with the cs-eclipse plug-in team. The message Eclipse is giving you seems to indicate it's a special case that would need to be handled by the developer.
If you do submit a ticket, let us know. I'd like to watch it. I think it would be a useful feature.
Since version 5.6.1, this capability is now available in eclipse-cs. I've just tested this with 5.7.0 (the latest version) and confirmed it works.
For reference, the original bug report is here. The feature doesn't appear in the release notes for that version, but that's due to omission (see comments in bug report).
I don't know what Eclipse plugin you use, but I use eclipse-cs.
In eclipse-cs, when you write a CheckStyle Checker (a class for detecting CheckStyle-related issues), you can write another class as so-called quickfix. If the writer of a Checker does not provide a quickfix, none will be available to you.
As for the maven issue, where your maven output and Eclipse warnings differ: The configuration of Eclipse may differ from the configuration read by maven. Please make sure both use the same configuration file.
You have to fix your checkstyle warnings manually.
FYI, in Eclipse you can also configure a "Save Action" to automatically apply the final modifier to all parameters if possible.
Go to Window → Preferences → Java → Editor → Save Actions and click Configure next to Additional Actions. Then on the "Code Style" tab, select "use 'final' modifier where possible", and check 'Parameter'.
This may help keeping your code compliant in the future. The save actions can also be applied to the entire workspace at once by using the "Clean Up" feature available in Java → Code Style → Clean Up.
To see problems tabs go to menu
Window>Show View>ProblemsRight-click on warning in Problems tab (e.g. "Parameter result Should be final")
Choose "Quick Fix"
In the "Quick Fix" window that opens up, select a fix type
Click "Select All" to select all files that need the fix.
Hit "Finish" to apply the fix.
The DoubleCheckedLocking check has been removed in Checkstyle 5.6 and must be manually removed from your Checkstyle configuration.
See also: http://sourceforge.net/tracker/index.php?func=detail&aid=3571442&group_id=29721&atid=397078
Open the Checkstyle preferences, create your own Check Configuration, go into your own check configuration, find the TreeWalker module, click it and then un-check the DoubleCheckedLocking. As simple as that.
