http://www.jindent.com |
|
Next: Lambda |
Brace style for constructor/method declarations |
Left brace { new line |
public void method() { ... |
public void method() { ... |
Right brace } new line |
Indent left brace { |
public·void·method() ····{ ····... |
public·void·method() { ... |
public·void·method()·{ ... |
public·void·method(){ ... |
Indent right brace } |
public·void·method() ····{ ····... ····} |
public·void·method() { ····... } |
Indent after right brace } |
Cuddle braces of empty blocks {} |
public void method() {} |
public void method() { } |
Indent cuddled braces {} |
public·void·method(){} |
public·void·method()·{} |
Prohibit blank lines after left brace { |
public void method() { ¶ // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } |
public void method() { // comment with a preceding blank line callAnotherMethod(); ¶ // another comment ... } |
See also: | Jindent - Settings - Formatter - Java / SQLJ - Blank Lines - Comments , Jindent - Settings - Formatter - Java / SQLJ - Blank Lines |
If number of lines in body is at least ... then insert blank line after { |
public int getCentimeters() { return measure; } ¶ public int getMeters() { int meters = measure / 100; return meters; } ¶ public void doSomething(int n) { callMethodA(n); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
getCentimeters()
looks fine,
but method doSomething(int)
seems to be formatted too close:
The method head public void doSomething(int n) {
and the first block statement
callMethodA(n);
are connected too close and could cause confusion.
public int getCentimeters() { return measure; } ¶ public int getMeters() { ¶ int meters = measure / 100; return meters; } ¶ public void doSomething(int n) { ¶ callMethodA(n); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
doSomething(int)
seems to be much clearer and
methodgetMeters()
is still formatted as before.
public int getCentimeters() { return measure; } ¶ public int getMeters() { int meters = measure / 100; return meters; } ¶ public void doSomething(int n) { ¶ callMethodA(n); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
getMeters()
is formatted in the same way as getCentimeters()
.
public int getCentimeters() { ¶ return measure; } ¶ public int getMeters() { ¶ int meters = measure / 100; return meters; } ¶ public void doSomething(int n) { ¶ callMethodA(n); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); } |
infinite
.If number of lines in body is at least ... then insert blank line before } |
public int getCentimeters() { return measure; } ¶ public int getMeters() { ¶ int meters = measure / 100; return meters; ¶ } ¶ public void doSomething(int n) { ¶ callMethodA(n); for (int i = 0; i < n; i++) { callMethodB(i); callMethodC(i); } callMethodD(i); ¶ } |
Do not insert blank line before single left brace |
See also: | Jindent - Settings - Formatter - Java / SQLJ - Braces Style - Presets |