do replace duplicates in different functions in class during extract method

This commit is contained in:
Ekaterina Tuzova
2013-04-25 16:47:16 +04:00
parent 8ac4b9c4c3
commit 129f17673f
4 changed files with 27 additions and 1 deletions
@@ -202,8 +202,11 @@ public class PyExtractMethodUtil {
@NotNull final PyFunction generatedMethod,
@NotNull final PyDuplicatesFinder finder,
@NotNull final Editor editor) {
final ScopeOwner owner = ScopeUtil.getScopeOwner(callElement);
ScopeOwner owner = ScopeUtil.getScopeOwner(callElement);
if (owner instanceof PsiFile) return;
if (owner instanceof PyFunction && ((PyFunction)owner).getContainingClass() != null) {
owner = ((PyFunction)owner).getContainingClass();
}
final List<Pair<PsiElement, PsiElement>> duplicates = finder.findDuplicates(owner, generatedMethod);
if (duplicates.size() > 0) {
@@ -0,0 +1,11 @@
class A:
def foo(self):
print 1
def baz(self):
self.foo()
self.foo()
def bar(self):
self.foo()
@@ -0,0 +1,8 @@
class A:
def baz(self):
print<caret> 1
print 1
def bar(self):
print 1
@@ -258,4 +258,8 @@ public class PyExtractMethodTest extends LightMarkedTestCase {
public void testDuplicateMultiLine() {
doTest("foo");
}
public void testDuplicateInClass() {
doTest("foo");
}
}