From: Daniel Jasper Date: Wed, 19 Nov 2014 14:11:11 +0000 (+0000) Subject: clang-format: [Java] Ignore C++-specific keywords X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=200069865f427e9dd336148b3847d2541fdc875b;p=clang 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! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222357 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index fe52fb5876..729ca97aab 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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); diff --git a/unittests/Format/FormatTestJava.cpp b/unittests/Format/FormatTestJava.cpp index 57a0d51542..c47cfa9214 100644 --- a/unittests/Format/FormatTestJava.cpp +++ b/unittests/Format/FormatTestJava.cpp @@ -275,5 +275,11 @@ TEST_F(FormatTestJava, MethodDeclarations) { 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