From 9b9e07608d2bec926e72c812b8c4c0283ccf143b Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 26 Nov 2014 18:03:42 +0000 Subject: [PATCH] clang-format: [Java] Don't line-wrap package declarations. This fixes llvm.org/PR21677. llvm-svn: 222843 --- clang/lib/Format/FormatToken.h | 2 ++ clang/lib/Format/TokenAnnotator.cpp | 6 ++++-- clang/unittests/Format/FormatTestJava.cpp | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 732096b..11c4925 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -547,6 +547,7 @@ struct AdditionalKeywords { kw_implements = &IdentTable.get("implements"); kw_instanceof = &IdentTable.get("instanceof"); kw_interface = &IdentTable.get("interface"); + kw_package = &IdentTable.get("package"); kw_synchronized = &IdentTable.get("synchronized"); kw_throws = &IdentTable.get("throws"); @@ -573,6 +574,7 @@ struct AdditionalKeywords { IdentifierInfo *kw_implements; IdentifierInfo *kw_instanceof; IdentifierInfo *kw_interface; + IdentifierInfo *kw_package; IdentifierInfo *kw_synchronized; IdentifierInfo *kw_throws; diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ccaac1b..93ac447 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -612,8 +612,10 @@ public: // definitions (code.google.com/p/protobuf) or missing "#" (either way we // should not break the line). IdentifierInfo *Info = CurrentToken->Tok.getIdentifierInfo(); - if (Info && Info->getPPKeywordID() == tok::pp_import && - CurrentToken->Next) { + if ((Style.Language == FormatStyle::LK_Java && + CurrentToken->is(Keywords.kw_package)) || + (Info && Info->getPPKeywordID() == tok::pp_import && + CurrentToken->Next)) { next(); parseIncludeDirective(); return LT_ImportStatement; diff --git a/clang/unittests/Format/FormatTestJava.cpp b/clang/unittests/Format/FormatTestJava.cpp index 10149f5..829ced7 100644 --- a/clang/unittests/Format/FormatTestJava.cpp +++ b/clang/unittests/Format/FormatTestJava.cpp @@ -319,6 +319,11 @@ TEST_F(FormatTestJava, SynchronizedKeyword) { "}"); } +TEST_F(FormatTestJava, PackageDeclarations) { + verifyFormat("package some.really.loooooooooooooooooooooong.package;", + getStyleWithColumns(50)); +} + TEST_F(FormatTestJava, ImportDeclarations) { verifyFormat("import some.really.loooooooooooooooooooooong.imported.Class;", getStyleWithColumns(50)); -- 2.7.4