[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier

Daniel Jasper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 13 11:28:36 PST 2016


djasper added inline comments.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:297
     case tok::kw_default:
+      if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) {
+        if (!SwitchLabelEncountered &&
----------------
Same as below.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:865
   case tok::kw_default:
-    nextToken();
-    parseLabel();
-    return;
+    if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) {
+      nextToken();
----------------
Change the order here. I.e.

  if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration)
    break;
  ...

I think then you almost don't even need the comment.


================
Comment at: lib/Format/UnwrappedLineParser.cpp:870
+    }
+    // 'default' can appear in a Java 8 declaration. Parse it as such.
+    break;
----------------
Is there a test case that hits this codepath? IIUC, it would need to have a "default" of a declaration that's not at the start of the line.


https://reviews.llvm.org/D27377





More information about the cfe-commits mailing list