clang-format: [Java] Detect `native` keyword.

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

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

llvm-svn: 225839
This commit is contained in:
Nico Weber 2015-01-13 22:32:50 +00:00
parent e5dbcb7fd0
commit ed50166b6b
3 changed files with 5 additions and 1 deletions

View File

@ -551,6 +551,7 @@ struct AdditionalKeywords {
kw_implements = &IdentTable.get("implements"); kw_implements = &IdentTable.get("implements");
kw_instanceof = &IdentTable.get("instanceof"); kw_instanceof = &IdentTable.get("instanceof");
kw_interface = &IdentTable.get("interface"); kw_interface = &IdentTable.get("interface");
kw_native = &IdentTable.get("native");
kw_package = &IdentTable.get("package"); kw_package = &IdentTable.get("package");
kw_synchronized = &IdentTable.get("synchronized"); kw_synchronized = &IdentTable.get("synchronized");
kw_throws = &IdentTable.get("throws"); kw_throws = &IdentTable.get("throws");
@ -581,6 +582,7 @@ struct AdditionalKeywords {
IdentifierInfo *kw_implements; IdentifierInfo *kw_implements;
IdentifierInfo *kw_instanceof; IdentifierInfo *kw_instanceof;
IdentifierInfo *kw_interface; IdentifierInfo *kw_interface;
IdentifierInfo *kw_native;
IdentifierInfo *kw_package; IdentifierInfo *kw_package;
IdentifierInfo *kw_synchronized; IdentifierInfo *kw_synchronized;
IdentifierInfo *kw_throws; IdentifierInfo *kw_throws;

View File

@ -1749,7 +1749,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return Style.SpaceBeforeParens != FormatStyle::SBPO_Never; return Style.SpaceBeforeParens != FormatStyle::SBPO_Never;
if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private, if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private,
tok::kw_protected) || 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)) Right.is(TT_TemplateOpener))
return true; return true;
} }

View File

@ -292,6 +292,7 @@ TEST_F(FormatTestJava, Generics) {
verifyFormat("protected <R> ArrayList<R> get() {}"); verifyFormat("protected <R> ArrayList<R> get() {}");
verifyFormat("private <R> ArrayList<R> get() {}"); verifyFormat("private <R> ArrayList<R> get() {}");
verifyFormat("public static <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 final <X> Foo foo() {}");
verifyFormat("public abstract <X> Foo foo();"); verifyFormat("public abstract <X> Foo foo();");
verifyFormat("<T extends B> T getInstance(Class<T> type);"); verifyFormat("<T extends B> T getInstance(Class<T> type);");