]> granicus.if.org Git - clang/commitdiff
clang-format: [Java] Accept generic types in enum declaration
authorDaniel Jasper <djasper@google.com>
Wed, 19 Nov 2014 22:38:18 +0000 (22:38 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 19 Nov 2014 22:38:18 +0000 (22:38 +0000)
Before:
  enum Foo implements Bar<X, Y> {
    ABC {
      ...
    }
    , CDE {
      ...
    };
  }

After:
  enum Foo implements Bar<X, Y> {
    ABC {
      ...
    },
    CDE {
      ...
    };
  }

Patch by Harry Terkelsen.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@222394 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJava.cpp

index d94e6c414e4913e6e978cf34afc944d00af487e1..af1e94cfe844a2736dee99322f94874cadaa3d52 100644 (file)
@@ -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;
 
index c47cfa9214bc6851071a682721617600167788b2..5c9bf1a25f800ffd81bdbb1da4be9b5ef7f1ee29 100644 (file)
@@ -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) {