]> granicus.if.org Git - clang/commitdiff
clang-format: Re-enable comment re-indentation for Java/JS.
authorDaniel Jasper <djasper@google.com>
Sun, 4 Jan 2015 09:11:17 +0000 (09:11 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 4 Jan 2015 09:11:17 +0000 (09:11 +0000)
This was broken by r224120.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225130 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestJava.cpp

index b50a9a9a127234e39f25e94451f21eeee7befa84..53876bab581915e16c569b7b5b507fa5c9a8418b 100644 (file)
@@ -905,12 +905,6 @@ unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
 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::breakProtrudingToken(const FormatToken &Current,
   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).
index d80cccdc4679a467222aff11802f3ea9d86e7a7b..b4f67afd9b44770bce1f1ef9cee4236e1130a1fb 100644 (file)
@@ -425,5 +425,18 @@ TEST_F(FormatTestJava, BreaksStringLiterals) {
             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