mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 15:06:56 +07:00
[spellchecker] migrate quick fixes creation to SpellCheckerQuickFixFactory
GitOrigin-RevId: dc14505126ac82d997bace928d0dea8bfc48d347
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5a8efdfc97
commit
1339ccbc9a
@@ -15,7 +15,6 @@ import com.intellij.psi.PsiElement;
|
|||||||
import com.intellij.psi.PsiElementVisitor;
|
import com.intellij.psi.PsiElementVisitor;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.spellchecker.SpellCheckerManager;
|
import com.intellij.spellchecker.SpellCheckerManager;
|
||||||
import com.intellij.spellchecker.quickfixes.SpellCheckerQuickFix;
|
|
||||||
import com.intellij.spellchecker.tokenizer.*;
|
import com.intellij.spellchecker.tokenizer.*;
|
||||||
import com.intellij.spellchecker.util.SpellCheckerBundle;
|
import com.intellij.spellchecker.util.SpellCheckerBundle;
|
||||||
import com.intellij.util.Consumer;
|
import com.intellij.util.Consumer;
|
||||||
@@ -139,15 +138,16 @@ public final class SpellCheckingInspection extends LocalInspectionTool {
|
|||||||
tokenizer.tokenize(element, consumer);
|
tokenizer.tokenize(element, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addBatchDescriptor(PsiElement element,
|
private static void addBatchDescriptor(@NotNull PsiElement element,
|
||||||
@NotNull TextRange textRange,
|
@NotNull TextRange textRange,
|
||||||
|
@NotNull String word,
|
||||||
@NotNull ProblemsHolder holder) {
|
@NotNull ProblemsHolder holder) {
|
||||||
SpellCheckerQuickFix[] fixes = SpellcheckingStrategy.getDefaultBatchFixes(element);
|
var fixes = SpellcheckingStrategy.getDefaultBatchFixes(element, textRange, word);
|
||||||
ProblemDescriptor problemDescriptor = createProblemDescriptor(element, textRange, fixes, false);
|
ProblemDescriptor problemDescriptor = createProblemDescriptor(element, textRange, fixes, false);
|
||||||
holder.registerProblem(problemDescriptor);
|
holder.registerProblem(problemDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addRegularDescriptor(PsiElement element, @NotNull TextRange textRange, @NotNull ProblemsHolder holder,
|
private static void addRegularDescriptor(@NotNull PsiElement element, @NotNull TextRange textRange, @NotNull ProblemsHolder holder,
|
||||||
boolean useRename, String wordWithTypo) {
|
boolean useRename, String wordWithTypo) {
|
||||||
SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, element.getLanguage());
|
SpellcheckingStrategy strategy = getSpellcheckingStrategy(element, element.getLanguage());
|
||||||
|
|
||||||
@@ -240,7 +240,7 @@ public final class SpellCheckingInspection extends LocalInspectionTool {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
myAlreadyChecked.add(word);
|
myAlreadyChecked.add(word);
|
||||||
addBatchDescriptor(myElement, range, myHolder);
|
addBatchDescriptor(myElement, range, word, myHolder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,20 +14,17 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
|
import com.intellij.spellchecker.DictionaryLayer;
|
||||||
import com.intellij.spellchecker.DictionaryLayersProvider;
|
import com.intellij.spellchecker.DictionaryLayersProvider;
|
||||||
import com.intellij.spellchecker.inspections.PlainTextSplitter;
|
import com.intellij.spellchecker.inspections.PlainTextSplitter;
|
||||||
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
|
import com.intellij.spellchecker.inspections.SpellCheckingInspection;
|
||||||
import com.intellij.spellchecker.quickfixes.ChangeTo;
|
import com.intellij.spellchecker.quickfixes.*;
|
||||||
import com.intellij.spellchecker.quickfixes.RenameTo;
|
|
||||||
import com.intellij.spellchecker.quickfixes.SaveTo;
|
|
||||||
import com.intellij.spellchecker.quickfixes.SpellCheckerQuickFix;
|
|
||||||
import com.intellij.spellchecker.settings.SpellCheckerSettings;
|
import com.intellij.spellchecker.settings.SpellCheckerSettings;
|
||||||
import com.intellij.util.KeyedLazyInstance;
|
import com.intellij.util.KeyedLazyInstance;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,42 +116,44 @@ public class SpellcheckingStrategy {
|
|||||||
&& InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element);
|
&& InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost)element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalQuickFix[] getRegularFixes(PsiElement element,
|
public LocalQuickFix[] getRegularFixes(@NotNull PsiElement element,
|
||||||
@NotNull TextRange textRange,
|
@NotNull TextRange textRange,
|
||||||
boolean useRename,
|
boolean useRename,
|
||||||
String typo) {
|
String typo) {
|
||||||
return getDefaultRegularFixes(useRename, typo, element, textRange);
|
return getDefaultRegularFixes(useRename, typo, element, textRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalQuickFix[] getDefaultRegularFixes(boolean useRename, String typo, @Nullable PsiElement element,
|
public static LocalQuickFix[] getDefaultRegularFixes(boolean useRename,
|
||||||
|
String typo,
|
||||||
|
@NotNull PsiElement element,
|
||||||
@NotNull TextRange range) {
|
@NotNull TextRange range) {
|
||||||
ArrayList<LocalQuickFix> result = new ArrayList<>();
|
ArrayList<LocalQuickFix> result = new ArrayList<>();
|
||||||
|
|
||||||
if (useRename && PsiTreeUtil.getNonStrictParentOfType(element, PsiNamedElement.class) != null) {
|
if (useRename && PsiTreeUtil.getNonStrictParentOfType(element, PsiNamedElement.class) != null) {
|
||||||
result.add(new RenameTo());
|
result.add(SpellCheckerQuickFixFactory.rename(element));
|
||||||
} else if (element != null) {
|
} else {
|
||||||
result.addAll(new ChangeTo(typo, element, range).getAllAsFixes());
|
result.addAll(SpellCheckerQuickFixFactory.changeToVariants(element, range, typo));
|
||||||
}
|
|
||||||
|
|
||||||
if (element == null) {
|
|
||||||
result.add(new SaveTo(typo));
|
|
||||||
return result.toArray(LocalQuickFix.EMPTY_ARRAY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final SpellCheckerSettings settings = SpellCheckerSettings.getInstance(element.getProject());
|
final SpellCheckerSettings settings = SpellCheckerSettings.getInstance(element.getProject());
|
||||||
if (settings.isUseSingleDictionaryToSave()) {
|
if (settings.isUseSingleDictionaryToSave()) {
|
||||||
result.add(new SaveTo(typo, DictionaryLayersProvider.getLayer(element.getProject(), settings.getDictionaryToSave())));
|
DictionaryLayer layer = DictionaryLayersProvider.getLayer(element.getProject(), settings.getDictionaryToSave());
|
||||||
|
result.add(SpellCheckerQuickFixFactory.saveTo(element, range, typo, layer));
|
||||||
return result.toArray(LocalQuickFix.EMPTY_ARRAY);
|
return result.toArray(LocalQuickFix.EMPTY_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.add(new SaveTo(typo));
|
result.add(SpellCheckerQuickFixFactory.saveTo(element, range, typo));
|
||||||
return result.toArray(LocalQuickFix.EMPTY_ARRAY);
|
return result.toArray(LocalQuickFix.EMPTY_ARRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SpellCheckerQuickFix[] getDefaultBatchFixes(PsiElement element) {
|
public static LocalQuickFix[] getDefaultBatchFixes(
|
||||||
|
@NotNull PsiElement element,
|
||||||
|
@NotNull TextRange textRange,
|
||||||
|
@NotNull String word
|
||||||
|
) {
|
||||||
return DictionaryLayersProvider.getAllLayers(element.getProject())
|
return DictionaryLayersProvider.getAllLayers(element.getProject())
|
||||||
.stream().map(it -> new SaveTo(it))
|
.stream().map(it -> SpellCheckerQuickFixFactory.saveTo(element, textRange, word, it))
|
||||||
.toArray(SpellCheckerQuickFix[]::new);
|
.toArray(LocalQuickFix[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMyContext(@NotNull PsiElement element) {
|
public boolean isMyContext(@NotNull PsiElement element) {
|
||||||
|
|||||||
Reference in New Issue
Block a user