From fc3744144539aa6a43ec9c80bd5c3503a3702f3c Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Sat, 1 Mar 2025 16:39:10 +0100 Subject: [PATCH] [java-imports] IDEA-368382 incorrect place for module import - support static separately (cherry picked from commit 8d1acc0e8d2bd7d60b1f03b1ebe367d7d9f2e2a9) IJ-CR-156496 GitOrigin-RevId: b85061e1772f4b7b6603edb980e34d90f6693e42 --- .../psi/codeStyle/JavaCodeStyleSettings.java | 2 +- ...cImportWithoutModuleAndStaticNotSeparate.xml | 17 +++++++++++++++++ .../codeStyle/JavaCodeStyleSettingsTest.java | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeStyle/withoutStaticImportWithoutModuleAndStaticNotSeparate.xml diff --git a/java/java-frontback-impl/src/com/intellij/psi/codeStyle/JavaCodeStyleSettings.java b/java/java-frontback-impl/src/com/intellij/psi/codeStyle/JavaCodeStyleSettings.java index 0d9b01419949..19a731f9e2b9 100644 --- a/java/java-frontback-impl/src/com/intellij/psi/codeStyle/JavaCodeStyleSettings.java +++ b/java/java-frontback-impl/src/com/intellij/psi/codeStyle/JavaCodeStyleSettings.java @@ -468,7 +468,7 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im } else { //if something is missed, restore it - if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY)) { + if (LAYOUT_STATIC_IMPORTS_SEPARATELY && !ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY)) { if (entries[0] == PackageEntry.ALL_MODULE_IMPORTS) { IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, 1); } diff --git a/java/java-tests/testData/codeStyle/withoutStaticImportWithoutModuleAndStaticNotSeparate.xml b/java/java-tests/testData/codeStyle/withoutStaticImportWithoutModuleAndStaticNotSeparate.xml new file mode 100644 index 000000000000..5114ac50f981 --- /dev/null +++ b/java/java-tests/testData/codeStyle/withoutStaticImportWithoutModuleAndStaticNotSeparate.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/psi/codeStyle/JavaCodeStyleSettingsTest.java b/java/java-tests/testSrc/com/intellij/java/psi/codeStyle/JavaCodeStyleSettingsTest.java index 5ddd141e4601..21d0d277c04f 100644 --- a/java/java-tests/testSrc/com/intellij/java/psi/codeStyle/JavaCodeStyleSettingsTest.java +++ b/java/java-tests/testSrc/com/intellij/java/psi/codeStyle/JavaCodeStyleSettingsTest.java @@ -254,6 +254,23 @@ public class JavaCodeStyleSettingsTest extends CodeStyleTestCase { assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(7)); } + public void testWithoutStaticImportWithoutModuleAndStaticNotSeparate() throws SchemeImportException { + CodeStyleSettings settings = importSettings(); + + JavaCodeStyleSettings customSettings = settings.getCustomSettings(JavaCodeStyleSettings.class); + + PackageEntryTable table = customSettings.IMPORT_LAYOUT_TABLE; + assertSize(7, table.getEntries()); + + assertEquals(PackageEntry.ALL_MODULE_IMPORTS, table.getEntryAt(0)); + assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(1)); + assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(2)); + assertEquals("javax", table.getEntryAt(3).getPackageName()); + assertEquals("java", table.getEntryAt(4).getPackageName()); + assertEquals(PackageEntry.BLANK_LINE_ENTRY, table.getEntryAt(5)); + assertEquals(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, table.getEntryAt(6)); + } + public void testEmptyConfigImport() throws SchemeImportException { CodeStyleSettings settings = importSettings();