mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
disable rename as wrong ref on invalid access refs; though enable quick fix there
This commit is contained in:
@@ -464,7 +464,7 @@ public class CreateFromUsageUtils {
|
||||
|
||||
@Override public void visitReferenceExpression(PsiReferenceExpression expr) {
|
||||
if (expression instanceof PsiReferenceExpression) {
|
||||
if (expr.textMatches(expression) && expr.resolve() == null) {
|
||||
if (expr.textMatches(expression) && !isValidReference(expr, false)) {
|
||||
result.add(expr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.*;
|
||||
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;
|
||||
@@ -48,9 +47,15 @@ public class RenameWrongRefFix implements IntentionAction {
|
||||
private final PsiReferenceExpression myRefExpr;
|
||||
@NonNls private static final String INPUT_VARIABLE_NAME = "INPUTVAR";
|
||||
@NonNls private static final String OTHER_VARIABLE_NAME = "OTHERVAR";
|
||||
private final boolean myUnresolvedOnly;
|
||||
|
||||
public RenameWrongRefFix(PsiReferenceExpression refExpr) {
|
||||
this(refExpr, false);
|
||||
}
|
||||
|
||||
public RenameWrongRefFix(PsiReferenceExpression refExpr, final boolean unresolvedOnly) {
|
||||
myRefExpr = refExpr;
|
||||
myUnresolvedOnly = unresolvedOnly;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -74,7 +79,7 @@ public class RenameWrongRefFix implements IntentionAction {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !CreateFromUsageUtils.isValidReference(myRefExpr, false) && CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class).length > 0;
|
||||
return !CreateFromUsageUtils.isValidReference(myRefExpr, myUnresolvedOnly);
|
||||
}
|
||||
|
||||
private class ReferenceNameExpression extends Expression {
|
||||
|
||||
@@ -17,22 +17,15 @@
|
||||
package com.intellij.refactoring.rename;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.RenameWrongRefFix;
|
||||
import com.intellij.lang.LanguageRefactoringSupport;
|
||||
import com.intellij.lang.refactoring.RefactoringSupportProvider;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ScrollType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenamer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RenameWrongRefHandler implements RenameHandler {
|
||||
|
||||
@@ -42,8 +35,12 @@ public class RenameWrongRefHandler implements RenameHandler {
|
||||
final PsiFile file = LangDataKeys.PSI_FILE.getData(dataContext);
|
||||
final Project project = PlatformDataKeys.PROJECT.getData(dataContext);
|
||||
if (editor == null || file == null || project == null) return false;
|
||||
return isAvailable(project, editor, file);
|
||||
}
|
||||
|
||||
public static boolean isAvailable(Project project, Editor editor, PsiFile file) {
|
||||
final PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
|
||||
return reference instanceof PsiReferenceExpression && new RenameWrongRefFix((PsiReferenceExpression)reference).isAvailable(project, editor, file);
|
||||
return reference instanceof PsiReferenceExpression && new RenameWrongRefFix((PsiReferenceExpression)reference, true).isAvailable(project, editor, file);
|
||||
}
|
||||
|
||||
public final boolean isRenaming(final DataContext dataContext) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Rename Reference" "true"
|
||||
class FooInterface {
|
||||
private int myInt;
|
||||
}
|
||||
|
||||
class Foo {
|
||||
void buzz() {
|
||||
myI<caret>nt + myInt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
class A {
|
||||
private int myField;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
void method() {
|
||||
myFi<caret>eld;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameWrongRefHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -60,6 +61,12 @@ public class RenameFieldTest extends LightCodeInsightTestCase {
|
||||
doTest("newField", "java");
|
||||
}
|
||||
|
||||
public void testRenameWrongRefDisabled() {
|
||||
String suffix = getTestName(false);
|
||||
configureByFile("/refactoring/renameField/before" + suffix + ".java");
|
||||
assertFalse(RenameWrongRefHandler.isAvailable(getProject(), getEditor(), getFile()));
|
||||
}
|
||||
|
||||
protected static void perform(String newName) {
|
||||
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
|
||||
.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
|
||||
|
||||
Reference in New Issue
Block a user