...
Note | ||
---|---|---|
| ||
|
...
Code Block | ||||
---|---|---|---|---|
| ||||
collection.add(new A() { @Override public void m() { // Do something. } }); |
Use a shorter version of Javadoc (mostly for Javadoc Tag only):
Code Block | ||
---|---|---|
| ||
/**
* {@inheritDoc}
*/
public void m() { ... }
|
Code Block | ||
---|---|---|
| ||
/** {@inheritDoc} */
public void m() { ... } |
Same as described at Oracle's Java Code Conventions.
Except for types (classes, interfaces, enumerations and annotations) and semantic constants names all other names Except for types (classes, interfaces, enumerations and annotations) and semantic constants names all other names should start with low-case letter. Types names should start with an upper-case letter. In the both cases a camel style should be used. Symbol '_' (underscore) should be used only to separate upper-case letters in the names. Constants (final class attributes that have constant semantic and not just made final because of inner class access or performance considerations) should all be upper-case. For example (class comments ommitted):
...
Every type should start with at least minimal Javadoc comments including description and author information in the following form:
Code Block | ||||
---|---|---|---|---|
| ||||
/** * Type description. * * @author John Doe */ / |
Every method, Every method, field or initializer public, private or protected in top-level, inner or anonymous type should have at least minimal Javadoc comments including description and description of parameters using @param, @return and @throws Javadoc tags, where applicable. For example:
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* Description.
*
* @param i Integer parameter.
* @param f Float parameter. Long comment, foo
* bar, foo bar, foo bar.
* @return Double value.
*/
public double foo(int i, float f) {
}
| ||||
Code Block | ||||
java | java | /** Array index. One-line comment is only allowed for fields. */ private int index; |
Code Block | ||||
---|---|---|---|---|
| ||||
/** * Some meaningful comment. */ static { } |
...
All identifiers in the Javadoc comments must be placed within <tt></tt> or linked to, if possible, using {@link ClassName} or {@link ClassName#method} constructs.Note also that only fields allow
...
Method's javadoc should be equals to /** {@inheritDoc} */ in case it overrides or implements method without changing contracts declared at parent's javadoc.
Use a shorter version of {@inheritDoc}.
Code Block | ||
---|---|---|
| ||
/**
* {@inheritDoc}
*/
@Owerride public void m() { ... }
|
Code Block | ||
---|---|---|
| ||
/** {@inheritDoc} */
@Override public void m() { ... } |
One-line Javadoc comments allowed and preferred for fields.
Code Block | ||||
---|---|---|---|---|
| ||||
/** Array index. One-line comment is only allowed for fields. */
private int index; |
Note | ||
---|---|---|
| ||
|
Source code has special spacing rules (mostly inherited from Sun's Java source code guidelines and mentioned here for better clarity).
In comma-separated enumerations there is always a space between comma and the next element in the list. For example, foo(p1, p2, p3) Notice spaces between comma ',' and the next parameter.
There is always a space in between operands and binary operation itself. For example:
Code Block | ||||
---|---|---|---|---|
| ||||
a += b; b = a; a * (c + b) / d
|
There should be no space between unary operation and its operand. For example:
Code Block | ||||
---|---|---|---|---|
| ||||
!a, ~b, -b, b++
|
Notice also that all assignments by this rule should have space around '=' symbol: int a = b
Comments should be separated by space from "// ", "/ , "/** "* or " */". For example, / Notice the space. /
Use per-class importing.
In case of the naming conflict - use fully qualified names (FQN).
Use imports instead of FQNs in Javadoc links.
Import should be ordered alphabetically, but packages starting with 'java.' should be declared prior to others.
Static imports should follow same rules as regular imports and be separeted by a new line.
Code Block | ||
---|---|---|
| ||
import java.util.ArrayList;
import java.util.Collection;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.thread.IgniteThread;
import org.jsr166.ConcurrentHashMap8;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; |
Note | ||
---|---|---|
| ||
|
Source code has special spacing rules (mostly inherited from Sun's Java source code guidelines and mentioned here for better clarity).
In comma-separated enumerations there is always a space between comma and the next element in the list. For example, foo(p1, p2, p3) Notice spaces between comma ',' and the next parameter.
There is always a space in between operands and binary operation itself. For example:
...
a += b; b = a; a * (c + b) / d
There should be no space between unary operation and its operand. For example:
...
!a, ~b, -b, b++
Notice also that all assignments by this rule should have space around '=' symbol: int a = b
Comments should be separated by space from "// ", "/ , "/** "* or " */". For example, / Notice the space. /
Use per-class importing.
In case of the naming conflict - use fully qualified names (FQN).
Use imports instead of FQNs in Javadoc links.
Note | ||
---|---|---|
| ||
The source code should be broken into minimal semantic units and all such units must be separated by one empty line. To simplify the recognition of semantic units, the every line of the source code should be separated by one empty line except for the following cases:
Source code line should not be longer then 120 characters (to be visible on most conventional monitors). 4 space characters should be used for tabulation and indentation. IDE should be configured to replace tabulation with spaces (to properly see source code on the platforms with different tabulation sizes).
...
Source code line should not be longer then 120 characters (to be visible on most conventional monitors). 4 space characters should be used for tabulation and indentation. IDE should be configured to replace tabulation with spaces (to properly see source code on the platforms with different tabulation sizes).
Empty lines should be used according to following rules:
Where | Number of empty lines required |
---|---|
Before package statement | 0 |
Before imports | 1 |
Between imports and static imports | 1 |
Before class header | 1 |
After class header | 0 |
Between class definition and EOF | 1 |
Between class members (filelds, methods, initializers) | 1 |
Between minimal semantic units in the method or initializer body | 1 |
. Note that single blank line SHOULD NOT be used for the mere decoration of the source code. Avoid using double empty lines.
Blanks space (1 space character) should be used before opening ( or {. { and } should always be the last tokens in the line (except for the possible comments). However, blank space should not be used between method name and opening (.
For exampleExample:
Code Block | ||||
---|---|---|---|---|
| ||||
/** * Class definition example. * * @author @java.author * @version @java.version */ class Foo { /** * Example method. * * @param i Example parameter. * @throws MyException Thrown in case of any error. */ public void method(int i) throws MyException { if (i > 0) { // Do recursion. try { for (int j = 0; j < 10; j++) method(i--); } catch (MyException e) { e.printStackTrace(); } } switch (i) { case 10: return i - 1; case 11: i += 2; i /= 10; break; default: assert false; } // No javadoc for anonymous classes. MyInterface itf = new MyInterface() { @Override public int myMethod(int p) { return p++; } }; if (i < 0) { // Exit now. System.out.println("Woo-hoo"); System.out.println("One more Woo-hoo"); return; } } } | ||||
Note | ||||
| ||||
Strictly define empty lines policy in these situations, at least: |
If source code lines and/or Javadoc lines get longer than 120 characters it should be broken. The rule is to start consequent line 4 spaces to the right relatively to first line. All other lines 3rds, 4th, etc. (if overall line gets longer than 120x2) should start on the same indentation as 2nd line. No other decorative rules are allowed.
...