Reputation: 6109
How do I get Eclipse to format my code like this:
f(g(
jkdfjkfjdsklfjsdkf,
fjdkfjdskfjsdklfjsdfkljsd,
rijekfjdskj,
));
instead of:
f(
g(
jkdfjkfjdsklfjsdkf,
fjdkfjdskfjsdklfjsdfkljsd,
rijekfjdskj,
)
);
It's fine if it doesn't do that automatically, as long as it preserves it when I do it.
Even with "Line Wrapping > Never join already wrapped lines" checked and "Line Wrapping > Wrapping settings > Function Calls > Arguments" set to "Do not wrap", it still insists on converting the first version into the second. "Line Wrapping > Prefer wrapping outer expressions (keep nested expression on one line)" also seems to have no effect.
The only workarounds I can think of, which I'd rather avoid, are adding @formatter:off
/@formatter:on
comments, or completely not using the formatter.
Are there any ways to get Eclipse to prefer the first version, or at least not modify it? Thanks!
Upvotes: 0
Views: 391
Reputation:
It's not going to be possible to get Eclipse to format code like this because there is no way to specify to the formatter that function calls should be treated differently from other arguments.
However, it's possible to leave this format as-is when doing a formatting pass.
From the Eclipse [built-in]
configuration, the only thing that needs changing is to check Never join already wrapped lines as you have done, and also select Parentheses positions -> Method/constructor invocation: -> preserve positions
org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=
preserve_positions
Note that ...Function Calls -> Arguments should not be set to "Do not wrap", but to the default "Wrap where necessary".
Upvotes: 1