]> granicus.if.org Git - clang/commitdiff
clang-format: [Java] Detect `native` keyword.
authorNico Weber <nicolasweber@gmx.de>
Tue, 13 Jan 2015 22:32:50 +0000 (22:32 +0000)
committerNico Weber <nicolasweber@gmx.de>
Tue, 13 Jan 2015 22:32:50 +0000 (22:32 +0000)
Before:
  public native<X> Foo foo();

After:
  public native <X> Foo foo();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225839 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/FormatToken.h
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJava.cpp

index 7ffbfbd4eba067217029eab7dd047db2bcd0b6f9..4811e02dd2282018d05234814e467219dff6bb13 100644 (file)
@@ -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;
index 6ad1ad2cc7ffe928a7d19ddf77fdbef7a849049c..b4eb3656bdf23012fc2bbb5c1f899a7b651b308a 100644 (file)
@@ -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;
   }
index b187206e5c68dd0e04c81fa0889d95b3d27a7ef4..3c7cf327685df500e390acbc1f87f57de4326d1a 100644 (file)
@@ -292,6 +292,7 @@ TEST_F(FormatTestJava, Generics) {
   verifyFormat("protected <R> ArrayList<R> get() {}");
   verifyFormat("private <R> ArrayList<R> get() {}");
   verifyFormat("public static <R> ArrayList<R> get() {}");
+  verifyFormat("public static native <R> ArrayList<R> get();");
   verifyFormat("public final <X> Foo foo() {}");
   verifyFormat("public abstract <X> Foo foo();");
   verifyFormat("<T extends B> T getInstance(Class<T> type);");