[PATCH] D27377: clang-format: Support the Java 8 'default' method modifier
Luis Héctor Chávez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 13 12:29:52 PST 2016
lhchavez updated this revision to Diff 81280.
lhchavez added a comment.
Addressed feedback
https://reviews.llvm.org/D27377
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJava.cpp
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
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27377.81280.patch
Type: text/x-patch
Size: 1682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161213/5a9e52a7/attachment.bin>
More information about the cfe-commits
mailing list