]> granicus.if.org Git - clang/commitdiff
clang-format: In Java, `assert` is followed by an expression.
authorNico Weber <nicolasweber@gmx.de>
Tue, 15 Sep 2015 23:48:17 +0000 (23:48 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 15 Sep 2015 23:48:17 +0000 (23:48 +0000)
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
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJava.cpp

index f50558c6ecfc7aa0edfac763ed88798aa498ae9e..8586337c86c1b7d5ccc266bcf77e0ae90363c742 100644 (file)
@@ -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;
index 5dad651bd965011d281b790d0634a2a2df1dbfc4..53027c79b3642d10d9dc89c735384d68121aea71 100644 (file)
@@ -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 &&
index 8e590879f6e24c136f535ab08679d7d0983f2aee..e74e797d5042d3d1e4c6f5b1ae0ac300e7d79aec 100644 (file)
@@ -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));