java - How do I enforce blank lines around non-orphaned braces in Eclipse? -
the eclipse format tool (luna) not account
- enforcing 1 blank line before , after non-orphaned brace on non-function declaration.
for (...) {
, if (...) {
, } else {
, } catch (...) {
enforcing 0 blank lines before orphaned closing brace
}
.enforcing 1 blank line after orphaned closing brace, except when followed orphaned closing brace (rule 2 trumping rule 3).
terminology:
- non-orphaned = paired operator/keyword
- non-function = not 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; // blank line (int x = 0; x < foo; x++) { // blank line if (x < value) { // blank line try { // blank line result = methodcall(x); result.setbar(outtareach); handleresult(x, result); x = z % 5; // blank line } catch (exception ex) { // blank line dosomething(x, ex); // no blank line - orphan } // blank line } else { // blank line othercall(x); // no blank line - orphan } // no blank line - orphan } // blank line ...
my reasons enhance code readability; i'll let jvm handle optimization. opinions regarding desired formatting style aside, is there way enforce particular blank line style within eclipse? perhaps there plug-in haven't yet found, or have code one?
the "blank lines" section of java code formatter of eclipse not provide ability enforce or apply this. of note, don't want force blank lines between code blocks not have braces (see string | int
, result | handleresult()
code blocks above examples).
closest settings have 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 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 preserve: 1
have @ jindent plugin; it's commercial might able achieve complex rules you're looking for.
Comments
Post a Comment