summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/FormatTokenLexer.cpp13
-rw-r--r--clang/unittests/Format/FormatTestJava.cpp12
2 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index 9415dbe9ab3..4ee43d6937e 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -84,6 +84,19 @@ void FormatTokenLexer::tryMergePreviousTokens() {
if (tryMergeTokens(JSRightArrow, TT_JsFatArrow))
return;
}
+
+ if (Style.Language == FormatStyle::LK_Java) {
+ static const tok::TokenKind JavaRightLogicalShift[] = {tok::greater,
+ tok::greater,
+ tok::greater};
+ static const tok::TokenKind JavaRightLogicalShiftAssign[] = {tok::greater,
+ tok::greater,
+ tok::greaterequal};
+ if (tryMergeTokens(JavaRightLogicalShift, TT_BinaryOperator))
+ return;
+ if (tryMergeTokens(JavaRightLogicalShiftAssign, TT_BinaryOperator))
+ return;
+ }
}
bool FormatTokenLexer::tryMergeNSStringLiteral() {
diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp
index ee09ca940f1..6e685f6703e 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -522,5 +522,17 @@ TEST_F(FormatTestJava, AlignsBlockComments) {
" void f() {}"));
}
+TEST_F(FormatTestJava, RetainsLogicalShifts) {
+ verifyFormat("void f() {\n"
+ " int a = 1;\n"
+ " a >>>= 1;\n"
+ "}");
+ verifyFormat("void f() {\n"
+ " int a = 1;\n"
+ " a = a >>> 1;\n"
+ "}");
+}
+
+
} // end namespace tooling
} // end namespace clang
OpenPOWER on IntegriCloud