Vaadin Coding Conventions
We use UTF-8.
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
or
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 "eclipse" directory)
- the result should be named "Vaadin Cleanup 20080201"
3.2. Window->Preferences->Java->Code style->Formatter
- Import VaadinJavaConventions.xml (found in the "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
- Remove 'this' qualifier for non static field accesses
- Remove 'this' qualifier for non static method accesses
- Convert control statement bodies to block
- Add missing '@Override' annotations
- Add missing '@Deprecated' annotations
- Remove unused imports
- Remove unnecessary casts
- Remove trailing whitespace on all lines
Discussion
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
