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

GitOrigin-RevId: ce6ec1c65d5777e5e3059093fdd01baf24f95e50
This commit is contained in:
Mikhail Pyltsin
2025-03-01 01:05:41 +01:00
committed by intellij-monorepo-bot
parent 203b4d4a70
commit abca56d632
8 changed files with 225 additions and 4 deletions

View File

@@ -380,6 +380,10 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
private void initImportsByDefault() {
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false, "java.awt", false));
PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false,"javax.swing", false));
initImportLayout();
}
private void initImportLayout() {
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_MODULE_IMPORTS);
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
@@ -458,8 +462,31 @@ public class JavaCodeStyleSettings extends CustomCodeStyleSettings implements Im
myOldVersion = myVersion = CustomCodeStyleSettingsUtils.readVersion(parentElement.getChild(getTagName()));
myIsInitialized = true;
PackageEntry[] entries = IMPORT_LAYOUT_TABLE.getEntries();
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_MODULE_IMPORTS)) {
IMPORT_LAYOUT_TABLE.setEntryAt(PackageEntry.ALL_MODULE_IMPORTS, 0);
//if it is broken, try to restore
if (entries.length == 0) {
initImportLayout();
}
else {
//if something is missed, restore it
if (!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);
}
else {
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY, 0);
}
}
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY)) {
if (entries[0] == PackageEntry.ALL_MODULE_IMPORTS) {
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, 1);
}
else {
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_OTHER_IMPORTS_ENTRY, 0);
}
}
if (!ContainerUtil.exists(entries, entry -> entry == PackageEntry.ALL_MODULE_IMPORTS)) {
IMPORT_LAYOUT_TABLE.insertEntryAt(PackageEntry.ALL_MODULE_IMPORTS, 0);
}
}
}