Search code examples
javaeclipseformatter

How to make eclipse formatter keep while statement on same line?


I want the eclipse formatter to keep

while(condition) doSomething();

formatted as-is, rather than changing it to

while(condition)
    doSomething();

I can't seem to find an option for it to do this. Is this possible with the eclipse formatter?


Solution

  • As of this commit in July 2018, this is now possible.

    The eclipse formatter now contains the options "Keep simple 'for' loop body on same line," "Keep simple 'while' loop body on same line, and "Keep simple 'do while' loop body on same line," which do exactly what I originally asked for.

    In settings -> Java -> formatter, if you click "Edit", you can find them under New Lines -> In control statements -> Simple loops

    Eclipse formatter preferences