From: Daniel Jasper Date: Thu, 20 Nov 2014 09:54:49 +0000 (+0000) Subject: clang-format: [Java] Don't align after "return". X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6cab6784b927cc55eea7eef560077a963fc5a404;p=platform%2Fupstream%2Fllvm.git 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. llvm-svn: 222424 --- diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 24680ae..40b50dd 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -740,7 +740,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State, // 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 = diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 94070f4..cb96756 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -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