mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
optimize imports: do not skip static imports in favor for simple imports (IDEA-95276)
This commit is contained in:
@@ -310,7 +310,7 @@ public class ImportHelper{
|
||||
private static StringBuilder buildImportListText(@NotNull List<Pair<String, Boolean>> names,
|
||||
@NotNull final Set<String> packagesOrClassesToImportOnDemand,
|
||||
@NotNull final Set<String> namesToUseSingle) {
|
||||
final Set<String> importedPackagesOrClasses = new THashSet<String>();
|
||||
final Set<Pair<String, Boolean>> importedPackagesOrClasses = new THashSet<Pair<String, Boolean>>();
|
||||
@NonNls final StringBuilder buffer = new StringBuilder();
|
||||
for (Pair<String, Boolean> pair : names) {
|
||||
String name = pair.getFirst();
|
||||
@@ -321,11 +321,12 @@ public class ImportHelper{
|
||||
if (useOnDemand && namesToUseSingle.remove(name)) {
|
||||
useOnDemand = false;
|
||||
}
|
||||
if (useOnDemand && (importedPackagesOrClasses.contains(packageOrClassName) || implicitlyImported)) continue;
|
||||
final Pair<String, Boolean> current = Pair.create(packageOrClassName, isStatic);
|
||||
if (useOnDemand && (importedPackagesOrClasses.contains(current) || implicitlyImported)) continue;
|
||||
buffer.append("import ");
|
||||
if (isStatic) buffer.append("static ");
|
||||
if (useOnDemand) {
|
||||
importedPackagesOrClasses.add(packageOrClassName);
|
||||
importedPackagesOrClasses.add(current);
|
||||
buffer.append(packageOrClassName);
|
||||
buffer.append(".*");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package example;
|
||||
|
||||
import static java.lang.Math.cos;
|
||||
import static java.lang.Math.sin;
|
||||
import example.ImportedClass.I1;
|
||||
import example.ImportedClass.I1A;
|
||||
import static example.ImportedClass.BAZZ.E1;
|
||||
import static example.ImportedClass.V;
|
||||
import static example.ImportedClass.FOO;
|
||||
import example.ImportedClass.BAR;
|
||||
|
||||
public class MyTest {
|
||||
protected MyTest() {
|
||||
super();
|
||||
String az = BAR.AZ + V;
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class ImportedClass {
|
||||
public static String V = "";
|
||||
|
||||
public static enum I1 {
|
||||
E1;
|
||||
}
|
||||
public static enum I1A {
|
||||
E1;
|
||||
}
|
||||
|
||||
public static enum BAR {
|
||||
E1, AZ;
|
||||
}
|
||||
|
||||
public static String FOO = "";
|
||||
|
||||
public static enum BAZZ {
|
||||
E1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package example;
|
||||
|
||||
import example.ImportedClass.BAR;
|
||||
|
||||
import static example.ImportedClass.FOO;
|
||||
import static example.ImportedClass.V;
|
||||
|
||||
public class MyTest {
|
||||
protected MyTest() {
|
||||
super();
|
||||
String az = BAR.AZ + V;
|
||||
System.out.println(FOO);
|
||||
}
|
||||
}
|
||||
|
||||
class ImportedClass {
|
||||
public static String V = "";
|
||||
|
||||
public static enum I1 {
|
||||
E1;
|
||||
}
|
||||
public static enum I1A {
|
||||
E1;
|
||||
}
|
||||
|
||||
public static enum BAR {
|
||||
E1, AZ;
|
||||
}
|
||||
|
||||
public static String FOO = "";
|
||||
|
||||
public static enum BAZZ {
|
||||
E1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class OptimizeImportsTest extends PsiTestCase{
|
||||
public void testSCR18364() throws Exception { doTest(); }
|
||||
public void testStaticImports1() throws Exception { doTest(); }
|
||||
public void testStaticImportsToOptimize() throws Exception { doTest(); }
|
||||
public void testStaticImportsToOptimizeMixed() throws Exception { doTest(); }
|
||||
public void testStaticImportsToOptimize2() throws Exception { doTest(); }
|
||||
public void testEmptyImportList() throws Exception { doTest(); }
|
||||
public void testIDEADEV10716() throws Exception { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user