mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: check qualifiers correspondence (IDEA-98515)
This commit is contained in:
@@ -348,6 +348,12 @@ public class DuplicatesFinder {
|
||||
if (!equivalentResolve(resolveResult1, resolveResult2, qualifier2)) {
|
||||
return false;
|
||||
}
|
||||
PsiElement qualifier1 = ((PsiJavaCodeReferenceElement)pattern).getQualifier();
|
||||
if (qualifier1 instanceof PsiReferenceExpression && qualifier2 instanceof PsiReferenceExpression &&
|
||||
!match.areCorrespond(((PsiReferenceExpression)qualifier1).resolve(), ((PsiReferenceExpression)qualifier2).resolve())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (pattern instanceof PsiTypeCastExpression) {
|
||||
|
||||
@@ -219,6 +219,11 @@ public final class Match {
|
||||
}
|
||||
}
|
||||
|
||||
boolean areCorrespond(PsiElement patternDeclaration, @NotNull PsiElement matchDeclaration) {
|
||||
PsiElement originalValue = myDeclarationCorrespondence.get(patternDeclaration);
|
||||
return originalValue == null || originalValue == matchDeclaration;
|
||||
}
|
||||
|
||||
private PsiElement replaceWith(final PsiStatement statement) throws IncorrectOperationException {
|
||||
final PsiElement matchStart = getMatchStart();
|
||||
final PsiElement matchEnd = getMatchEnd();
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.*;
|
||||
class Test {
|
||||
|
||||
public void method() {
|
||||
String a = "A";
|
||||
<selection>ArrayList<String> listA = new ArrayList<String>();
|
||||
listA.add(a);</selection>
|
||||
|
||||
ArrayList<String> listB = new ArrayList<String>();
|
||||
ArrayList<String> listC = new ArrayList<String>();
|
||||
listB.add("B");
|
||||
listC.add("C");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.*;
|
||||
class Test {
|
||||
|
||||
public void method() {
|
||||
String a = "A";
|
||||
newMethod(a);
|
||||
|
||||
ArrayList<String> listB = new ArrayList<String>();
|
||||
ArrayList<String> listC = new ArrayList<String>();
|
||||
listB.add("B");
|
||||
listC.add("C");
|
||||
}
|
||||
|
||||
private void newMethod(String a) {
|
||||
ArrayList<String> listA = new ArrayList<String>();
|
||||
listA.add(a);
|
||||
}
|
||||
}
|
||||
@@ -575,6 +575,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
public void testCheckQualifierMapping() throws Exception {
|
||||
doDuplicatesTest();
|
||||
}
|
||||
|
||||
private void doTestDisabledParam() throws PrepareFailedException {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.ELSE_ON_NEW_LINE = true;
|
||||
|
||||
Reference in New Issue
Block a user