How do you keep yourself coding to standards? There is stylecop and resharper for C#. Are there any tools/eclipse plugins for code analisys in Java? Which of them do you use?
Here at work we use Checkstyle to ensure that the code follows certain rules. Checkstyle is also available as plugin for Eclipse.
- Checkout http://checkstyle.sourceforge.net/.
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard. Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration file is supplied supporting the Sun Code Conventions. As well, other sample configuration files are supplied for other well known conventions.
PMD is integrated with JDeveloper, Eclipse, JEdit, JBuilder, BlueJ, CodeGuide, NetBeans/Sun Java Studio Enterprise/Creator, IntelliJ IDEA, TextPad, Maven, Ant, Gel, JCreator, and Emacs.
- Findbugs http://findbugs.sourceforge.net
FindBugs uses static analysis to inspect Java bytecode for occurrences of bug patterns. Static analysis means that FindBugs can find bugs by simply inspecting a program's code: executing the program is not necessary. This makes FindBugs very easy to use: in general, you should be able to use it to look for bugs in your code within a few minutes of downloading it. FindBugs works by analyzing Java bytecode (compiled class files), so you don't even need the program's source code to use it. Because its analysis is sometimes imprecise, FindBugs can report false warnings, which are warnings that do not indicate real errors. In practice, the rate of false warnings reported by FindBugs is less than 50%.
What's wrong with a bit of self-discipline? If you can't do it for something as trivial as formatting, I don't hold out much hope for other quality aspects of code.
We use Checkstyle at my company, only for javadoc checks though.
It is nice in the way that you can configure different modules to include stuff to check for, and also on what levels (as in protected, public, private etc).
A heads-up is that for javadoc-checking you need to explicitly state if a method is allowed to throw
several exceptions. This is so because the creators think that it is bad design to have a method throw more than one exception (they are in other words trying to control design, not related IMHO).
Checkstyle and FindBugs and PMD. The latter two are much more than just style tools. But there is usually some effort to be put in, in order to get an agreement among the members of the team and, as well as for configuration of the tool.
Having a coding standards document that is distributed to all of the developers in the team/department/organisation is a good start.
The eclipse compiler warnings and code formatter does the job for us. Although I'm aware that checkstyle does quite a bit more semantic checking for actual design of code, rather than just laying it out sensibly.
You can have a look at Sonar. It's an open source project that really makes easy the execution of Checkstyle, PMD and Findbugs.