mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
[extract duplicates] fix: don't suggest change signature for expressions with local refs
GitOrigin-RevId: 58b7c2debe3960bbe2c64a1cbc521a8ebd872a1a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5371a9a6f6
commit
1210f80627
@@ -112,7 +112,8 @@ class JavaDuplicatesFinder(pattern: List<PsiElement>, private val predefinedChan
|
||||
return@filterNot true
|
||||
}
|
||||
|
||||
if (ExtractMethodHelper.hasReferencesToScope(duplicate.pattern, changedExpressions.map{ change -> change.pattern })){
|
||||
if (ExtractMethodHelper.hasReferencesToScope(duplicate.pattern, changedExpressions.map{ change -> change.pattern }) ||
|
||||
ExtractMethodHelper.hasReferencesToScope(duplicate.candidate, changedExpressions.map { change -> change.candidate })){
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -152,13 +153,13 @@ class JavaDuplicatesFinder(pattern: List<PsiElement>, private val predefinedChan
|
||||
return when {
|
||||
pattern.parent is PsiExpressionStatement -> false
|
||||
pattern is PsiReferenceExpression && pattern.parent is PsiCall -> false
|
||||
pattern is PsiExpression && candidate is PsiExpression -> canBeReplaced(pattern.type, candidate.type)
|
||||
pattern is PsiExpression && candidate is PsiExpression -> pattern.type != PsiType.VOID && canBeReplaced(pattern.type, candidate.type)
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun canBeReplaced(pattern: PsiType?, candidate: PsiType?): Boolean {
|
||||
return pattern != null && pattern != PsiType.VOID && candidate != null && pattern.isAssignableFrom(candidate)
|
||||
return pattern != null && candidate != null && pattern.isAssignableFrom(candidate)
|
||||
}
|
||||
|
||||
private fun isOvercomplicated(duplicate: Duplicate): Boolean {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
public class Test{
|
||||
|
||||
void test1(){
|
||||
<selection>String local = "local";
|
||||
System.out.println("one");
|
||||
System.out.println("two");</selection>
|
||||
}
|
||||
|
||||
void test2(){
|
||||
String local = "local";
|
||||
System.out.println("one");
|
||||
System.out.println(local.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
public class Test{
|
||||
|
||||
void test1(){
|
||||
extracted();
|
||||
}
|
||||
|
||||
private void extracted() {
|
||||
String local = "local";
|
||||
System.out.println("one");
|
||||
System.out.println("two");
|
||||
}
|
||||
|
||||
void test2(){
|
||||
String local = "local";
|
||||
System.out.println("one");
|
||||
System.out.println(local.toLowerCase());
|
||||
}
|
||||
}
|
||||
@@ -186,6 +186,10 @@ class ExtractMethodAndDuplicatesInplaceTest: LightJavaCodeInsightTestCase() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testAvoidChangeSignatureForLocalRefs(){
|
||||
doTest()
|
||||
}
|
||||
|
||||
fun testRefactoringListener(){
|
||||
templateTest {
|
||||
configureByFile("$BASE_PATH/${getTestName(false)}.java")
|
||||
|
||||
Reference in New Issue
Block a user