r222424 - clang-format: [Java] Don't align after "return".
Daniel Jasper
djasper at google.com
Thu Nov 20 01:54:49 PST 2014
Author: djasper
Date: Thu Nov 20 03:54:49 2014
New Revision: 222424
URL: http://llvm.org/viewvc/llvm-project?rev=222424&view=rev
Log:
clang-format: [Java] Don't align after "return".
Doesn't seem to be common practice in Java.
Before:
return aaaaaaaaaaaaaaaaaaa
&& bbbbbbbbbbbbbbbbbbb
&& ccccccccccccccccccc;
After:
return aaaaaaaaaaaaaaaaaaa
&& bbbbbbbbbbbbbbbbbbb
&& ccccccccccccccccccc;
Patch by Harry Terkelsen.
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=222424&r1=222423&r2=222424&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Nov 20 03:54:49 2014
@@ -740,7 +740,8 @@ void ContinuationIndenter::moveStatePast
// a builder type call after 'return' or, if the alignment after opening
// brackets is disabled.
if (!Current.isTrailingComment() &&
- (!Previous || Previous->isNot(tok::kw_return) || *I > 0) &&
+ (!Previous || Previous->isNot(tok::kw_return) ||
+ (Style.Language != FormatStyle::LK_Java && *I > 0)) &&
(Style.AlignAfterOpenBracket || *I != prec::Comma ||
Current.NestingLevel == 0))
NewParenState.Indent =
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222424&r1=222423&r2=222424&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Thu Nov 20 03:54:49 2014
@@ -302,5 +302,20 @@ TEST_F(FormatTestJava, CppKeywords) {
verifyFormat("public void delete(Object o);");
}
+TEST_F(FormatTestJava, NeverAlignAfterReturn) {
+ verifyFormat("return aaaaaaaaaaaaaaaaaaa\n"
+ " && bbbbbbbbbbbbbbbbbbb\n"
+ " && ccccccccccccccccccc;",
+ getStyleWithColumns(40));
+ verifyFormat("return (result == null)\n"
+ " ? aaaaaaaaaaaaaaaaa\n"
+ " : bbbbbbbbbbbbbbbbb;",
+ getStyleWithColumns(40));
+ verifyFormat("return aaaaaaaaaaaaaaaaaaa()\n"
+ " .bbbbbbbbbbbbbbbbbbb()\n"
+ " .ccccccccccccccccccc();",
+ getStyleWithColumns(40));
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list