mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
rename suggestions: suggest new names for non-variables (IDEA-121982)
This commit is contained in:
+10
-13
@@ -97,10 +97,11 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider {
|
||||
if (!(psiElement instanceof PsiNamedElement)) return null;
|
||||
String name = ((PsiNamedElement)psiElement).getName();
|
||||
if (name == null) return null;
|
||||
String prefix = "";
|
||||
if (psiElement instanceof PsiVariable) {
|
||||
final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(psiElement.getProject());
|
||||
final VariableKind kind = codeStyleManager.getVariableKind((PsiVariable)psiElement);
|
||||
final String prefix = codeStyleManager.getPrefixByVariableKind(kind);
|
||||
prefix = codeStyleManager.getPrefixByVariableKind(kind);
|
||||
if (kind == VariableKind.STATIC_FINAL_FIELD) {
|
||||
final String[] words = NameUtil.splitNameIntoWords(name);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
@@ -111,19 +112,15 @@ public class JavaNameSuggestionProvider implements NameSuggestionProvider {
|
||||
}
|
||||
return new String[] {buffer.toString()};
|
||||
}
|
||||
else {
|
||||
final List<String> result = new ArrayList<String>();
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
|
||||
if (name.startsWith(prefix)) {
|
||||
name = name.substring(prefix.length());
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
|
||||
}
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase())));
|
||||
return ArrayUtil.toStringArray(result);
|
||||
}
|
||||
|
||||
}
|
||||
return new String[]{name};
|
||||
final List<String> result = new ArrayList<String>();
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
|
||||
if (name.startsWith(prefix)) {
|
||||
name = name.substring(prefix.length());
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name)));
|
||||
}
|
||||
result.add(suggestProperlyCasedName(prefix, NameUtil.splitNameIntoWords(name.toLowerCase())));
|
||||
return ArrayUtil.toStringArray(result);
|
||||
}
|
||||
|
||||
private static String suggestProperlyCasedName(String prefix, String[] words) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyTest {
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
static Foo get<caret>_i() { return null; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class MyTest {
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
static Foo getI() { return null; }
|
||||
}
|
||||
@@ -18,11 +18,15 @@ package com.intellij.refactoring;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.rename.JavaNameSuggestionProvider;
|
||||
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: 12/4/11
|
||||
@@ -76,6 +80,20 @@ public class RenameMembersInplaceTest extends LightCodeInsightTestCase {
|
||||
doTestInplaceRename("bar");
|
||||
}
|
||||
|
||||
public void testNameSuggestion() throws Exception {
|
||||
configureByFile(BASE_PATH + "/" + getTestName(false) + ".java");
|
||||
|
||||
final PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase.getInstance().getAllAccepted());
|
||||
assertNotNull(element);
|
||||
|
||||
final Set<String> result = new LinkedHashSet<String>();
|
||||
new JavaNameSuggestionProvider().getSuggestedNames(element, getFile(), result);
|
||||
|
||||
CodeInsightTestUtil.doInlineRename(new MemberInplaceRenameHandler(), result.iterator().next(), getEditor(), element);
|
||||
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testConflictingMethodName() throws Exception {
|
||||
try {
|
||||
doTestInplaceRename("bar");
|
||||
|
||||
Reference in New Issue
Block a user