Skip to content
Sebastian Schlicht edited this page Mar 3, 2016 · 10 revisions

Code formatting

We use auto formatting of Eclipse's save actions as this is the most comfortable way to avoid any merge conflicts due to formatting.

Formatter settings

Download our eclipse coding style.

In Eclipse do the following: Right-click metalcon project -> Properties -> Java Code Style -> Formatter. Enable project specific settings, then click Import and select the downloaded file. Make sure you have the new profile selected.

XML Formatting Settings

In addition to the formatter profile we need to adjust the formatting of XML files manually. In the Eclipse Settings go to XML > XML Files > Editor and apply:

  • Line width: 80
  • indentation via spaces
  • indentation size: 2 (see bugfix below)

Due to a bug in Eclipse you might not be able to change the indentation size. You have to open the preference file .metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.wst.xml.core.prefs in your workspace folder manually and add:

indentationSize=2

Save action settings

In Eclipse do the following: Right-click metalcon project -> Properties -> Java Editor -> Save Actions. Enable project specific settings and configure so you have these settings:

  • Format source code: Yes
    • Format all lines
  • Organize imports: Yes
  • Additional actions: Yes
    • 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 '@Override' annotations to implementations of interface methods
    • Add missing '@Deprecated' annotations
    • Remove unnecessary casts
    • Remove trailing white space on all lines
    • Correct indentation

Documentation

Atleast all public methods should be documented (this isn't the case yet, but we are getting there).

Write full english sentences. Start a sentence with a Capital and end it with a dot.

Naming

Names/identifies/files are written in lowerCamelCase. This means the first letter is lowercase, and every letter that starts a new word is upper case. There are no spaces or hypens seperating words. For exmample: "Requirements Band" become requirementBand. All the following names are wrong: RequirementsBand, requirementsband, requirements band, requirements_band, requirement-bands.

Abbreviations are treated normal words. Meaning myHtmlParser is right, wrong would be: myHTMLParser.

Class names, Interfaces and Inheritance

Classes always start with a capital letter. Subclasses always take the name of their superclass as suffix. Eg:

  • Baseclass: class Band {};
  • Subclass: class MetalBand extending Band {};
  • Subclass: class HeavyMetalBand extending MetalBand {};
  • Interfaces: Usually end on able or ing.

Newline at EOF

Every file that contains text (.txt, .md, XML, ...) should end with a newline at the end of file.

This is neccessary in order to proberly use files from the console.

This is how a file with newline at eof is displayed:

$ cat helloWorld.txt
Hello, World!
$ exit

This is how a file without newline at eof is displayed:

$ cat helloWorld.txt
Hello, World!$ exit

Most Linux commands / file editors automatically add newlines at end of files. The online git wiki editor however does not.

Clone this wiki locally