diff options
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJava.cpp | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index ba492aae029..21f0e7bad1b 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -757,6 +757,13 @@ void UnwrappedLineParser::parseStructuralElement() { // A record declaration or definition is always the start of a structural // element. break; + case tok::period: + nextToken(); + // In Java, classes have an implicit static member "class". + if (Style.Language == FormatStyle::LK_Java && FormatTok && + FormatTok->is(tok::kw_class)) + nextToken(); + break; case tok::semi: nextToken(); addUnwrappedLine(); diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 5a45b80f3bf..47e219b4a1b 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -65,6 +65,11 @@ TEST_F(FormatTestJava, FormatsInstanceOfLikeOperators) { Style); } +TEST_F(FormatTestJava, ClassKeyword) { + verifyFormat("SomeClass.class.getName();"); + verifyFormat("Class c = SomeClass.class;"); +} + TEST_F(FormatTestJava, ClassDeclarations) { verifyFormat("public class SomeClass {\n" " private int a;\n" |