<div dir="ltr">Hello!<div><br></div><div>I've been a long-time clang-format user for C++ and it works really well - so heartfelt thanks for it!</div><div><br></div><div>Now that BreakAfterJavaFieldAnnotations has been added in 3.9, it becomes also quite usable for Java.</div><div><br></div><div>So I experimented a bit with v3.9.0-r262937 on a Java project, but found a couple of issues.</div><div><br></div><div>My goal was to get as close as possible to vanilla Sun Java formatting style.</div><div><div>Here are the .clang-format rules that should achieve this, to the best of my knowledge (see e.g. <a href="https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml">https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml</a>):</div><div><br></div><div><div>AccessModifierOffset: -4</div><div>AllowShortBlocksOnASingleLine: false<br></div><div>AllowShortFunctionsOnASingleLine: None</div><div>AllowShortIfStatementsOnASingleLine: false</div><div>AllowShortLoopsOnASingleLine: false</div><div>BreakBeforeBinaryOperators: false<br></div><div>BreakBeforeBraces: Attach</div><div>BreakAfterJavaFieldAnnotations: true<br></div><div>ColumnLimit: 120 <-- *this is the only non-standard part*</div><div>IndentCaseLabels: true</div><div>IndentWidth: 4</div><div>MaxEmptyLinesToKeep: 1</div><div>SpaceBeforeAssignmentOperators: true</div><div>SpaceBeforeParens: ControlStatements</div><div>SpacesInParentheses: false</div><div>TabWidth: 4</div><div>UseTab: Never</div></div></div><div><br></div><div>Issues:</div><div><br></div><div>1. No break before lambda body</div><div><br></div><div>Eclipse formats Java 8 lambdas consistently with the "line break after brace" style, but clang-format does not.</div><div><br></div><div>Compare:</div><div><br></div><div>clang-format with the configuration above:</div><div><br></div><div><div>        final Button logsButton = new Button("Logs");</div><div>        logsButton.addClickListener((e) -> { getNavigator().navigateTo("logs"); });</div><div>        actions.addComponent(logsButton);</div></div><div><br></div><div>Eclipse:</div><div><br></div><div><div>        final Button logsButton = new Button("Logs");</div><div>        logsButton.addClickListener((e) -> {</div><div>            getNavigator().navigateTo("logs");</div><div>        });</div><div>        actions.addComponent(logsButton);</div></div><div><br></div><div>What do you think, is clang-format behavior justified? Shouldn't "AllowShortFunctionsOnASingleLine: None" force a break?</div><div>Maybe even a separate configuration parameter AllowShortLambdasOnASingleLine should be added?</div><div><br></div><div>2. Odd formatting of a short interface declaration<br></div><div><br></div><div><div>Given the following interface declaration as formatted by Eclipse:</div><div><br></div><div><div>public interface LoginView {</div><div>    void showError(String message);</div><div>}</div></div></div><div><br></div><div>for some reason, clang-format formats this on one line:</div><div><br></div><div>public interface LoginView { void showError(String message); }<br></div><div><br></div><div>This is really odd for Java-accustomed eyes. I didn't find any other AllowShort... directives besides the ones listed above to turn this off.</div><div><br></div><div>Again, what do you think, is clang-format behavior justified?</div><div><div>Should we add a configuration parameter to control this (AllowShortClassesOnASingleLine or some such)?</div></div><div><br></div><div>---</div><div><br></div><div><div>It would be really nice if clang-format could support the Sun vanilla style and Eclipse and clang-format could be made to co-exist, so that their formatting would be identical if configured properly.</div></div><div><br></div><div>Thanks in advance for any comments,</div><div>Mart</div></div>