Vaadin Coding Conventions

We use UTF-8 and Unix style line delimiters.

We follow Code Conventions for the Java Programming Language (Mandatory read!)

Format (ctrl-shift-F) and Organize Imports (ctrl-shift-O) before commit, or even better: as Save Actions. Formatting might uncover problems with your code, so you might want to do it every now and then while coding.

Clean Up can be found under the Source -menu. Consider doing that before commit.

Eclipse setup

1. Text File Encoding

1.1. Workspace-wide: Window->Preferences->General->Workspace

  • Text File Encoding, Other: UTF-8


Project specific: Properties->Resource

  • Text File Encoding, Other: UTF-8

2. JDK compliance

Java5 is used for Vaadin 6. Sun java 1.5 recommended.

3. Formatting etc

You can set the coding convention (etc) preferences either as a workspace (preferred) or project preference.

3.1. Window->Preferences->Java->Code style->Clean Up

  • Import VaadinCleanup.xml (found in the<current version>/eclipse directory)
  • the result should be named "Vaadin Cleanup 20080201"

3.2. Window->Preferences->Java->Code style->Formatter

  • Import VaadinJavaConventions.xml (found in the<current version>/eclipse directory)
  • the result should be named "Vaadin Java Conventions 20071114"

3.3. Window->Preferences->Java->Editor->Save Actions

  • [x] Perform the selected actions ...
    • [x] Format
    • [x] Organize imports
    • [x] Additional actions -> Configure
      • Code Organizing tab: Select Remove trailing whitespace for All lines, deselect everything else
      • Code Style tab: Select Use blocks in... Always, deselect everything else
      • Member Accesses tab: On both Use 'this'..., select Only if necessary, deselect everything else
      • Missing Code tab: Select everything except Implementations of interface methods (1.6 or higher)
      • Unnecessary Code tab: Select Remove unused importas and Remove unnecessary casts, deselect everything else
      • Press OK to close the Additional Save Actions dialog
    • The list of Additional actions should now contain these entries
      • Remove 'this' qualifier for non static field accesses
      • Remove 'this' qualifier for non static method accesses
      • Convert control statement bodies to block
      • Remove unused imports
      • Add missing '@Override' annotations
      • Add missing '@Deprecated' annotations
      • Remove unnecessary casts
      • Remove trailing whitespace on all lines

3.4. Window->Preferences->Java->Compiler->Error/Warnings

  • Set "Potential Programming Problems->Serializable class without SerializableUID" to ignore

3.5 General -> Workspace

  • Set "New text file delimiter" to "Other: Unix"


Some of the applied formatting/cleanups, and why:

  • Tab policy Spaces only; not "Mixed" (consistency), not "Tabs only" (not java conventions compatible)
  • Braces around if/for/while blocks: 1) The conventions say so 2) "Always" is a much simpler rule to follow than "if unclear"
  • remove unnecessary "this" (this.variable, this.method()): for consistency; the alternative is always add "this", "this" sometimes not acceptable
  • Disabling "block comment formatting" would solve GWT jsni code indent problem, but we do want to format other block comments. Using "/*-" is a better solution.
  • remove unused imports, remove unnecessary casts: no harm, cleaner code
  • decided against "remove unused [members|variables]", because it might remove stuff while the code is work-in-progress
  • remove trailing whitespace; no harm, cleaner
  • Serialization UUIDs are not used in the project. To avoid a @suppresswarning("serial") in all files the warnings should be turned off
Last modified 6 years ago Last modified on 27 Jan 2012 14:06:06