r222527 - clang-format: [Java] Support more Java keywords.
Daniel Jasper
djasper at google.com
Fri Nov 21 04:19:07 PST 2014
Author: djasper
Date: Fri Nov 21 06:19:07 2014
New Revision: 222527
URL: http://llvm.org/viewvc/llvm-project?rev=222527&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=222527&r1=222526&r2=222527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Fri Nov 21 06:19:07 2014
@@ -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;
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=222527&r1=222526&r2=222527&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Nov 21 06:19:07 2014
@@ -1710,8 +1710,9 @@ bool TokenAnnotator::spaceRequiredBefore
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;
}
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222527&r1=222526&r2=222527&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Fri Nov 21 06:19:07 2014
@@ -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;");
More information about the cfe-commits
mailing list