mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
in-place refactorings don't suggest names of built-in types (PY-4474)
This commit is contained in:
+2
-2
@@ -13,8 +13,8 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* @author Alexey.Ivanov
|
||||
*/
|
||||
public class NameSuggestorUtil {
|
||||
private NameSuggestorUtil() {
|
||||
public class NameSuggesterUtil {
|
||||
private NameSuggesterUtil() {
|
||||
}
|
||||
|
||||
private static String deleteNonLetterFromString(@NotNull final String string) {
|
||||
@@ -30,7 +30,7 @@ import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.PyNoneType;
|
||||
import com.jetbrains.python.psi.types.PyType;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import com.jetbrains.python.refactoring.NameSuggestorUtil;
|
||||
import com.jetbrains.python.refactoring.NameSuggesterUtil;
|
||||
import com.jetbrains.python.refactoring.PyRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -141,13 +141,17 @@ abstract public class IntroduceHandler implements RefactoringActionHandler {
|
||||
}
|
||||
}
|
||||
if (text != null) {
|
||||
candidates.addAll(NameSuggestorUtil.generateNames(text));
|
||||
candidates.addAll(NameSuggesterUtil.generateNames(text));
|
||||
}
|
||||
PyType type = expression.getType(TypeEvalContext.slow());
|
||||
final TypeEvalContext context = TypeEvalContext.slow();
|
||||
PyType type = expression.getType(context);
|
||||
if (type != null && type != PyNoneType.INSTANCE) {
|
||||
final String typeName = type.getName();
|
||||
String typeName = type.getName();
|
||||
if (typeName != null) {
|
||||
candidates.addAll(NameSuggestorUtil.generateNamesByType(typeName));
|
||||
if (type.isBuiltin(context)) {
|
||||
typeName = typeName.substring(0, 1);
|
||||
}
|
||||
candidates.addAll(NameSuggesterUtil.generateNamesByType(typeName));
|
||||
}
|
||||
}
|
||||
final PyKeywordArgument kwArg = PsiTreeUtil.getParentOfType(expression, PyKeywordArgument.class);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"foo <caret>bar"
|
||||
@@ -34,7 +34,7 @@ public class PyIntroduceConstantTest extends PyIntroduceTestCase {
|
||||
}
|
||||
|
||||
public void testSuggestUniqueNames() { // PY-4409
|
||||
doTestSuggestions(PyExpression.class, "STR1");
|
||||
doTestSuggestions(PyExpression.class, "S1");
|
||||
}
|
||||
|
||||
public void testPy4414() {
|
||||
|
||||
@@ -20,14 +20,18 @@ import java.util.Collection;
|
||||
*/
|
||||
public abstract class PyIntroduceTestCase extends PyLightFixtureTestCase {
|
||||
protected void doTestSuggestions(Class<? extends PyExpression> parentClass, String... expectedNames) {
|
||||
final Collection<String> names = buildSuggestions(parentClass);
|
||||
for (String expectedName : expectedNames) {
|
||||
assertTrue(StringUtil.join(names, ", "), names.contains(expectedName));
|
||||
}
|
||||
}
|
||||
|
||||
protected Collection<String> buildSuggestions(Class<? extends PyExpression> parentClass) {
|
||||
myFixture.configureByFile(getTestName(true) + ".py");
|
||||
IntroduceHandler handler = createHandler();
|
||||
PyExpression expr = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()),
|
||||
parentClass);
|
||||
final Collection<String> names = handler.getSuggestedNames(expr);
|
||||
for (String expectedName : expectedNames) {
|
||||
assertTrue(StringUtil.join(names, ", "), names.contains(expectedName));
|
||||
}
|
||||
return handler.getSuggestedNames(expr);
|
||||
}
|
||||
|
||||
protected abstract IntroduceHandler createHandler();
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.refactoring.introduce.IntroduceHandler;
|
||||
import com.jetbrains.python.refactoring.introduce.variable.PyIntroduceVariableHandler;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@@ -44,6 +46,12 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
|
||||
doTestSuggestions(PyExpression.class, "foo_bar");
|
||||
}
|
||||
|
||||
public void testDontSuggestBuiltinTypeNames() { // PY-4474
|
||||
final Collection<String> strings = buildSuggestions(PyExpression.class);
|
||||
assertTrue(strings.contains("s"));
|
||||
assertFalse(strings.contains("str"));
|
||||
}
|
||||
|
||||
public void testIncorrectSelection() { // PY-4455
|
||||
doTestCannotPerform();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user