r220287 - clang-format: [Java] Understand string literal concatenation.
Daniel Jasper
djasper at google.com
Tue Oct 21 04:34:53 PDT 2014
Author: djasper
Date: Tue Oct 21 06:34:53 2014
New Revision: 220287
URL: http://llvm.org/viewvc/llvm-project?rev=220287&view=rev
Log:
clang-format: [Java] Understand string literal concatenation.
Before:
String someString = "abc" + "cde";
After:
String someString = "abc"
+ "cde";
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=220287&r1=220286&r2=220287&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Oct 21 06:34:53 2014
@@ -1805,6 +1805,9 @@ bool TokenAnnotator::mustBreakBefore(con
if (Left.Type == TT_JavaAnnotation && Right.isNot(tok::l_paren) &&
Line.Last->is(tok::l_brace))
return true;
+ if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next &&
+ Right.Next->is(tok::string_literal))
+ return true;
}
return false;
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=220287&r1=220286&r2=220287&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Oct 21 06:34:53 2014
@@ -97,5 +97,10 @@ TEST_F(FormatTestJava, Generics) {
verifyFormat("A.<B>doSomething();");
}
+TEST_F(FormatTestJava, StringConcatenation) {
+ verifyFormat("String someString = \"abc\"\n"
+ " + \"cde\";");
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list