For Developers‎ > ‎

Checkstyle

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. (http://checkstyle.sourceforge.net/)

Eclipse
  1. (Package Explorer) Right click and click 'Refresh'
  2. Help->Install New Software...
  3. Work with -> Add: http://eclipse-cs.sourceforge.net/update
  4. Type 'Checkstyle' into the search box
  5. Select 'Checkstyle' and click-through next
  6. (Menu bar) Window->Preferences->Checkstyle->New
  7. Under 'Type' select 'Project Relative Configuration'
  8. Under 'Name' enter 'chromium-style-5.0'
  9. Click browse and navigate to tools/android/checkstyle/chromium-style-5.0.xml
  10. Click OK
  11. (Package Explorer) Right click project -> Properties -> Checkstyle
  12. Under "Simple - use the following check configuration for all files" select 'chromium-style-5.0'
  13.  (Recommended) Under 'Exclude from checking...' Select:
    • files outside source directories
    • files not opened in editor
Eclim
  1. cd <path>/<to>/<eclimd> (e.g. ...../eclipse43/stable/)
  2. find . -name 'checkstyle*.jar' | grep eclim
  3. The latest version (as of 11/12/2013) is 5.6. If you have an older version (e.g. checkstyle-5.4.jar, checkstyle-5.5.jar) follow the update steps.
Update checkstyle jar
  1. Follow Eclipse steps #2 through #5
  2. find . -name 'checkstyle-5.6.jar'
  3. Copy that jar into the same directory as the old one.
  4. vim ./plugins/org.eclim.jdt_2.3.2/META-INF/MANIFEST.MF (jdt version number may be different)
  5. Under 'Bundle-ClassPath' edit the old checkstyle*.jar version number to the new one. 
  6. Restart eclimd
Configure Eclim
  1. Open vim and enter :EclimSettings
  2. Find the line org.eclim.java.checkstyle.config=
  3. Append /your/project/path/src/tools/android/checkstyle/chromium-style-5.0.xml
  4. Open a Java file and enter :Checkstyle to verify it works
  5. (Optional) Add the following to your vimrc:
" Run Checkstyle on open/write
autocmd BufWinEnter *.java :Checkstyle
autocmd BufWritePost *.java :Checkstyle


Limitations
    Does not support double indentation levels for line-wrap which may generate spurious warnings.
Comments