[extract duplicates] IDEA-262587: don't skip duplicates with local assignments

GitOrigin-RevId: f0385f26151e310bb070de1ad07c637b14ef3354
This commit is contained in:
Alexandr Suhinin
2021-10-25 13:09:33 +03:00
committed by intellij-monorepo-bot
parent 6a00399fe2
commit 94f3aff222
6 changed files with 77 additions and 1 deletions

View File

@@ -128,7 +128,6 @@ class JavaDuplicatesFinder(pattern: List<PsiElement>, private val predefinedChan
return when {
pattern !is PsiExpression || candidate !is PsiExpression -> false
pattern.parent is PsiExpressionStatement -> false
pattern is PsiReferenceExpression && pattern.parent?.parent is PsiExpressionStatement -> false
pattern is PsiReferenceExpression && pattern.resolve() is PsiMethod && candidate is PsiReferenceExpression -> pattern.resolve() == candidate.resolve()
else -> pattern.type.isAssignableFrom(candidate.type)
}

View File

@@ -0,0 +1,16 @@
public class Sample2 {
void test1(){
<selection>int a = 1;
int b = 2;
a = 42;
System.out.println(a);</selection>
}
void test2(){
int x = 1;
int y = 2;
x = 42;
System.out.println(x);
}
}

View File

@@ -0,0 +1,17 @@
public class Sample2 {
void test1(){
extracted();
}
private void extracted() {
int a = 1;
int b = 2;
a = 42;
System.out.println(a);
}
void test2(){
extracted();
}
}

View File

@@ -0,0 +1,16 @@
public class Sample2 {
void test1(){
<selection>int a = 1;
int b = 2;
a = 42;
System.out.println(a);</selection>
}
void test2(){
int x = 1;
int y = 2;
y = 42;
System.out.println(x);
}
}

View File

@@ -0,0 +1,20 @@
public class Sample2 {
void test1(){
extracted();
}
private void extracted() {
int a = 1;
int b = 2;
a = 42;
System.out.println(a);
}
void test2(){
int x = 1;
int y = 2;
y = 42;
System.out.println(x);
}
}

View File

@@ -162,6 +162,14 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
doTest()
}
fun testLocalAssignmentDuplicates(){
doTest();
}
fun testWrongLocalAssignmentDuplicates(){
doTest();
}
fun testRefactoringListener(){
templateTest {
configureByFile("$BASE_PATH/${getTestName(false)}.java")