From: Daniel Jasper Date: Fri, 21 Nov 2014 12:19:07 +0000 (+0000) Subject: clang-format: [Java] Support more Java keywords. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29bc9e51554646093f95470aa7a7aee3244951ac;p=clang clang-format: [Java] Support more Java keywords. Before: public final Foo foo() { } public abstract Foo foo(); After: public final Foo foo() { } public abstract Foo foo(); Patch by Harry Terkelsen. Thank you. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222527 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index 7ced6eac40..053a3b050e 100644 --- a/lib/Format/FormatToken.h +++ b/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/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 6d9006be30..b376ec95c1 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index f6ab7d32cd..53df9af123 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -229,6 +229,8 @@ TEST_F(FormatTestJava, Generics) { verifyFormat("protected ArrayList get() {\n}"); verifyFormat("private ArrayList get() {\n}"); verifyFormat("public static ArrayList get() {\n}"); + verifyFormat("public final Foo foo() {\n}"); + verifyFormat("public abstract Foo foo();"); verifyFormat(" T getInstance(Class type);"); verifyFormat("Function function;");