From 5e7be1d53683b4067e5cf5831e8fedba12785acf Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 2 Nov 2014 22:13:03 +0000 Subject: [PATCH] clang-format: [Java] Don't break imports. This fixes llvm.org/PR21453. llvm-svn: 221112 --- clang/lib/Format/TokenAnnotator.cpp | 6 +++--- clang/unittests/Format/FormatTestJava.cpp | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1056d43..5eb6e10 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -541,8 +541,8 @@ private: } } else { while (CurrentToken) { - if (CurrentToken->is(tok::string_literal)) - // Mark these string literals as "implicit" literals, too, so that + if (CurrentToken->isNot(tok::comment)) + // Mark these tokens as "implicit" string literals, so that // they are not split or line-wrapped. CurrentToken->Type = TT_ImplicitStringLiteral; next(); @@ -622,7 +622,7 @@ public: // should not break the line). IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo(); if (Info && Info->getPPKeywordID() == tok::pp_import && - CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) { + CurrentToken->Next) { next(); parseIncludeDirective(); return LT_Other; diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 2b05ca4..126b163 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -163,5 +163,10 @@ TEST_F(FormatTestJava, SynchronizedKeyword) { "}"); } +TEST_F(FormatTestJava, ImportDeclarations) { + verifyFormat("import some.really.loooooooooooooooooooooong.imported.Class;", + getStyleWithColumns(50)); +} + } // end namespace tooling } // end namespace clang -- 2.7.4