From: Nico Weber Date: Tue, 13 Jan 2015 22:32:50 +0000 (+0000) Subject: clang-format: [Java] Detect `native` keyword. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dee97ba884a96100a248dd74832489711ee827a2;p=clang clang-format: [Java] Detect `native` keyword. Before: public native Foo foo(); After: public native Foo foo(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225839 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 7ffbfbd4eb..4811e02dd2 100644 --- a/lib/Format/FormatToken.h +++ b/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/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 6ad1ad2cc7..b4eb3656bd 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index b187206e5c..3c7cf32768 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/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);");