r222357 - clang-format: [Java] Ignore C++-specific keywords
Daniel Jasper
djasper at google.com
Wed Nov 19 06:11:11 PST 2014
Author: djasper
Date: Wed Nov 19 08:11:11 2014
New Revision: 222357
URL: http://llvm.org/viewvc/llvm-project?rev=222357&view=rev
Log:
clang-format: [Java] Ignore C++-specific keywords
Before:
public void union
(Object o);
public void struct
(Object o);
public void delete (Object o);
After:
public void union(Object o);
public void struct(Object o);
public void delete(Object o);
Patch by Harry Terkelsen, thank you!
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=222357&r1=222356&r2=222357&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Nov 19 08:11:11 2014
@@ -1688,6 +1688,11 @@ private:
IdentifierInfo &Info = IdentTable.get(FormatTok->TokenText);
FormatTok->Tok.setIdentifierInfo(&Info);
FormatTok->Tok.setKind(Info.getTokenID());
+ if (Style.Language == FormatStyle::LK_Java &&
+ FormatTok->isOneOf(tok::kw_struct, tok::kw_union, tok::kw_delete)) {
+ FormatTok->Tok.setKind(tok::identifier);
+ FormatTok->Tok.setIdentifierInfo(nullptr);
+ }
} else if (FormatTok->Tok.is(tok::greatergreater)) {
FormatTok->Tok.setKind(tok::greater);
FormatTok->TokenText = FormatTok->TokenText.substr(0, 1);
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222357&r1=222356&r2=222357&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Wed Nov 19 08:11:11 2014
@@ -275,5 +275,11 @@ TEST_F(FormatTestJava, MethodDeclaration
getStyleWithColumns(40));
}
+TEST_F(FormatTestJava, CppKeywords) {
+ verifyFormat("public void union(Type a, Type b);");
+ verifyFormat("public void struct(Object o);");
+ verifyFormat("public void delete(Object o);");
+}
+
} // end namespace tooling
} // end namespace clang
More information about the cfe-commits
mailing list