The Eclipse format tool (Luna) does not account for
- Enforcing 1 blank line before and after a non-orphaned brace on non-function declaration.
for (...) {
, if (...) {
, } else {
, } catch (...) {
Enforcing 0 blank lines before an orphaned closing brace
}
.Enforcing 1 blank line after an orphaned closing brace, except when followed by another orphaned closing brace (rule 2 trumping rule 3).
Terminology:
- non-orphaned = paired with operator/keyword
- non-function = not a class or method declaration
Example:
...
someCall();
} // ORPHAN CLOSE BRACE - NO BLANK LINE BEFORE OR AFTER
} // ORPHAN CLOSE BRACE – BLANK LINE AFTER
someOtherCall();
} // ORPHAN CLOSE BRACE – NO BLANK LINE BEFORE
...
String result;
int foo = 1000;
// a blank line
for (int x = 0; x < foo; x++) {
// a blank line
if (x < value) {
// a blank line
try {
// a blank line
result = methodCall(x);
result.setBar(outtaReach);
handleResult(x, result);
x = z % 5;
// a blank line
} catch (Exception ex) {
// a blank line
doSomething(x, ex); // no blank line - orphan
}
// a blank line
} else {
// a blank line
otherCall(x); // no blank line - orphan
} // no blank line - orphan
}
// a blank line
...
My reasons for this are to enhance code readability; I'll let the JVM handle optimization. Opinions regarding my desired formatting style aside, is there a way to enforce this particular blank line style within Eclipse? Perhaps there is a plug-in to do this that I haven't yet found, or would I have to code one?
The "Blank Lines" section of the Java Code Formatter of Eclipse does not provide the ability to enforce or apply this. Of note, I don't want to force blank lines between code blocks that do not have braces (see the String | int
and result | handleResult()
code blocks above as examples).
Closest settings I have to this is:
Blank lines in compilation unit
- Before package declaration: 0
- After package declaration: 1
- Before import declaration: 1
- Between import groups: 0
- After import declaration: 1
- Between class declarations: 1
Blank lines within class declarations
- Before first declaration: 1
- Before declarations of the same kind: 1
- Before member class declarations: 1
- Before field declarations: 0
- Before method declarations: 1
- At beginning of method body: 1
Existing blank lines
- Number of empty lines to preserve: 1