From ed50166b6b552a3419f75142776296c20cb75992 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 13 Jan 2015 22:32:50 +0000 Subject: [PATCH] clang-format: [Java] Detect `native` keyword. Before: public native Foo foo(); After: public native Foo foo(); llvm-svn: 225839 --- clang/lib/Format/FormatToken.h | 2 ++ clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTestJava.cpp | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 7ffbfbd4eba0..4811e02dd228 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -551,6 +551,7 @@ struct AdditionalKeywords { kw_implements = &IdentTable.get("implements"); kw_instanceof = &IdentTable.get("instanceof"); kw_interface = &IdentTable.get("interface"); + kw_native = &IdentTable.get("native"); kw_package = &IdentTable.get("package"); kw_synchronized = &IdentTable.get("synchronized"); kw_throws = &IdentTable.get("throws"); @@ -581,6 +582,7 @@ struct AdditionalKeywords { IdentifierInfo *kw_implements; IdentifierInfo *kw_instanceof; IdentifierInfo *kw_interface; + IdentifierInfo *kw_native; IdentifierInfo *kw_package; IdentifierInfo *kw_synchronized; IdentifierInfo *kw_throws; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6ad1ad2cc7ff..b4eb3656bdf2 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1749,7 +1749,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return Style.SpaceBeforeParens != FormatStyle::SBPO_Never; if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private, tok::kw_protected) || - Left.isOneOf(Keywords.kw_final, Keywords.kw_abstract)) && + Left.isOneOf(Keywords.kw_final, Keywords.kw_abstract, + Keywords.kw_native)) && Right.is(TT_TemplateOpener)) return true; } diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index b187206e5c68..3c7cf327685d 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -292,6 +292,7 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("protected ArrayList get() {}"); verifyFormat("private ArrayList get() {}"); verifyFormat("public static ArrayList get() {}"); + verifyFormat("public static native ArrayList get();"); verifyFormat("public final Foo foo() {}"); verifyFormat("public abstract Foo foo();"); verifyFormat(" T getInstance(Class type);");