From: Daniel Jasper Date: Fri, 17 Oct 2014 13:36:14 +0000 (+0000) Subject: clang-format: [Java] Don't break immediately after "throws". X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30622663a58dd3f6b869f6f6c259ec582942b836;p=clang clang-format: [Java] Don't break immediately after "throws". Before: public void doSooooooooooooooooooooooooooomething() throws LooooooooooooooooooooooooooooongException {} After: public void doSooooooooooooooooooooooooooomething() throws LooooooooooooooooooooooooooooongException {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220041 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index c83ec60475..14382021b5 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1791,6 +1791,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { const FormatToken &Left = *Right.Previous; + + if (Style.Language == FormatStyle::LK_Java) { + if (Left.is(tok::identifier) && Left.TokenText == "throws") + return false; + } + if (Left.is(tok::at)) return false; if (Left.Tok.getObjCKeywordID() == tok::objc_interface) diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 4ae04e6b09..2bca3bbe89 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -37,12 +37,6 @@ protected: return format(Code, 0, Code.size(), Style); } - static FormatStyle getGoogleJSStyleWithColumns(unsigned ColumnLimit) { - FormatStyle Style = getGoogleStyle(FormatStyle::LK_Java); - Style.ColumnLimit = ColumnLimit; - return Style; - } - static void verifyFormat( llvm::StringRef Code, const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) { @@ -65,5 +59,10 @@ TEST_F(FormatTestJava, ClassDeclarations) { "}"); } +TEST_F(FormatTestJava, ThrowsDeclarations) { + verifyFormat("public void doSooooooooooooooooooooooooooomething()\n" + " throws LooooooooooooooooooooooooooooongException {}"); +} + } // end namespace tooling } // end namespace clang