Java: Fixed comparing potential matches when detecting duplicates of the extracted method (IDEA-182275)

This commit is contained in:
Pavel Dolgov
2017-11-17 15:44:44 +03:00
parent 9d7fa672d4
commit 7fa96faf72
4 changed files with 43 additions and 1 deletions
@@ -564,7 +564,7 @@ public class DuplicatesFinder {
PsiElement child2 = children2[i];
if (!matchPattern(child1, child2, candidates, match)) {
matchedExtractablePart = matchExtractableExpression(child1, child2, candidates, match, true);
return matchedExtractablePart != null && matchedExtractablePart;
if (matchedExtractablePart == null || !matchedExtractablePart) return false;
}
}
@@ -0,0 +1,17 @@
class WriteDifferentFieldsDuplicate {
Runnable x;
Runnable y;
private void foo() {
<selection>
if (x != null) {
x.run();
x = null;
}</selection>
if (y != null) {
y.run();
y = null;
}
}
}
@@ -0,0 +1,21 @@
class WriteDifferentFieldsDuplicate {
Runnable x;
Runnable y;
private void foo() {
newMethod();
if (y != null) {
y.run();
y = null;
}
}
private void newMethod() {
if (x != null) {
x.run();
x = null;
}
}
}
@@ -1177,6 +1177,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doTest();
}
public void testWriteDifferentFieldsDuplicate() throws Exception {
doDuplicatesTest();
}
private void doTestDisabledParam() throws PrepareFailedException {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
settings.ELSE_ON_NEW_LINE = true;