forked from OSchip/llvm-project
[clang-format] [PR41187] moves Java import statements to the wrong location if code contains statements that start with the word import
Summary: Import sorting of java file, incorrectly move import statement to after a function beginning with the word import. Make 1 character change to regular expression to ensure there is always at least one space/tab after the word import Previously clang-format --style="LLVM" would format ``` import X; class C { void m() { importFile(); } } ``` as ``` class C { void m() { importFile(); import X; } } ``` Reviewers: djasper, klimek, reuk, JonasToth Reviewed By: klimek Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59684 llvm-svn: 357345
This commit is contained in:
parent
08a940d629
commit
88335c21a4
|
@ -1983,7 +1983,7 @@ static void sortJavaImports(const FormatStyle &Style,
|
|||
namespace {
|
||||
|
||||
const char JavaImportRegexPattern[] =
|
||||
"^[\t ]*import[\t ]*(static[\t ]*)?([^\t ]*)[\t ]*;";
|
||||
"^[\t ]*import[\t ]+(static[\t ]*)?([^\t ]*)[\t ]*;";
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
|
|
@ -262,6 +262,21 @@ TEST_F(SortImportsTestJava, NoNewlineAtEnd) {
|
|||
"import org.a;"));
|
||||
}
|
||||
|
||||
TEST_F(SortImportsTestJava, ImportNamedFunction) {
|
||||
EXPECT_EQ("import X;\n"
|
||||
"class C {\n"
|
||||
" void m() {\n"
|
||||
" importFile();\n"
|
||||
" }\n"
|
||||
"}\n",
|
||||
sort("import X;\n"
|
||||
"class C {\n"
|
||||
" void m() {\n"
|
||||
" importFile();\n"
|
||||
" }\n"
|
||||
"}\n"));
|
||||
}
|
||||
|
||||
TEST_F(SortImportsTestJava, NoReplacementsForValidImports) {
|
||||
// Identical #includes have led to a failure with an unstable sort.
|
||||
std::string Code = "import org.a;\n"
|
||||
|
|
Loading…
Reference in New Issue