mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
support Rename Reference on invalid method call (IDEA-176918)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Rename reference" "true"
|
||||
class c {
|
||||
void () {
|
||||
int i = i;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Rename reference" "true"
|
||||
class c {
|
||||
void foo(boolean b) {
|
||||
if (b) {
|
||||
int i = 0;
|
||||
i++;
|
||||
} else {
|
||||
k++;
|
||||
}
|
||||
}
|
||||
int k;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Rename reference" "true"
|
||||
class FooInterface {
|
||||
private int myInt;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
float myFloat;
|
||||
|
||||
void buzz() {
|
||||
myFloat + myFloat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// "Rename reference" "true"
|
||||
class Foo {
|
||||
|
||||
void buzz() {
|
||||
buzz();
|
||||
this.buzz(); //don't pay attention to same type qualifier
|
||||
a.buzz();
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,5 @@ class c {
|
||||
i<caret>++;
|
||||
}
|
||||
}
|
||||
int k;
|
||||
}
|
||||
@@ -4,6 +4,8 @@ class FooInterface {
|
||||
}
|
||||
|
||||
class Foo {
|
||||
float myFloat;
|
||||
|
||||
void buzz() {
|
||||
myI<caret>nt + myInt;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user