r241337 - clang-format: [Java/JS] Properly support instanceof and its precedence.
Daniel Jasper
djasper at google.com
Fri Jul 3 03:12:53 PDT 2015
Author: djasper
Date: Fri Jul 3 05:12:53 2015
New Revision: 241337
URL: http://llvm.org/viewvc/llvm-project?rev=241337&view=rev
Log:
clang-format: [Java/JS] Properly support instanceof and its precedence.
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=241337&r1=241336&r2=241337&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Jul 3 05:12:53 2015
@@ -1008,7 +1008,7 @@ private:
if (Tok.isNot(tok::identifier) || !Tok.Previous)
return false;
- if (Tok.Previous->is(TT_LeadingJavaAnnotation))
+ if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof))
return false;
// Skip "const" as it does not have an influence on whether this is a name.
@@ -1336,6 +1336,10 @@ private:
return 0;
if (Current->is(TT_RangeBasedForLoopColon))
return prec::Comma;
+ if ((Style.Language == FormatStyle::LK_Java ||
+ Style.Language == FormatStyle::LK_JavaScript) &&
+ Current->is(Keywords.kw_instanceof))
+ return prec::Relational;
if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
return Current->getPrecedence();
if (Current->isOneOf(tok::period, tok::arrow))
@@ -2238,7 +2242,8 @@ bool TokenAnnotator::canBreakBefore(cons
return true;
if (Right.is(tok::kw_typename) && Left.isNot(tok::kw_const))
return true;
- if (Left.isBinaryOperator() && !Left.isOneOf(tok::arrowstar, tok::lessless) &&
+ if ((Left.isBinaryOperator() || Left.is(TT_BinaryOperator)) &&
+ !Left.isOneOf(tok::arrowstar, tok::lessless) &&
Style.BreakBeforeBinaryOperators != FormatStyle::BOS_All &&
(Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None ||
Left.getPrecedence() == prec::Assignment))
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=241337&r1=241336&r2=241337&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Fri Jul 3 05:12:53 2015
@@ -67,6 +67,8 @@ TEST_F(FormatTestJava, FormatsInstanceOf
verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa instanceof\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
Style);
+ verifyFormat("return aaaaaaaaaaaaaaaaaaa instanceof bbbbbbbbbbbbbbbbbbbbbbb\n"
+ " && ccccccccccccccccccc instanceof dddddddddddddddddddddd;");
}
TEST_F(FormatTestJava, Chromium) {
More information about the cfe-commits
mailing list