From ccb68b487e06c3744f8e4b25267d4a23ce90fd62 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 19 Nov 2014 22:38:18 +0000 Subject: [PATCH] clang-format: [Java] Accept generic types in enum declaration Before: enum Foo implements Bar { ABC { ... } , CDE { ... }; } After: enum Foo implements Bar { ABC { ... }, CDE { ... }; } Patch by Harry Terkelsen. llvm-svn: 222394 --- clang/lib/Format/UnwrappedLineParser.cpp | 11 ++++++----- clang/unittests/Format/FormatTestJava.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index d94e6c4..af1e94c 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1331,23 +1331,24 @@ void UnwrappedLineParser::parseAccessSpecifier() { void UnwrappedLineParser::parseEnum() { // Won't be 'enum' for NS_ENUMs. if (FormatTok->Tok.is(tok::kw_enum)) - nextToken(); + nextToken(); // Eat up enum class ... if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct)) nextToken(); while (FormatTok->Tok.getIdentifierInfo() || - FormatTok->isOneOf(tok::colon, tok::coloncolon)) { + FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less, + tok::greater, tok::comma, tok::question)) { nextToken(); // We can have macros or attributes in between 'enum' and the enum name. - if (FormatTok->Tok.is(tok::l_paren)) + if (FormatTok->is(tok::l_paren)) parseParens(); - if (FormatTok->Tok.is(tok::identifier)) + if (FormatTok->is(tok::identifier)) nextToken(); } // Just a declaration or something is wrong. - if (!FormatTok->is(tok::l_brace)) + if (FormatTok->isNot(tok::l_brace)) return; FormatTok->BlockKind = BK_Block; diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index c47cfa9..5c9bf1a 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -164,6 +164,20 @@ TEST_F(FormatTestJava, EnumDeclarations) { " public void f() {\n" " }\n" "}"); + verifyFormat("private enum SomeEnum implements Foo {\n" + " ABC {\n" + " @Override\n" + " public String toString() {\n" + " return \"ABC\";\n" + " }\n" + " },\n" + " CDE {\n" + " @Override\n" + " public String toString() {\n" + " return \"CDE\";\n" + " }\n" + " };\n" + "}"); } TEST_F(FormatTestJava, ThrowsDeclarations) { -- 2.7.4