mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
disable on-demand static import for non-static members (IDEA-191774)
This commit is contained in:
+4
-1
@@ -29,6 +29,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ImportUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -93,6 +94,8 @@ public class AddOnDemandStaticImportAction extends BaseElementAtCaretIntentionAc
|
||||
.createReferenceFromText(refNameElement.getText(), refExpr);
|
||||
final PsiElement target = copy.resolve();
|
||||
if (target != null && PsiTreeUtil.getParentOfType(target, PsiClass.class) != psiClass) return null;
|
||||
PsiElement resolve = ((PsiJavaCodeReferenceElement)gParent).resolve();
|
||||
if (resolve instanceof PsiMember && !((PsiMember)resolve).hasModifierProperty(PsiModifier.STATIC)) return null;
|
||||
}
|
||||
|
||||
PsiFile file = refExpr.getContainingFile();
|
||||
@@ -120,7 +123,7 @@ public class AddOnDemandStaticImportAction extends BaseElementAtCaretIntentionAc
|
||||
return false;
|
||||
}
|
||||
final PsiClass containingClass = PsiUtil.getTopLevelClass(refExpr);
|
||||
if (aClass != containingClass) {
|
||||
if (aClass != containingClass || !ImportUtils.isInsideClassBody(element, aClass)) {
|
||||
PsiImportList importList = ((PsiJavaFile)file).getImportList();
|
||||
if (importList == null) {
|
||||
return false;
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Add on demand static import for 'test.Foo'" "true"
|
||||
package test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static test.Foo.*;
|
||||
|
||||
abstract class Foo implements List<Bar> {
|
||||
static class Bar {}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add on demand static import for 'test.Foo'" "true"
|
||||
package test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
abstract class Foo implements List<F<caret>oo.Bar> {
|
||||
static class Bar {}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add on demand static import for 'test.Foo.Bar'" "false"
|
||||
package test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
abstract class Foo implements List<F<caret>oo.Bar> {
|
||||
class Bar {}
|
||||
}
|
||||
Reference in New Issue
Block a user