From 90992a9c9fb002201de6cdb2a9a4720b70d5fee6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 15 Sep 2015 23:48:17 +0000 Subject: [PATCH] clang-format: In Java, `assert` is followed by an expression. Before: assert a&& b; Now: assert a && b; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247750 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 2 ++ lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTestJava.cpp | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index f50558c6ec..8586337c86 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -539,6 +539,7 @@ struct AdditionalKeywords { kw_var = &IdentTable.get("var"); kw_abstract = &IdentTable.get("abstract"); + kw_assert = &IdentTable.get("assert"); kw_extends = &IdentTable.get("extends"); kw_implements = &IdentTable.get("implements"); kw_instanceof = &IdentTable.get("instanceof"); @@ -580,6 +581,7 @@ struct AdditionalKeywords { // Java keywords. IdentifierInfo *kw_abstract; + IdentifierInfo *kw_assert; IdentifierInfo *kw_extends; IdentifierInfo *kw_implements; IdentifierInfo *kw_instanceof; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 5dad651bd9..53027c79b3 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -860,7 +860,7 @@ private: Contexts.back().IsExpression = true; } else if (Current.is(TT_TrailingReturnArrow)) { Contexts.back().IsExpression = false; - } else if (Current.is(TT_LambdaArrow)) { + } else if (Current.is(TT_LambdaArrow) || Current.is(Keywords.kw_assert)) { Contexts.back().IsExpression = Style.Language == FormatStyle::LK_Java; } else if (Current.is(tok::l_paren) && !Line.MustBeDeclaration && !Line.InPPDirective && diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 8e590879f6..e74e797d50 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -393,6 +393,11 @@ TEST_F(FormatTestJava, SynchronizedKeyword) { "}"); } +TEST_F(FormatTestJava, AssertKeyword) { + verifyFormat("assert a && b;"); +} + + TEST_F(FormatTestJava, PackageDeclarations) { verifyFormat("package some.really.loooooooooooooooooooooong.package;", getStyleWithColumns(50)); -- 2.40.0