mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
add single member static import: do not remove qualifier when members with the same name exist in the hierarchy
This commit is contained in:
@@ -119,8 +119,8 @@ public class AddSingleMemberStaticImportAction extends PsiElementBaseIntentionAc
|
||||
|
||||
if (refExpr.getReferenceName().equals(expression.getReferenceName())) {
|
||||
final PsiExpression qualifierExpression = expression.getQualifierExpression();
|
||||
PsiElement referent = expression.getUserData(TEMP_REFERENT_USER_DATA);
|
||||
if (!expression.isQualified()) {
|
||||
PsiElement referent = expression.getUserData(TEMP_REFERENT_USER_DATA);
|
||||
|
||||
if (referent instanceof PsiMember && referent != expression.resolve()) {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(expression.getProject()).getElementFactory();
|
||||
@@ -138,11 +138,22 @@ public class AddSingleMemberStaticImportAction extends PsiElementBaseIntentionAc
|
||||
if (qualifierExpression instanceof PsiReferenceExpression) {
|
||||
PsiElement aClass = ((PsiReferenceExpression)qualifierExpression).resolve();
|
||||
if (aClass == ((PsiMember)resolved).getContainingClass()) {
|
||||
try {
|
||||
qualifierExpression.delete();
|
||||
boolean foundMemberByName = false;
|
||||
if (referent instanceof PsiMember) {
|
||||
final String memberName = ((PsiMember)referent).getName();
|
||||
final PsiClass containingClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
|
||||
if (containingClass != null) {
|
||||
foundMemberByName |= containingClass.findFieldByName(memberName, true) != null;
|
||||
foundMemberByName |= containingClass.findMethodsByName(memberName, true).length > 0;
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
if (!foundMemberByName) {
|
||||
try {
|
||||
qualifierExpression.delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Add static import for 'test.Bar.f'" "true"
|
||||
package test;
|
||||
|
||||
import static test.Bar.f;
|
||||
|
||||
class Bar {
|
||||
public static final void f() {}
|
||||
}
|
||||
public class Foo {
|
||||
public static final void f(int i) {}
|
||||
{
|
||||
Bar.<caret>f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Add static import for 'test.Bar.f'" "true"
|
||||
package test;
|
||||
|
||||
import static test.Bar.f;
|
||||
|
||||
class Bar {
|
||||
public static final void f() {}
|
||||
}
|
||||
public class Foo extends FooSuper{
|
||||
{
|
||||
Bar.<caret>f();
|
||||
}
|
||||
}
|
||||
|
||||
class FooSuper {
|
||||
public static final void f(int i) {}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Add static import for 'test.Bar.f'" "true"
|
||||
package test;
|
||||
|
||||
class Bar {
|
||||
public static final void f() {}
|
||||
}
|
||||
public class Foo {
|
||||
public static final void f(int i) {}
|
||||
{
|
||||
Bar.<caret>f();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Add static import for 'test.Bar.f'" "true"
|
||||
package test;
|
||||
|
||||
class Bar {
|
||||
public static final void f() {}
|
||||
}
|
||||
public class Foo extends FooSuper{
|
||||
{
|
||||
Bar.<caret>f();
|
||||
}
|
||||
}
|
||||
|
||||
class FooSuper {
|
||||
public static final void f(int i) {}
|
||||
}
|
||||
Reference in New Issue
Block a user