CodeStyle Braces and Wrapping Problem: In Method Declaration 'Next Line If Wrapped' not working?
Hello,
I've been trying to refactor our code base following a Next Line If Wrapped logic for braces:
-
Next line if wrapped: select this option to have the opening brace placed at the beginning of the line after the multiline declaration line.
I'm under the assumption that if the method declaration is just a single declaration line, then the left curly brace should be End Of Line.
However, whenever I try to reformat with the setting Next Line If Wrapped enabled for Method Declaration:

It doesn't seem to correct this example:
private void dummyMethod()
{
System.out.println("hi");
}
Which should be this:
private void dummyMethod() {
System.out.println("hi");
}
Is my assumption about Next Line if Wrapped incorrect? And if so, is there a way to configure CodeStyle to achieve the above result (while still maintaining the new line if wrapped rule for multiline declaration statements)?
Please sign in to leave a comment.
You should disable Settings (Preferences on macOS) | Editor | Code Style | Java | Wrapping and Braces | Keep when reformatting | Line breaks.
Hi Serge,
I disabled the setting:
But it appears that it still won't refactor.
For additional context, prior to disabling Line Breaks, refactoring Next Line if Wrapped for Class Declarations seems to work:
Would refactor to this:
class Foo {This is still the case after disabling Line Breaks.
It looks like this issue is already mentioned here: https://youtrack.jetbrains.com/issue/IDEA-178569/Quirks-and-non-deterministic-behaviour-with-Java-code-formatter.
Currently, "Next line if wrapped" keeps it wrapped if it was already wrapped, either because the line was long or when the user explicitly added a newline.
I see, thank you for the heads up!