This fixes llvm.org/PR21436.
llvm-svn: 222641
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");
IdentifierInfo *kw_extends;
IdentifierInfo *kw_final;
IdentifierInfo *kw_implements;
+ IdentifierInfo *kw_instanceof;
IdentifierInfo *kw_interface;
IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws;
// 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)) {
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"