mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[grazie] Refactor RenameTo suggestions to ArrayList (without duplicates), null initially, volatile, assigned lazily
Co-authored-by: Peter Gromov <peter.gromov@jetbrains.com> Merge-request: IJ-MR-176786 Merged-by: Ilia Permiashkin <ilia.permiashkin@jetbrains.com> GitOrigin-RevId: a1c7bc955586e4d8ac15f99c463c5aac1579a082
This commit is contained in:
committed by
intellij-monorepo-bot
co-authored by
Peter Gromov
parent
d2759a2ebf
commit
ad535dd829
@@ -15,8 +15,6 @@ import com.intellij.spellchecker.settings.SpellCheckerSettings
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
import com.intellij.tools.ide.metrics.benchmark.Benchmark
|
||||
import com.intellij.ui.ChooserInterceptor
|
||||
import com.intellij.ui.UiInterceptors
|
||||
import java.util.function.Consumer
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RenameTo extends IntentionAndQuickFixAction implements Iconable, EventTrackingIntentionAction {
|
||||
|
||||
@@ -35,7 +36,7 @@ public class RenameTo extends IntentionAndQuickFixAction implements Iconable, Ev
|
||||
private final TextRange range;
|
||||
private final SmartPsiElementPointer<PsiElement> pointer;
|
||||
private final SpellcheckerRateTracker tracker;
|
||||
private final SequencedSet<String> suggestions = new LinkedHashSet<>();
|
||||
private volatile List<String> suggestions;
|
||||
private SmartPsiElementPointer<PsiElement> namedPointer;
|
||||
|
||||
public RenameTo(String typo, TextRange range, PsiElement psi, SpellcheckerRateTracker tracker) {
|
||||
@@ -103,8 +104,8 @@ public class RenameTo extends IntentionAndQuickFixAction implements Iconable, Ev
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nls String getFixName(SequencedCollection<String> suggestions) {
|
||||
return suggestions.size() == 1 ?
|
||||
public static @Nls String getFixName(List<String> suggestions) {
|
||||
return (suggestions != null && suggestions.size() == 1) ?
|
||||
SpellCheckerBundle.message("rename.to.0", suggestions.getFirst()) :
|
||||
SpellCheckerBundle.message("rename.to");
|
||||
}
|
||||
@@ -131,13 +132,14 @@ public class RenameTo extends IntentionAndQuickFixAction implements Iconable, Ev
|
||||
}
|
||||
|
||||
private void generateSuggestions(String name, PsiElement element) {
|
||||
if (suggestions.isEmpty()) {
|
||||
if (suggestions == null) {
|
||||
TextRange range = this.range.shiftLeft(element.getText().indexOf(name));
|
||||
SpellCheckerManager.getInstance(pointer.getProject()).getSuggestions(typo)
|
||||
this.suggestions = SpellCheckerManager.getInstance(pointer.getProject()).getSuggestions(typo)
|
||||
.stream()
|
||||
.map(suggestion -> range.replace(name, suggestion))
|
||||
.filter(suggestion -> RenameUtil.isValidName(element.getProject(), element, suggestion))
|
||||
.forEach(suggestions::add);
|
||||
.distinct()
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user