From f26c755d42da1db5adcdcb082abd6ad26942d65d Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 17 Oct 2014 13:36:14 +0000 Subject: [PATCH] clang-format: [Java] Don't break immediately after "throws". Before: public void doSooooooooooooooooooooooooooomething() throws LooooooooooooooooooooooooooooongException {} After: public void doSooooooooooooooooooooooooooomething() throws LooooooooooooooooooooooooooooongException {} llvm-svn: 220041 --- clang/lib/Format/TokenAnnotator.cpp | 6 ++++++ clang/unittests/Format/FormatTestJava.cpp | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index c83ec60..1438202 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 4ae04e6..2bca3bb 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/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 -- 2.7.4