mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] rename wrong reference: disable hint for non-local variables; prettify popup
GitOrigin-RevId: d4edc196bee3b4dc83ce9cee59df93c8f7019e2b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f930fcf4f1
commit
fe31a2e44b
@@ -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
|
||||
|
||||
+11
-3
@@ -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<LookupElement> 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<PsiElement> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user