mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
spellchecker: forbid to suggest existing name when "Rename To" (IDEA-80936)
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.refactoring.rename;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 2/8/12
|
||||
*/
|
||||
public abstract class PreferrableNameSuggestionProvider implements NameSuggestionProvider {
|
||||
public boolean shouldCheckOthers() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -33,7 +33,9 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.refactoring.rename.NameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.PreferrableNameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.inplace.InplaceRefactoring;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.ui.PositionTracker;
|
||||
@@ -240,7 +242,8 @@ public abstract class InplaceVariableIntroducer<E extends PsiElement> extends In
|
||||
final LinkedHashSet<String> names = new LinkedHashSet<String>();
|
||||
names.add(text);
|
||||
for (NameSuggestionProvider provider : Extensions.getExtensions(NameSuggestionProvider.EP_NAME)) {
|
||||
provider.getSuggestedNames(psiVariable, psiVariable, names);
|
||||
final SuggestedNameInfo suggestedNameInfo = provider.getSuggestedNames(psiVariable, psiVariable, names);
|
||||
if (suggestedNameInfo != null && provider instanceof PreferrableNameSuggestionProvider && !((PreferrableNameSuggestionProvider)provider).shouldCheckOthers()) break;
|
||||
}
|
||||
final LookupElement[] items = new LookupElement[names.size()];
|
||||
final Iterator<String> iterator = names.iterator();
|
||||
|
||||
@@ -138,7 +138,10 @@ public class RenameDialog extends RefactoringDialog {
|
||||
final NameSuggestionProvider[] providers = Extensions.getExtensions(NameSuggestionProvider.EP_NAME);
|
||||
for(NameSuggestionProvider provider: providers) {
|
||||
SuggestedNameInfo info = provider.getSuggestedNames(myPsiElement, myNameSuggestionContext, result);
|
||||
if (info != null) mySuggestedNameInfo = info;
|
||||
if (info != null) {
|
||||
mySuggestedNameInfo = info;
|
||||
if (provider instanceof PreferrableNameSuggestionProvider && !((PreferrableNameSuggestionProvider)provider).shouldCheckOthers()) break;
|
||||
}
|
||||
}
|
||||
if (result.size() == 0) {
|
||||
result.add(UsageViewUtil.getShortName(myPsiElement));
|
||||
|
||||
+4
-1
@@ -60,6 +60,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
@@ -68,6 +69,7 @@ import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.rename.NameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.PreferrableNameSuggestionProvider;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -616,7 +618,8 @@ public abstract class InplaceRefactoring {
|
||||
if (names == null) {
|
||||
names = new LinkedHashSet<String>();
|
||||
for (NameSuggestionProvider provider : Extensions.getExtensions(NameSuggestionProvider.EP_NAME)) {
|
||||
provider.getSuggestedNames(myElementToRename, myElementToRename, names);
|
||||
final SuggestedNameInfo suggestedNameInfo = provider.getSuggestedNames(myElementToRename, myElementToRename, names);
|
||||
if (suggestedNameInfo != null && provider instanceof PreferrableNameSuggestionProvider && !((PreferrableNameSuggestionProvider)provider).shouldCheckOthers()) break;
|
||||
}
|
||||
}
|
||||
myLookupItems = new LookupElement[names.size()];
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
key="spellchecking.inspection.name" groupKey="spelling" enabledByDefault="true" level="TYPO"
|
||||
implementationClass="com.intellij.spellchecker.inspections.SpellCheckingInspection"/>
|
||||
|
||||
<nameSuggestionProvider id="DictionarySuggestionProvider" implementation="com.intellij.spellchecker.quickfixes.DictionarySuggestionProvider"/>
|
||||
<nameSuggestionProvider id="DictionarySuggestionProvider" implementation="com.intellij.spellchecker.quickfixes.DictionarySuggestionProvider" order="first"/>
|
||||
<severitiesProvider implementation="com.intellij.spellchecker.SpellCheckerSeveritiesProvider"/>
|
||||
|
||||
<spellchecker.support language="TEXT" implementationClass="com.intellij.spellchecker.tokenizer.SpellcheckingStrategy"/>
|
||||
|
||||
+7
-2
@@ -18,14 +18,14 @@ package com.intellij.spellchecker.quickfixes;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.psi.codeStyle.SuggestedNameInfo;
|
||||
import com.intellij.refactoring.rename.NameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.PreferrableNameSuggestionProvider;
|
||||
import com.intellij.spellchecker.SpellCheckerManager;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
|
||||
public class DictionarySuggestionProvider implements NameSuggestionProvider {
|
||||
public class DictionarySuggestionProvider extends PreferrableNameSuggestionProvider {
|
||||
|
||||
private boolean active;
|
||||
|
||||
@@ -33,6 +33,11 @@ public class DictionarySuggestionProvider implements NameSuggestionProvider {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCheckOthers() {
|
||||
return !active;
|
||||
}
|
||||
|
||||
public SuggestedNameInfo getSuggestedNames(PsiElement element, PsiElement nameSuggestionContext, Set<String> result) {
|
||||
assert result != null;
|
||||
if (!active || nameSuggestionContext==null) {
|
||||
|
||||
Reference in New Issue
Block a user