mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
optimize imports: check accessibility before expanding on-demand to single-static-import (IDEA-157833)
This commit is contained in:
@@ -247,6 +247,8 @@ public class ImportHelper{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
PsiResolveHelper resolveHelper = facade.getResolveHelper();
|
||||
|
||||
for (int i = 0; i < onDemandImportsList.size(); i++) {
|
||||
String onDemandName = onDemandImportsList.get(i);
|
||||
if (prefix.equals(onDemandName)) continue;
|
||||
@@ -254,18 +256,18 @@ public class ImportHelper{
|
||||
PsiClass aClass = onDemandElements.get(i);
|
||||
if (aClass != null) {
|
||||
PsiField field = aClass.findFieldByName(shortName, true);
|
||||
if (field != null && field.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (field != null && field.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(field, file, null)) {
|
||||
namesToUseSingle.add(name);
|
||||
}
|
||||
else {
|
||||
PsiClass inner = aClass.findInnerClassByName(shortName, true);
|
||||
if (inner != null && inner.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (inner != null && inner.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(inner, file, null)) {
|
||||
namesToUseSingle.add(name);
|
||||
}
|
||||
else {
|
||||
PsiMethod[] methods = aClass.findMethodsByName(shortName, true);
|
||||
for (PsiMethod method : methods) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC) && resolveHelper.isAccessible(method, file, null)) {
|
||||
namesToUseSingle.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
|
||||
import static test.a.A.*;
|
||||
import static test.b.B.*;
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(A_CONST);
|
||||
System.out.println(B_CONST);
|
||||
System.out.println(SHARED_CONST);
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public static final int A_CONST = 1;
|
||||
public static final int SHARED_CONST = 2;
|
||||
}
|
||||
|
||||
class B {
|
||||
public static final int B_CONST = 1;
|
||||
private static final int SHARED_CONST = 2;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package test;
|
||||
|
||||
import static test.a.A.*;
|
||||
import static test.b.B.*;
|
||||
|
||||
class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(A_CONST);
|
||||
System.out.println(B_CONST);
|
||||
System.out.println(SHARED_CONST);
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public static final int A_CONST = 1;
|
||||
public static final int SHARED_CONST = 2;
|
||||
}
|
||||
|
||||
class B {
|
||||
public static final int B_CONST = 1;
|
||||
private static final int SHARED_CONST = 2;
|
||||
}
|
||||
@@ -39,6 +39,7 @@ public class OptimizeImportsTest extends OptimizeImportsTestCase {
|
||||
public void testNewImportListIsEmptyAndJavaDocWithInvalidCodePreserved() throws Exception { doTest(); }
|
||||
|
||||
public void testDontCollapseToOnDemandImport() throws Exception { doTest(); }
|
||||
public void testIgnoreInaccessible() throws Exception{ doTest();}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(".java");
|
||||
|
||||
Reference in New Issue
Block a user