Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -294,6 +294,11 @@ addUnwrappedLine(); break; case tok::kw_default: + if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration) { + parseStructuralElement(); + break; + } + // fallthrough case tok::kw_case: if (!SwitchLabelEncountered && (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1))) @@ -853,6 +858,8 @@ parseSwitch(); return; case tok::kw_default: + if (Style.Language == FormatStyle::LK_Java && Line->MustBeDeclaration) + break; nextToken(); parseLabel(); return; Index: unittests/Format/FormatTestJava.cpp =================================================================== --- unittests/Format/FormatTestJava.cpp +++ unittests/Format/FormatTestJava.cpp @@ -515,5 +515,22 @@ " void f() {}")); } +TEST_F(FormatTestJava, UnderstandsDefaultModifier) { + verifyFormat("class SomeClass {\n" + " default void f() {}\n" + " public default void g() {}\n" + " default public void h() {}\n" + " int i() {\n" + " switch (0) {\n" + " case 0:\n" + " break;\n" + " default:\n" + " break;\n" + " }\n" + " }\n" + "}", + getGoogleStyle(FormatStyle::LK_Java)); +} + } // end namespace tooling } // end namespace clang