Java: sort imports correctly when "Layout static imports separately" is disabled (IDEA-298584)

(cherry picked from commit 6656672e1ae56cffbc4f65cfbbd79d97004aef78)

GitOrigin-RevId: a1065f373f4f8fa92e8f36564f6091fd99408e65
This commit is contained in:
Bas Leijdekkers
2024-10-17 15:32:21 +02:00
committed by intellij-monorepo-bot
parent 982a5b4d9c
commit c82b457feb
2 changed files with 66 additions and 2 deletions

View File

@@ -175,7 +175,8 @@ public final class ImportHelper{
PackageEntry[] entries = settings.IMPORT_LAYOUT_TABLE.getEntries();
for (int i = 0; i < imports.size(); i++) {
Import anImport = imports.get(i);
entryForName[i] = findEntryIndex(ImportUtils.getPackageOrClassName(anImport.name()), anImport.isStatic(), entries);
entryForName[i] = findEntryIndex(ImportUtils.getPackageOrClassName(anImport.name()),
settings.LAYOUT_STATIC_IMPORTS_SEPARATELY && anImport.isStatic(), entries);
}
List<Import> resultList = new ArrayList<>(imports.size());
@@ -841,7 +842,9 @@ public final class ImportHelper{
String className = ref.getCanonicalText();
packageName = ImportUtils.getPackageOrClassName(className);
}
return findEntryIndex(packageName, statement instanceof PsiImportStaticStatement, mySettings.IMPORT_LAYOUT_TABLE.getEntries());
return findEntryIndex(packageName,
mySettings.LAYOUT_STATIC_IMPORTS_SEPARATELY && statement instanceof PsiImportStaticStatement,
mySettings.IMPORT_LAYOUT_TABLE.getEntries());
}
public static boolean hasConflictingOnDemandImport(@NotNull PsiJavaFile file, @NotNull PsiClass psiClass, @NotNull String referenceName) {