]> granicus.if.org Git - clang/commitdiff
clang-format: [Java] Don't break immediately after "throws".
authorDaniel Jasper <djasper@google.com>
Fri, 17 Oct 2014 13:36:14 +0000 (13:36 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 17 Oct 2014 13:36:14 +0000 (13:36 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJava.cpp

index c83ec604758ee99c66d323f2154d3d44ceedd746..14382021b521058cbb5db4a35219453402b8347b 100644 (file)
@@ -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)
index 4ae04e6b09e9e6fc2122a4a98beee12d66490575..2bca3bbe8926181f6ec9a32f03d7ef5ff8ad4c3e 100644 (file)
@@ -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