Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -294,6 +294,15 @@ addUnwrappedLine(); break; case tok::kw_default: + if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) { + if (!SwitchLabelEncountered && + (Style.IndentCaseLabels || + (Line->InPPDirective && Line->Level == 1))) + ++Line->Level; + SwitchLabelEncountered = true; + } + parseStructuralElement(); + break; case tok::kw_case: if (!SwitchLabelEncountered && (Style.IndentCaseLabels || (Line->InPPDirective && Line->Level == 1))) @@ -853,9 +862,13 @@ parseSwitch(); return; case tok::kw_default: - nextToken(); - parseLabel(); - return; + if (Style.Language != FormatStyle::LK_Java || !Line->MustBeDeclaration) { + nextToken(); + parseLabel(); + return; + } + // 'default' can appear in a Java 8 declaration. Parse it as such. + break; case tok::kw_case: parseCaseLabel(); return; Index: unittests/Format/FormatTestJava.cpp =================================================================== --- unittests/Format/FormatTestJava.cpp +++ unittests/Format/FormatTestJava.cpp @@ -515,5 +515,20 @@ " void f() {}")); } +TEST_F(FormatTestJava, UnderstandsDefaultModifier) { + verifyFormat("class SomeClass {\n" + " default void f() {}\n" + " int g() {\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