r222829 - clang-format: [Java] Improve formatting of throws declarations.

Daniel Jasper djasper at google.com
Wed Nov 26 04:31:20 PST 2014


Author: djasper
Date: Wed Nov 26 06:31:19 2014
New Revision: 222829

URL: http://llvm.org/viewvc/llvm-project?rev=222829&view=rev
Log:
clang-format: [Java] Improve formatting of throws declarations.

Before:
  public void doSoooooooooo() throws LoooooooooongException,
      LooooooooooongException {}

After:
  public void doSoooooooooo()
      throws LoooooooooongException, LooooooooooongException {}

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222829&r1=222828&r2=222829&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov 26 06:31:19 2014
@@ -1200,7 +1200,8 @@ private:
       else if (Current->isOneOf(tok::period, tok::arrow))
         return PrecedenceArrowAndPeriod;
       else if (Style.Language == FormatStyle::LK_Java &&
-               Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements))
+               Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
+                                Keywords.kw_throws))
         return 0;
     }
     return -1;
@@ -1470,7 +1471,7 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Style.Language == FormatStyle::LK_Java) {
     if (Left.is(TT_LeadingJavaAnnotation))
       return 1;
-    if (Right.is(Keywords.kw_extends))
+    if (Right.isOneOf(Keywords.kw_extends, Keywords.kw_throws))
       return 1;
     if (Right.is(Keywords.kw_implements))
       return 2;

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222829&r1=222828&r2=222829&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Wed Nov 26 06:31:19 2014
@@ -202,6 +202,8 @@ TEST_F(FormatTestJava, ArrayInitializers
 TEST_F(FormatTestJava, ThrowsDeclarations) {
   verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
                "    throws LooooooooooooooooooooooooooooongException {}");
+  verifyFormat("public void doSooooooooooooooooooooooooooomething()\n"
+               "    throws LoooooooooongException, LooooooooooongException {}");
 }
 
 TEST_F(FormatTestJava, Annotations) {





More information about the cfe-commits mailing list