diff --git a/java/java-analysis-impl/src/messages/QuickFixBundle.properties b/java/java-analysis-impl/src/messages/QuickFixBundle.properties index 3732ffc4ec19..a122e215da97 100644 --- a/java/java-analysis-impl/src/messages/QuickFixBundle.properties +++ b/java/java-analysis-impl/src/messages/QuickFixBundle.properties @@ -368,7 +368,7 @@ move.0.from.module.1.to.2=Move ''{0}'' from module ''{1}'' to ''{2}'' add.0.to.classpath=Add ''{0}'' to classpath iterate.iterable=Iterate -rename.reference=Rename Reference +rename.reference=Variable to Reference choose.fields.to.generate.constructor.parameters.for=Choose Fields to Generate Constructor Parameters for choose.constructors.to.add.parameter.to=Choose Constructors to Add Parameter to diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameWrongRefFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameWrongRefFix.java index 9f6e7748122a..00780b9d3035 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameWrongRefFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RenameWrongRefFix.java @@ -19,6 +19,7 @@ import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.NlsSafe; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; @@ -73,7 +74,7 @@ public class RenameWrongRefFix implements HintAction { return !CreateFromUsageUtils.isValidReference(myRefExpr, myUnresolvedOnly); } - private LookupElement @NotNull [] collectItems() { + private LookupElement @NotNull [] collectItems(boolean onTheFly) { Set items = new LinkedHashSet<>(); boolean qualified = myRefExpr.getQualifierExpression() != null; @@ -83,6 +84,9 @@ public class RenameWrongRefFix implements HintAction { items.add(createLookupElement(var, v-> v.getName())); } } else { + if (onTheFly) { + return LookupElement.EMPTY_ARRAY; + } class MyScopeProcessor implements PsiScopeProcessor { final ArrayList myResult = new ArrayList<>(); final boolean myFilterMethods; @@ -138,7 +142,7 @@ public class RenameWrongRefFix implements HintAction { public void invoke(@NotNull Project project, final Editor editor, PsiFile file) { PsiReferenceExpression[] refs = CreateFromUsageUtils.collectExpressions(myRefExpr, PsiMember.class, PsiFile.class); PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, PsiMember.class, PsiFile.class); - LookupElement[] items = collectItems(); + LookupElement[] items = collectItems(false); ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName()); TemplateBuilderImpl builder = new TemplateBuilderImpl(element); @@ -177,7 +181,7 @@ public class RenameWrongRefFix implements HintAction { if (!Registry.is("editor.show.popup.for.unresolved.references", false)) { return false; } - LookupElement[] items = collectItems(); + LookupElement[] items = collectItems(true); if (items.length == 0) return false; String hintText = ShowAutoImportPass.getMessage(items.length > 1, items[0].getLookupString()); TextRange textRange = myRefExpr.getTextRange(); @@ -215,6 +219,10 @@ public class RenameWrongRefFix implements HintAction { if (value instanceof LookupElement) { @NlsSafe String refSuggestion = ((LookupElement)value).getLookupString(); setText(refSuggestion); + Object object = ((LookupElement)value).getObject(); + if (object instanceof Iconable) { + setIcon(((Iconable)object).getIcon(0)); + } } return component; }