Coding Standards - IDE Settings

We have two sets of coding standards.  First are the firm standards, which must be adhered by all code contributed to the system.  Second are the guidelines, which should generally be followed; however, we fully recognize that exceptions may occur.

Firm Standards

Modified lines should have trailing spaces stripped.

  • To do this in Intellij: Preferences > Editor > General, Other section.  "Strip trailing spaces on Save:" make certain that the drop down has "Modified Lines" selected.
  • To do this in Eclipse: Preferences > Java > Editor > Save Actions > Perform the selected actions on save > Format source code > Format edited lines

All imports should be explicitly listed.

  • Intellij makes this difficult.  Go to Preferences > Editor > Code Style > Java, Imports tab.  Check Use single class import.  For "Class count to use import with '*'" choose some improbably high number, like 200.  Or higher.
  • In Eclipse: Preferences > Java > Code Style > Organize Imports.  For "Number of imports needed for .*", choose some improbably high number.

Avoid static imports.

  • In Intellij, go to Preferences > Editor > Code Style > Java, Imports tab.  For "Names count to use static import with '*'": choose an improbably high number; again, 200 seems decent.  When Intellij offers a helper which tempts you with a static import, do not choose that foul option.
  • In Eclipse: Preferences > Java > Editor > Content Assist:  Uncheck "Use static imports".

Have IDE add license headers.

  • In Intellij, go to Preferences > Editor > File and Code templates, Files tab.  In the various file types, add the proper code template.  Be aware that Intellij supports directives like ${YEAR}, which simplifies template creation.
  • In Eclipse, there is a different menu path to configure each file type.  Eclipse also supports directives like ${YEAR}.
    • For Java, go to Preferences > Java > Code Style > Code Templates > Comments > Files, and add the proper code template.  Check "Automatically add comments for new methods and types".  Note that the default comment for Types includes an @author tag, which should be removed.
    • For Javascript, go to Preferences > JavaScript > Code Style > Code Templates > Comments > Files, and add the proper code template.
    • For XML, go to Preferences > XML > XML Files > Editor > Templates > xml declaration, and add the proper code template.
    • For JSP and tag files, go to Preferences > Web > JSP Files > Editor > Templates.  Select the appropriate file types and add the proper code template.

Properly indent Java code: 4 spaces for a regular line and 4 spaces for a continuation indentation.

  • In Intellij, go to Preferences > Editor > Code Style > Java, Tabs and Indents tab.  Make sure that "Use tab character" is NOT checked.  Indent should be 4 spaces, Continuation Indent should be 4 spaces.
  • In Eclipse, go to Preferences > Java > Code Style > Formatter > Edit > Indentations tab.  Set "Indentation size" and "Tab size to 4", and set "Tab Policy" to "Spaces only".

Property indent JavaScript code: 4 spaces for a regular line and 4 spaces for a continuation line.

  • In Intellij, go to Preferences > Editor > Code Style > JavaScript, Tabs and Indents tab.  Make sure that "Use tab character" is NOT checked.  Indent should be 4 spaces, Continuation Indent should be 4 spaces.
  • In Eclipse, go to Preferences > JavaScript > Code Style > Formatter > Edit > Indentations tab.  Set "Indentation size" and "Tab size to 4", and set "Tab Policy" to "Spaces only".

Property indent XML code, too.  4 spaces per indentation.

  • In Intellij, go to Preferences > Editor > Code Style > XML, Tabs and Indents tab.  Make sure that "Use tab character" is NOT checked.  Indent should be 4 spaces.
  • In Eclipse, go to Preferences > XML > XML Files > Editor.  Select "Indent using spaces" and set "Indentation size" to 4.

All conditionals should have brackets, even those which are a single line long.

Guidelines

A single line of whitespace between methods is all that is needed.

Avoid JavaDocs which add no explanation beyond what can be easily deduced from the code.

Organize classes in a meaningful order as recommending in Java Coding Standards#ClassStructure

Avoid Importing Unwanted Classes

Sometimes it can be easy to import the wrong version of a class, often because of maven transitive dependencies. For example, we have upgraded libraries such as commons-lang and commons-collections to newer versions with new packages, but the older versions are still coming into the project as transitive dependencies. We have also removed some dependencies, such as guava and jdom from Kuali Financials, but these too are pulled in as transitive dependencies. We have added a maven plugin to fail the build at the compile phase if there are classes imported incorrectly. However, it can also be helpful to avoid these imports during development with help from your IDE.

  • In Intellij, go to Preferences > Editor > General > Auto Import, Java and enter the list of packages to exclude under Exclude from Import and Completion. The list of what to exclude can be found in the checkstyle.xml file in the root of the financials project. You can also exclude classes directly from the Class picker dialog.