r221256 - clang-format: [Java] Fix class declaration line breaks.

Daniel Jasper djasper at google.com
Tue Nov 4 02:53:14 PST 2014


Author: djasper
Date: Tue Nov  4 04:53:14 2014
New Revision: 221256

URL: http://llvm.org/viewvc/llvm-project?rev=221256&view=rev
Log:
clang-format: [Java] Fix class declaration line breaks.

Before:
  @SomeAnnotation()
  abstract
      class aaaaaaaaa<a> extends bbbbbbbbbbbb<b> implements cccccccccccc {
  }

After:
  @SomeAnnotation()
  abstract class aaaaaaaaa<a> extends bbbbbbbbbbbb<b>
      implements cccccccccccc {
  }

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=221256&r1=221255&r2=221256&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Nov  4 04:53:14 2014
@@ -1862,6 +1862,10 @@ bool TokenAnnotator::canBreakBefore(cons
         (Left.TokenText == "throws" || Left.TokenText == "extends" ||
          Left.TokenText == "implements"))
       return false;
+    if (Right.is(tok::identifier) &&
+        (Right.TokenText == "throws" || Right.TokenText == "extends" ||
+         Right.TokenText == "implements"))
+      return true;
   }
 
   if (Left.is(tok::at))

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=221256&r1=221255&r2=221256&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Nov  4 04:53:14 2014
@@ -82,6 +82,11 @@ TEST_F(FormatTestJava, ClassDeclarations
                "    implements cccccccccccc {\n"
                "}",
                getStyleWithColumns(76));
+  verifyFormat("@SomeAnnotation()\n"
+               "abstract class aaaaaaaaa<a> extends bbbbbbbbbbbb<b>\n"
+               "    implements cccccccccccc {\n"
+               "}",
+               getStyleWithColumns(76));
 }
 
 TEST_F(FormatTestJava, EnumDeclarations) {





More information about the cfe-commits mailing list