This documents defines and describes coding style and standard used in Tigase projects source code.
Examples should be considered as non-normative, that is formatting choices should not be treated as rules.
A source file consists of, in order:
Additionally:
Wildcard imports can be used for:
following import ordering applies:
blank linejavax.* classesjava.* classesblank line; sorts before .)Following order of the elements of the class is mandatory:
final, static fields in following order:
publicprotectedpackage-privateprivatepublic enumstatic fields in following order:
publicprotectedpackage-privateprivatestatic initializer blockfinal fields in following order:
publicprotectedpackage-privateprivatefields without modifiers in following order:
publicprotectedpackage-privateprivatestatic method(s)static classesIn addition:
Braces follow the Kernighan and Ritchie style (Egyptian brackets):
else or a comma.All indentation (opening a new block of block-like construct) must be made with tabs. After the block, then indent returns to the previous.
Ideal tab-size: 4
Defined column limit is 120 characters and must be line-wrapped as described below Java code has a column limit of 100 characters. Except as noted below, any line that would exceed this limit must be line-wrapped, as explained in section Line-wrapping.
line-wrapping is a process of dividing long lines that would otherwise go over the defined Column Limit (above). It’s recommended to wrap lines whenever it’s possible even if they are not longer than defined limit.
A single blank line appears:
Multiple blank lines are not permitted.
Beyond where required by the language or other style rules, and apart from literals, comments and Javadoc, a single ASCII space also appears in the following places only.
if, for, while, switch, try, catch or synchronized, from an open parenthesis (() that follows it on that lineelse or catch, from a closing curly brace (}) that precedes it on that lineBefore any open curly brace ({), with two exceptions:
@SomeAnnotation({a, b}) (no space is used)String[][] x = {{"foo"}}; (no space is required between {{, by item 8 below)On both sides of any binary or ternary operator. This also applies to the following "operator-like" symbols:
<T extends Foo & Bar>catch (FooException | BarException e):) in an enhanced for ("foreach") statementthe arrow in a lambda expression: (String str) → str.length()
but not:
::) of a method reference, which is written like Object::toString.), which is written like object.toString(),:; or the closing parenthesis ()) of a castList<String> listHorizontal alignment is the practice of adding a variable number of additional spaces in your code with the goal of making certain tokens appear directly below certain other tokens on previous lines.
This practice is permitted, but is never required. It is not even required to maintain horizontal alignment in places where it was already used.
int a, b; are not used.Identifiers use only ASCII letters and digits, and, in a small number of cases noted below, underscores. Thus each valid identifier name is matched by the regular expression \w+ .
CONSTANT_CASE: all uppercase letters, with words separated by underscores.@Override annotation whenever it is legal. This includes a class method overriding a superclass method, a class method implementing an interface method, and an interface method re-specifying a super-interface method.blank lines should be inserted after:
empty tag should be included for following tags:
@params@return@throwsAt the minimum, Javadoc is present for every public class, and every public or protected member of such a class, with a few exceptions:
getFoo, in cases where there really and truly is nothing else worthwhile to say but "Returns the foo".