Import Formatting Rules

 

IDE Agnostic Instructions

Formatting Java files:

 

  • JavaDoc parameter information is on the same line, not indented
  • Line length is 128 characters
  • Spaces are used instead of tabs
  • Switch blocks are indented
  • Indentation size is 4

 

 

Formatting Resource Files

 

All of resources files have to follow these conventions:

 

  • Line length is 128 characters
  • Spaces are used instead of tabs
  • Indentation size is 4

 

Eclipse

(version 3.7 used)

 

Both of the code-style configurations (format and clean-up) needs to be configured to pass JBoss Community checkstyle criterion.

Java Formatter Rules

(Ctrl+Shift+F by default)

 

  1. download the formatting rules locally:
    https://github.com/richfaces/build/raw/master/ide-prefs/eclipse-formatting-rules.xml
  2. in Eclipse go to Window -> Preferences -> Java -> Code Style -> Formatter
  3. click Import
  4. select formatting rules which you have downloaded in step (1)

    (see picture bellow)

 

 

Clean-up Rules

(not bound by default, use  of Ctrl+Shift+O recommended)

 

  1. download the clean-up rules locally:
    https://github.com/richfaces/build/raw/master/ide-prefs/eclipse-cleanup-rules.xml
  2. in Eclipse go to Window -> Preferences -> Java -> Code Style -> Clean-up
  3. click Import
  4. select clean-up rules which you have downloaded in step (1)

 

Map the Clean-up Rules to Ctrl+Shift+O
  1. in Eclipse go to Window -> Preferences -> General -> Keys
  2. type "clean" into filter input ("type filter text")
  3. select Clean-up
  4. setup Binding: focus the input and type Ctrl+Shift+O as individual keys (or any other prefered shortcut)
    • you will have to unbind Ctrl+Shift+O from "Organise imports" action first

 

Be sure to trigger Formatting and and then Clean-up (in right order) before each file save!

 

formatting_setup_01.png

 

 

Formatting XML

 

  1. in Eclipse go to Window -> Preferences -> Web -> XML Files -> Editor
  2. setup
    • Line width: 128
    • Split multiple attributes each on new line: NO
    • Align final bracked in multi-line element tags: NO
    • Preserve whitespace in tags with PCDATA content: NO
    • Clear all blank lines: NO
    • Format comments: NO
    • Insert whitespace before closing empty eng-tags: YES
    • Indent using spaces
    • Indentation size: 4

 

Formatting CSS

 

  1. in Eclipse go to Window -> Preferences -> Web -> CSS Files -> Editor
  2. setup
    • Line width: 128
    • Insert line break between properties: YES
    • Disable wrapping in style attribute of Html: YES
    • Indent using spaces
    • Indentation size: 4
    • Capitalization style: all Lowercase

 

Formatting HTML


  1. in Eclipse go to Window -> Preferences -> Web -> HTML Files -> Editor
  2. setup
    • Line width: 128
    • Split multiple attributes each on new line: NO
    • Align final bracked in multi-line element tags: NO
    • Clear all blank lines: NO
    • Indent using spaces
    • Indentation size: 4
    • Tag names: Lowercase
    • Attribute names: Lowercase

 


 

 

 

 

 

Intellij IDEA

(version 10.5 used)

 

  1. download JAR distribution with IDEA settings (contains only Code style settings):
    https://github.com/richfaces/build/raw/master/ide-prefs/idea-settings.jar
  2. in IDEA go to File -> Settings -> Import Settings
  3. select the downloaded JAR file
  4. confirm to import Code Style and File Templates
  5. restart IDE

 

 

 

Netbeans

(version 7.0 used)

 

  1. download ZIP distribution with Netbeans settings
    https://github.com/richfaces/build/raw/master/ide-prefs/netbeans-jboss-community-formatter.zip
  2. in Netbeans go to Tools -> Options
  3. click to Import button at bottom of Options dialog
  4. click Browser and select downloaded ZIP file
  5. there will be All -> Editor -> Other structure listed in Available Options
  6. select All and click OK
  7. restart IDE