mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
inline method: do not insert unnecessary qualification (IDEA-70786 )
This commit is contained in:
@@ -22,10 +22,13 @@ import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.util.FieldConflictsResolver;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ChangeContextUtil {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.ChangeContextUtil");
|
||||
|
||||
@@ -212,7 +215,8 @@ public class ChangeContextUtil {
|
||||
InheritanceUtil.isInheritorOrSelf(thisClass, realParentClass, true)) {
|
||||
boolean needQualifier = true;
|
||||
PsiElement refElement = refExpr.resolve();
|
||||
if (refMember.equals(refElement)){
|
||||
if (refMember.equals(refElement) ||
|
||||
(refElement instanceof PsiMethod && refMember instanceof PsiMethod && ArrayUtil.find(((PsiMethod)refElement).findSuperMethods(), refMember) > -1)){
|
||||
if (thisAccessExpr instanceof PsiThisExpression && ((PsiThisExpression)thisAccessExpr).getQualifier() == null) {
|
||||
//Trivial qualifier
|
||||
needQualifier = false;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
class A {
|
||||
public void f() {
|
||||
g();
|
||||
}
|
||||
|
||||
public void g() {
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public void g() {
|
||||
|
||||
}
|
||||
public void h() {
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
f<caret>();
|
||||
}
|
||||
}.run();
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
class A {
|
||||
|
||||
public void g() {
|
||||
}
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
public void g() {
|
||||
|
||||
}
|
||||
public void h() {
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
g();
|
||||
}
|
||||
}.run();
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,10 @@ public class InlineMethodTest extends LightCodeInsightTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSuperMethodInAnonymousClass() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
String name = getTestName(false);
|
||||
@NonNls String fileName = "/refactoring/inlineMethod/" + name + ".java";
|
||||
|
||||
Reference in New Issue
Block a user