mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Java: don't break compilation on optimize imports when package has "import" in its name (IDEA-336461)
(cherry picked from commit a691c03b8814e7cffec4dd32d4dfc7f3b0e10814) GitOrigin-RevId: 5747d57365f3b54861ba9a1a34209c42ac28669f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
44840c3a42
commit
f4cdf03f94
@@ -390,7 +390,7 @@ public final class ImportHelper{
|
||||
Import current = new Import(packageOrClassName, isStatic);
|
||||
if (namesToUseSingle.remove(name)) {
|
||||
if (useOnDemand && importedPackagesOrClasses.contains(current)) {
|
||||
buffer.insert(buffer.lastIndexOf("import"), "import " + (isStatic ? "static " : "") + name + ";\n");
|
||||
buffer.insert(buffer.lastIndexOf("import "), "import " + (isStatic ? "static " : "") + name + ";\n");
|
||||
continue;
|
||||
}
|
||||
useOnDemand = false;
|
||||
|
||||
@@ -243,6 +243,49 @@ public class LightOptimizeImportsTest extends LightJavaCodeInsightFixtureTestCas
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void testConflictInPackageWithImportInName() {
|
||||
myFixture.addClass("package a.importb; public class A {}");
|
||||
myFixture.addClass("package a.importb; public class B {}");
|
||||
myFixture.addClass("package a.importb; public class Boolean {}"); // conflict with java.lang.Process
|
||||
|
||||
@Language("JAVA")
|
||||
String text = """
|
||||
package a;
|
||||
|
||||
import a.importb.A;
|
||||
import a.importb.B;
|
||||
import a.importb.Boolean;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
A a;
|
||||
B b;
|
||||
Boolean boo;
|
||||
}
|
||||
}""";
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, text);
|
||||
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 1;
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
@Language("JAVA")
|
||||
String result = """
|
||||
package a;
|
||||
|
||||
import a.importb.Boolean;
|
||||
import a.importb.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
A a;
|
||||
B b;
|
||||
Boolean boo;
|
||||
}
|
||||
}""";
|
||||
myFixture.checkResult(result);
|
||||
}
|
||||
|
||||
public void testStaticImportOnMethodFromSuperClass() {
|
||||
myFixture.addClass("""
|
||||
package p; public class A {
|
||||
|
||||
Reference in New Issue
Block a user