diff options
author | Daniel Jasper <djasper@google.com> | 2014-11-21 12:19:07 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-11-21 12:19:07 +0000 |
commit | 82c9275344f584f83945b1b247420b27abd8a791 (patch) | |
tree | 2d0de90b848d6b0378b04e5b5f739224dfa502f0 | |
parent | 43419a74ac2bd80f9b6215557f4e33bc074e3cb1 (diff) | |
download | bcm5719-llvm-82c9275344f584f83945b1b247420b27abd8a791.tar.gz bcm5719-llvm-82c9275344f584f83945b1b247420b27abd8a791.zip |
clang-format: [Java] Support more Java keywords.
Before:
public final<X> Foo foo() {
}
public abstract<X> Foo foo();
After:
public final <X> Foo foo() {
}
public abstract <X> Foo foo();
Patch by Harry Terkelsen. Thank you.
llvm-svn: 222527
-rw-r--r-- | clang/lib/Format/FormatToken.h | 4 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 7ced6eac409..053a3b050e4 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -546,7 +546,9 @@ struct AdditionalKeywords { kw_function = &IdentTable.get("function"); kw_var = &IdentTable.get("var"); + kw_abstract = &IdentTable.get("abstract"); kw_extends = &IdentTable.get("extends"); + kw_final = &IdentTable.get("final"); kw_implements = &IdentTable.get("implements"); kw_interface = &IdentTable.get("interface"); kw_synchronized = &IdentTable.get("synchronized"); @@ -569,7 +571,9 @@ struct AdditionalKeywords { IdentifierInfo *kw_var; // Java keywords. + IdentifierInfo *kw_abstract; IdentifierInfo *kw_extends; + IdentifierInfo *kw_final; IdentifierInfo *kw_implements; IdentifierInfo *kw_interface; IdentifierInfo *kw_synchronized; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 6d9006be30b..b376ec95c1b 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1710,8 +1710,9 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; if (Left.is(Keywords.kw_synchronized) && Right.is(tok::l_paren)) return Style.SpaceBeforeParens != FormatStyle::SBPO_Never; - if (Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private, - tok::kw_protected) && + if ((Left.isOneOf(tok::kw_static, tok::kw_public, tok::kw_private, + tok::kw_protected) || + Left.isOneOf(Keywords.kw_final, Keywords.kw_abstract)) && Right.Type == TT_TemplateOpener) return true; } diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index f6ab7d32cde..53df9af1234 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -229,6 +229,8 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("protected <R> ArrayList<R> get() {\n}"); verifyFormat("private <R> ArrayList<R> get() {\n}"); verifyFormat("public static <R> ArrayList<R> get() {\n}"); + verifyFormat("public final <X> Foo foo() {\n}"); + verifyFormat("public abstract <X> Foo foo();"); verifyFormat("<T extends B> T getInstance(Class<T> type);"); verifyFormat("Function<F, ? extends T> function;"); |