mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: Fixed duplicate matching for complex expressions (IDEA-188127)
This commit is contained in:
+3
@@ -610,6 +610,9 @@ public class DuplicatesFinder {
|
||||
if (!myWithExtractedParameters || !(pattern instanceof PsiReferenceExpression) || !(candidate instanceof PsiReferenceExpression)) {
|
||||
return false;
|
||||
}
|
||||
if (myPattern.length == 1 && myPattern[0] == pattern) {
|
||||
return false;
|
||||
}
|
||||
ExtractableExpressionPart part1 = ExtractableExpressionPart.matchVariable((PsiReferenceExpression)pattern, null);
|
||||
if (part1 == null || part1.myVariable == null) {
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class CallChainExpression {
|
||||
String foo() {
|
||||
String s = <selection>A.a().b().c</selection>;
|
||||
System.out.println(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
static class A {
|
||||
static A a() { return new A(); }
|
||||
A b() { return this; }
|
||||
String c = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
class CallChainExpression {
|
||||
String foo() {
|
||||
String s = newMethod();
|
||||
System.out.println(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
private String newMethod() {
|
||||
return A.a().b().c;
|
||||
}
|
||||
|
||||
static class A {
|
||||
static A a() { return new A(); }
|
||||
A b() { return this; }
|
||||
String c = "";
|
||||
}
|
||||
}
|
||||
@@ -1229,6 +1229,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
doExitPointsTest(false);
|
||||
}
|
||||
|
||||
public void testCallChainExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestDisabledParam() throws PrepareFailedException {
|
||||
final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
settings.ELSE_ON_NEW_LINE = true;
|
||||
|
||||
Reference in New Issue
Block a user