r222641 - clang-format: [Java] Treat 'instanceof' like other binary operators.
Daniel Jasper
djasper at google.com
Sun Nov 23 13:34:25 PST 2014
Author: djasper
Date: Sun Nov 23 15:34:25 2014
New Revision: 222641
URL: http://llvm.org/viewvc/llvm-project?rev=222641&view=rev
Log:
clang-format: [Java] Treat 'instanceof' like other binary operators.
This fixes llvm.org/PR21436.
Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=222641&r1=222640&r2=222641&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Sun Nov 23 15:34:25 2014
@@ -532,6 +532,7 @@ struct AdditionalKeywords {
kw_extends = &IdentTable.get("extends");
kw_final = &IdentTable.get("final");
kw_implements = &IdentTable.get("implements");
+ kw_instanceof = &IdentTable.get("instanceof");
kw_interface = &IdentTable.get("interface");
kw_synchronized = &IdentTable.get("synchronized");
kw_throws = &IdentTable.get("throws");
@@ -557,6 +558,7 @@ struct AdditionalKeywords {
IdentifierInfo *kw_extends;
IdentifierInfo *kw_final;
IdentifierInfo *kw_implements;
+ IdentifierInfo *kw_instanceof;
IdentifierInfo *kw_interface;
IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222641&r1=222640&r2=222641&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Nov 23 15:34:25 2014
@@ -795,8 +795,10 @@ private:
// Line.MightBeFunctionDecl can only be true after the parentheses of a
// function declaration have been found. In this case, 'Current' is a
// trailing token of this declaration and thus cannot be a name.
- if (isStartOfName(Current) &&
- (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
+ if (Current.is(Keywords.kw_instanceof)) {
+ Current.Type = TT_BinaryOperator;
+ } else if (isStartOfName(Current) &&
+ (!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
Contexts.back().FirstStartOfName = &Current;
Current.Type = TT_StartOfName;
} else if (Current.is(tok::kw_auto)) {
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222641&r1=222640&r2=222641&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Sun Nov 23 15:34:25 2014
@@ -54,6 +54,17 @@ TEST_F(FormatTestJava, NoAlternativeOper
verifyFormat("someObject.and();");
}
+TEST_F(FormatTestJava, FormatsInstanceOfLikeOperators) {
+ FormatStyle Style = getStyleWithColumns(50);
+ verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ " instanceof bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
+ Style);
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+ verifyFormat("return aaaaaaaaaaaaaaaaaaaaaaaaaaaaa instanceof\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;",
+ Style);
+}
+
TEST_F(FormatTestJava, ClassDeclarations) {
verifyFormat("public class SomeClass {\n"
" private int a;\n"
More information about the cfe-commits
mailing list