r222394 - clang-format: [Java] Accept generic types in enum declaration
Daniel Jasper
djasper at google.com
Wed Nov 19 14:38:19 PST 2014
Author: djasper
Date: Wed Nov 19 16:38:18 2014
New Revision: 222394
URL: http://llvm.org/viewvc/llvm-project?rev=222394&view=rev
Log:
clang-format: [Java] Accept generic types in enum declaration
Before:
enum Foo implements Bar<X, Y> {
ABC {
...
}
, CDE {
...
};
}
After:
enum Foo implements Bar<X, Y> {
ABC {
...
},
CDE {
...
};
}
Patch by Harry Terkelsen.
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=222394&r1=222393&r2=222394&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Nov 19 16:38:18 2014
@@ -1331,23 +1331,24 @@ void UnwrappedLineParser::parseAccessSpe
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;
Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=222394&r1=222393&r2=222394&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Wed Nov 19 16:38:18 2014
@@ -164,6 +164,20 @@ TEST_F(FormatTestJava, EnumDeclarations)
" public void f() {\n"
" }\n"
"}");
+ verifyFormat("private enum SomeEnum implements Foo<?, B> {\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) {
More information about the cfe-commits
mailing list