]> granicus.if.org Git - clang/commitdiff
Don't break string literals in Java and JavaScript.
authorAlexander Kornienko <alexfh@google.com>
Fri, 12 Dec 2014 13:03:22 +0000 (13:03 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 12 Dec 2014 13:03:22 +0000 (13:03 +0000)
The proper way to break string literals in these languages is by inserting a "+"
between parts which we don't support yet. So we disable string literal breaking
until then.

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

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

index e709cfbfc8512f206f5185c80091c7c3a9ba82b8..af4e1735dbf8655be26eaf68280515eb4a9792c9 100644 (file)
@@ -923,6 +923,12 @@ static bool getRawStringLiteralPrefixPostfix(StringRef Text, StringRef &Prefix,
 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)
index 6f7e43f325ce58a0db668d8bc880411c38be9b4a..d80cccdc4679a467222aff11802f3ea9d86e7a7b 100644 (file)
@@ -418,5 +418,12 @@ TEST_F(FormatTestJava, FormatsLambdas) {
                getStyleWithColumns(40));
 }
 
+TEST_F(FormatTestJava, BreaksStringLiterals) {
+  // FIXME: String literal breaking is currently disabled for Java and JS, as it
+  // requires strings to be merged using "+" which we don't support.
+  EXPECT_EQ("\"some text other\";",
+            format("\"some text other\";", getStyleWithColumns(14)));
+}
+
 } // end namespace tooling
 } // end namespace clang