IntelliJ IDEA Editor Settings

This page describes the noticeable changes made to the default code formatting settings in IntelliJ IDEA. This is also a chance to review some of these changes and tweak them if necessary. None of these are essential for a pull request, but they all help. They can also be added after the original pull request but before a merge.

General

  • Line length is 80 characters

  • Use spaces instead of tabs for indentation

  • Use UTF-8 encoding

  • Use unix-style line endings (\n)

Code Conventions

  1. Install the Eclipse Code Formatter plugin, then restart IDEA

  2. Open Settings (Ctrl+Alt+S or ⌘+,)

  3. On the Other Settings Eclipse Code Formatter page

    1. Check Use the Eclipse code formatter

    2. In the Supported file types section, check Enable Java

    3. In Eclipse Java Formatter config file, browse to your local copy of VaadinJavaConventions.xml

  4. Go to Editor Code Style, and set Hard wrap at (columns) to 80

Imports

  1. Open Settings (Ctrl+Alt+S or ⌘+,)

  2. Go to Editor General Auto Import and un-check Optimize imports on the fly

  3. Go to Editor Code Style Java and on the Imports tab

    1. Make sure that Use single class import is checked

    2. Set both Class count to use import with ‘*‘ and Names count to use static import with ‘*‘ to 99

    3. On the Import Layout pane, make sure that Layout static imports separately is checked

    4. Remove all the packages in the list Packages to Use Import with ‘*‘

    5. Organize Java imports to comply to the convention defined below:

      Show code

      Java

      Expand code

      1. import javax.*
      2. import java.*
      3. <blank line>
      4. import all other imports
      5. <blank line>
      6. import com.google.gwt.*
      7. import com.vaadin.*
      8. <blank line>
      9. import elemental.*
      10. import static all other imports

Copyright

  1. Open Settings (Ctrl+Alt+S or ⌘+,)

  2. Go to Editor Copyright Copyright Profiles and create a new profile named Vaadin, with the copyright text as defined below:

    Show code

    Expand code

    1. Copyright 2000-$today.year Vaadin Ltd.
    2. Licensed under the Apache License, Version 2.0 (the "License"); you may not
    3. use this file except in compliance with the License. You may obtain a copy of
    4. the License at
    5. http://www.apache.org/licenses/LICENSE-2.0
    6. Unless required by applicable law or agreed to in writing, software
    7. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    8. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    9. License for the specific language governing permissions and limitations under
    10. the License.

Known Problems in Configuration

IntelliJ IDEA has a known problem with importing sources of other module as resources. Which is the case with the Flow project where flow-client has flow-server sources as a resource.

The fix for this is to during development time comment out the flow-server resource for the flow-client/pom.xml.

Show code

Comment out the flow-server resource

Expand code

  1. <resource><directory>../flow-server/src/main/java</directory></resource>
Note
Build flow-client package
To build the flow-client package remember to un-comment the resource.
  1. Go one level higher, to Editor Copyright, and set Default project copyright to the Vaadin profile you just created