r224120 - Don't break string literals in Java and JavaScript.
Alexander Kornienko
alexfh at google.com
Fri Dec 12 05:03:22 PST 2014
Author: alexfh
Date: Fri Dec 12 07:03:22 2014
New Revision: 224120
URL: http://llvm.org/viewvc/llvm-project?rev=224120&view=rev
Log:
Don't break string literals in Java and JavaScript.
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.
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=224120&r1=224119&r2=224120&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Dec 12 07:03:22 2014
@@ -923,6 +923,12 @@ static bool getRawStringLiteralPrefixPos
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)
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=224120&r1=224119&r2=224120&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Fri Dec 12 07:03:22 2014
@@ -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
More information about the cfe-commits
mailing list