mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
optimize imports: resolve conflicts with inner classes on-demand imports (IDEA-59199; IDEA-78746)
This commit is contained in:
@@ -311,10 +311,15 @@ public class ImportHelper{
|
||||
Set<String> set = Arrays.stream(aPackage.getClasses(resolveScope)).map(PsiClass::getName).collect(toSet());
|
||||
classNames.put(onDemand, set);
|
||||
}
|
||||
else if (isStatic && (aClass = facade.findClass(onDemand, resolveScope)) != null) { // import static foo.package1.Class1.*;
|
||||
PsiMember[][] membersArray = {aClass.getInnerClasses(), aClass.getMethods(), aClass.getFields()};
|
||||
Set<String> set = Arrays.stream(membersArray).flatMap(Arrays::stream).map(PsiMember::getName).collect(toSet());
|
||||
classNames.put(onDemand, set);
|
||||
else if ((aClass = facade.findClass(onDemand, resolveScope)) != null) { // import static foo.package1.Class1.*;
|
||||
if (isStatic) {
|
||||
PsiMember[][] membersArray = {aClass.getInnerClasses(), aClass.getMethods(), aClass.getFields()};
|
||||
Set<String> set = Arrays.stream(membersArray).flatMap(Arrays::stream).map(PsiMember::getName).collect(toSet());
|
||||
classNames.put(onDemand, set);
|
||||
}
|
||||
else {
|
||||
classNames.put(onDemand, Arrays.stream(aClass.getInnerClasses()).map(PsiClass::getName).collect(toSet()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
onDemands.remove(i);
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package foo;
|
||||
|
||||
import foo.A.Person;
|
||||
import foo.A.OtherClass;
|
||||
import foo.A.OtherClass1;
|
||||
import foo.A.OtherClass2;
|
||||
import foo.A.OtherClass3;
|
||||
import foo.A.OtherClass4;
|
||||
|
||||
class Client {
|
||||
public void method(OtherClass otherClass) {
|
||||
OtherClass1 o1;
|
||||
OtherClass2 o2;
|
||||
OtherClass3 o3;
|
||||
OtherClass4 o4;
|
||||
Person person = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public interface Person {}
|
||||
public static class OtherClass {}
|
||||
public static class OtherClass1 {}
|
||||
public static class OtherClass2 {}
|
||||
public static class OtherClass3 {}
|
||||
public static class OtherClass4 {}
|
||||
public static class Override {}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package foo;
|
||||
|
||||
import foo.A.*;
|
||||
|
||||
import java.lang.Override;
|
||||
|
||||
class Client {
|
||||
public void method(OtherClass otherClass) {
|
||||
OtherClass1 o1;
|
||||
OtherClass2 o2;
|
||||
OtherClass3 o3;
|
||||
OtherClass4 o4;
|
||||
Person person = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public interface Person {}
|
||||
public static class OtherClass {}
|
||||
public static class OtherClass1 {}
|
||||
public static class OtherClass2 {}
|
||||
public static class OtherClass3 {}
|
||||
public static class OtherClass4 {}
|
||||
public static class Override {}
|
||||
}
|
||||
@@ -49,6 +49,10 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testConflictingWithJavaLang() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(".java");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user