support Rename Reference on invalid method call (IDEA-176918)

This commit is contained in:
Anna.Kozlova
2017-08-08 17:40:06 +02:00
parent b846335cd0
commit 6d1f106889
11 changed files with 69 additions and 4 deletions

View File

@@ -23,6 +23,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.quickfix.*;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider;
import com.intellij.codeInspection.LocalQuickFixOnPsiElementAsIntentionAdapter;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.IndexNotReadyException;
@@ -717,6 +718,9 @@ public class HighlightMethodUtil {
PermuteArgumentsFix.registerFix(info, methodCall, candidates, fixRange);
WrapExpressionFix.registerWrapAction(candidates, list.getExpressions(), info);
registerChangeParameterClassFix(methodCall, list, info);
if (candidates.length == 0) {
UnresolvedReferenceQuickFixProvider.registerReferenceFixes(methodCall.getMethodExpression(), new QuickFixActionRegistrarImpl(info));
}
return info;
}

View File

@@ -497,7 +497,7 @@ public class CreateFromUsageUtils {
JavaRecursiveElementWalkingVisitor visitor = new JavaRecursiveElementWalkingVisitor() {
@Override public void visitReferenceExpression(PsiReferenceExpression expr) {
if (expression instanceof PsiReferenceExpression) {
if (expr.textMatches(expression) && !isValidReference(expr, false)) {
if (Comparing.equal(expr.getReferenceName(), ((PsiReferenceExpression)expression).getReferenceName()) && !isValidReference(expr, false)) {
result.add(expr);
}
}
@@ -507,7 +507,7 @@ public class CreateFromUsageUtils {
@Override public void visitMethodCallExpression(PsiMethodCallExpression expr) {
if (expression instanceof PsiMethodCallExpression) {
PsiReferenceExpression methodExpression = expr.getMethodExpression();
if (methodExpression.textMatches(((PsiMethodCallExpression) expression).getMethodExpression())) {
if (Comparing.equal(methodExpression.getReferenceName(), ((PsiMethodCallExpression) expression).getMethodExpression().getReferenceName())) {
result.add(expr.getMethodExpression());
}
}

View File

@@ -23,6 +23,7 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateBuilderImpl;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
@@ -125,7 +126,7 @@ public class RenameWrongRefFix implements IntentionAction {
}
}
items.add(LookupElementBuilder.create(myRefExpr.getReferenceName()));
if (!ApplicationManager.getApplication().isUnitTestMode()) items.add(LookupElementBuilder.create(myRefExpr.getReferenceName()));
MyScopeProcessor processor = new MyScopeProcessor(myRefExpr);
myRefExpr.processVariants(processor);
PsiElement[] variants = processor.getVariants();

View File

@@ -0,0 +1,6 @@
// "Rename reference" "true"
class c {
void () {
int i = i;
}
}

View File

@@ -0,0 +1,12 @@
// "Rename reference" "true"
class c {
void foo(boolean b) {
if (b) {
int i = 0;
i++;
} else {
k++;
}
}
int k;
}

View File

@@ -0,0 +1,12 @@
// "Rename reference" "true"
class FooInterface {
private int myInt;
}
class Foo {
float myFloat;
void buzz() {
myFloat + myFloat;
}
}

View File

@@ -0,0 +1,9 @@
// "Rename reference" "true"
class Foo {
void buzz() {
buzz();
this.buzz(); //don't pay attention to same type qualifier
a.buzz();
}
}

View File

@@ -8,4 +8,5 @@ class c {
i<caret>++;
}
}
int k;
}

View File

@@ -4,6 +4,8 @@ class FooInterface {
}
class Foo {
float myFloat;
void buzz() {
myI<caret>nt + myInt;
}

View File

@@ -0,0 +1,9 @@
// "Rename reference" "true"
class Foo {
void buzz() {
b<caret>ar();
this.bar(); //don't pay attention to same type qualifier
a.bar();
}
}

View File

@@ -15,7 +15,16 @@
*/
package com.intellij.java.codeInsight.daemon.quickFix;
public class RenameWrongReferenceTest extends LightQuickFixAvailabilityTestCase {
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
public class RenameWrongReferenceTest extends LightQuickFixParameterizedTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable());
}
public void test() throws Exception { doAllTests(); }