Don't suggest defined unread and unmodified variables in extract method (PY-6391)

This commit is contained in:
Andrey Vlasovskikh
2012-04-23 19:39:08 +04:00
parent 0099417de2
commit 1c8d1c937b
4 changed files with 22 additions and 3 deletions
@@ -139,9 +139,6 @@ public class PyCodeFragmentBuilder extends PyRecursiveElementVisitor {
}
// If declaration is before we look for modifications inside
if (pos == Position.BEFORE) {
if (!isTopLevel(element)) {
inElements.add(name);
}
final List<PyElement> list = modifiedInsideMap.get(name);
boolean modificationSeen = false;
if (list != null) {
@@ -154,6 +151,9 @@ public class PyCodeFragmentBuilder extends PyRecursiveElementVisitor {
}
}
if (modificationSeen) {
if (!isTopLevel(element)) {
inElements.add(name);
}
break;
}
}
@@ -0,0 +1,9 @@
def bar():
if 11 > 4:
print('ok')
def main(indices):
foo = True
bar()
return foo
@@ -0,0 +1,5 @@
def main(indices):
foo = True
<selection>if 11 > 4:
print('ok')</selection>
return foo
@@ -162,4 +162,9 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
public void testLocalVarDefinedBeforeModifiedInside() {
doTest("bar");
}
// PY-6391
public void testDefinedBeforeAccessedAfter() {
doTest("bar");
}
}