r225130 - clang-format: Re-enable comment re-indentation for Java/JS.

Daniel Jasper djasper at google.com
Sun Jan 4 01:11:18 PST 2015


Author: djasper
Date: Sun Jan  4 03:11:17 2015
New Revision: 225130

URL: http://llvm.org/viewvc/llvm-project?rev=225130&view=rev
Log:
clang-format: Re-enable comment re-indentation for Java/JS.

This was broken by r224120.

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=225130&r1=225129&r2=225130&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sun Jan  4 03:11:17 2015
@@ -905,12 +905,6 @@ unsigned ContinuationIndenter::addMultil
 unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
                                                     LineState &State,
                                                     bool DryRun) {
-  // FIXME: String literal breaking is currently disabled for Java and JS, as
-  // it requires strings to be merged using "+" which we don't support.
-  if (Style.Language == FormatStyle::LK_Java ||
-      Style.Language == FormatStyle::LK_JavaScript)
-    return 0;
-
   // Don't break multi-line tokens other than block comments. Instead, just
   // update the state.
   if (Current.isNot(TT_BlockComment) && Current.IsMultiline)
@@ -929,6 +923,12 @@ unsigned ContinuationIndenter::breakProt
   unsigned ColumnLimit = getColumnLimit(State);
 
   if (Current.isStringLiteral()) {
+    // FIXME: String literal breaking is currently disabled for Java and JS, as
+    // it requires strings to be merged using "+" which we don't support.
+    if (Style.Language == FormatStyle::LK_Java ||
+        Style.Language == FormatStyle::LK_JavaScript)
+      return 0;
+
     // Don't break string literals inside preprocessor directives (except for
     // #define directives, as their contents are stored in separate lines and
     // are not affected by this check).

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=225130&r1=225129&r2=225130&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Jan  4 03:11:17 2015
@@ -425,5 +425,18 @@ TEST_F(FormatTestJava, BreaksStringLiter
             format("\"some text other\";", getStyleWithColumns(14)));
 }
 
+TEST_F(FormatTestJava, AlignsBlockComments) {
+  EXPECT_EQ("/*\n"
+            " * Really multi-line\n"
+            " * comment.\n"
+            " */\n"
+            "void f() {}",
+            format("  /*\n"
+                   "   * Really multi-line\n"
+                   "   * comment.\n"
+                   "   */\n"
+                   "  void f() {}"));
+}
+
 } // end namespace tooling
 } // end namespace clang





More information about the cfe-commits mailing list