fixed PY-10964 Extract variable doesn't work as expected inside brackets

fixed PY-10221 Refactor->Extract->Variable may break square bracket symmetry and may break user input

there are overlapped reference in python for slice expression (P['x']) one for the reference itself, one for the operator [
This commit is contained in:
Ekaterina Tuzova
2013-10-08 17:07:37 +04:00
parent ecec49d524
commit 0a38c715d8
3 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
P = {'a': 0}
M = [42]
a_ = P['a']
M[a_] += 1

View File

@@ -0,0 +1,4 @@
P = {'a': 0}
M = [42]
M[<selection>P['a']</selection>] += 1

View File

@@ -5,6 +5,7 @@ import com.intellij.testFramework.TestDataPath;
import com.jetbrains.python.psi.PyCallExpression;
import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.refactoring.introduce.IntroduceHandler;
import com.jetbrains.python.refactoring.introduce.IntroduceOperation;
import com.jetbrains.python.refactoring.introduce.variable.PyIntroduceVariableHandler;
import java.util.Collection;
@@ -208,6 +209,23 @@ public class PyIntroduceVariableTest extends PyIntroduceTestCase {
doTest();
}
// PY-10964
public void testMultiReference() {
myFixture.configureByFile(getTestName(true) + ".py");
boolean inplaceEnabled = myFixture.getEditor().getSettings().isVariableInplaceRenameEnabled();
try {
myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(true);
IntroduceHandler handler = createHandler();
final IntroduceOperation operation = new IntroduceOperation(myFixture.getProject(), myFixture.getEditor(), myFixture.getFile(), "a_");
operation.setReplaceAll(true);
handler.performAction(operation);
myFixture.checkResultByFile(getTestName(true) + ".after.py");
}
finally {
myFixture.getEditor().getSettings().setVariableInplaceRenameEnabled(inplaceEnabled);
}
}
private void doTestCannotPerform() {
boolean thrownExpectedException = false;
try {