mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add static import: remove qualifier in case of inheritance (IDEA-155419)
This commit is contained in:
+4
-15
@@ -242,22 +242,11 @@ public class AddSingleMemberStaticImportAction extends BaseElementAtCaretIntenti
|
||||
aClass = PsiUtil.resolveClassInClassTypeOnly(((PsiVariable)aClass).getType());
|
||||
}
|
||||
if (aClass instanceof PsiClass && InheritanceUtil.isInheritorOrSelf((PsiClass)aClass, resolvedClass, true)) {
|
||||
boolean foundMemberByName = false;
|
||||
if (referent instanceof PsiMember) {
|
||||
final String memberName = ((PsiMember)referent).getName();
|
||||
final PsiClass containingClass = PsiTreeUtil.getParentOfType(reference, PsiClass.class);
|
||||
if (containingClass != null) {
|
||||
foundMemberByName |= containingClass.findFieldByName(memberName, true) != null;
|
||||
foundMemberByName |= containingClass.findMethodsByName(memberName, true).length > 0;
|
||||
}
|
||||
try {
|
||||
qualifierExpression.delete();
|
||||
}
|
||||
if (!foundMemberByName) {
|
||||
try {
|
||||
qualifierExpression.delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Add static import for 'test.StaticImport.v'" "true"
|
||||
package test;
|
||||
|
||||
import static test.StaticImport.v;
|
||||
|
||||
class StaticImport {
|
||||
static String v = "123";
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Child extends StaticImport {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(v);
|
||||
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Add static import for 'test.StaticImport.v'" "true"
|
||||
package test;
|
||||
|
||||
class StaticImport {
|
||||
static String v = "123";
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Child extends StaticImport {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(StaticImport.<caret>v);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user