[java-imports] IDEA-368382 incorrect place for module import

- support static separately


(cherry picked from commit 8d1acc0e8d2bd7d60b1f03b1ebe367d7d9f2e2a9)

IJ-CR-156496

GitOrigin-RevId: d109ac92ad1c67ef65b4267cc752475b98fa267e
This commit is contained in:
Mikhail Pyltsin
2025-03-01 16:39:10 +01:00
committed by intellij-monorepo-bot
parent f99f182609
commit f82340ac1c
3 changed files with 35 additions and 1 deletions

View File

@@ -464,7 +464,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);
}

View File

@@ -0,0 +1,17 @@
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="LAYOUT_STATIC_IMPORTS_SEPARATELY" value="false" />
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="false" module="true" />
<emptyLine />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value> </option>
</JavaCodeStyleSettings>
</code_scheme>

View File

@@ -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();