mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[java-refactoring] isFirstUse: take PsiAssignmentExpression into account
Fixes IDEA-361852 Java Inline Method refactor introduces intermediate variables (cherry picked from commit 680fbb62f3440b7ae29f4de1793260fe5be0ab36) IJ-CR-149087 GitOrigin-RevId: c9ede4356696412b656b0295f21f534cce04bc30
This commit is contained in:
committed by
intellij-monorepo-bot
parent
cc45672e28
commit
6fe3ec50ef
@@ -545,8 +545,15 @@ public final class InlineUtil implements CommonJavaInlineUtil {
|
||||
call instanceof PsiNewExpression newExpression ? newExpression.getQualifier() : null;
|
||||
if (qualifier != null && !ExpressionUtils.isSafelyRecomputableExpression(qualifier)) return false;
|
||||
cur = call;
|
||||
}
|
||||
else if (parent instanceof PsiReferenceExpression ref) {
|
||||
} else if (parent instanceof PsiAssignmentExpression assign && assign.getRExpression() == cur) {
|
||||
PsiExpression lExpression = assign.getLExpression();
|
||||
if (lExpression instanceof PsiReferenceExpression lRef &&
|
||||
(lRef.getQualifierExpression() == null || lRef.getQualifierExpression() instanceof PsiQualifiedExpression)) {
|
||||
cur = assign;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (parent instanceof PsiReferenceExpression ref) {
|
||||
if (parent.getParent() instanceof PsiMethodCallExpression call) {
|
||||
cur = call;
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.List;
|
||||
|
||||
public class Foo {
|
||||
|
||||
public Foo hi() {
|
||||
System.out.println("hi");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Foo hiTwice() {
|
||||
return hi().hi();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Foo().hi().<caret>hiTwice().hi();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public class Foo {
|
||||
|
||||
public Foo hi() {
|
||||
System.out.println("hi");
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Foo().hi().hi().hi().hi();
|
||||
}
|
||||
}
|
||||
@@ -579,6 +579,8 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testAndChainLambda() { doTest(); }
|
||||
public void testAndChainLambdaSingleLine() { doTest(); }
|
||||
|
||||
public void testInlineDoubleCall() { doTest(); }
|
||||
|
||||
public void testTernaryBranch() { doTest(); }
|
||||
public void testTernaryBranchCollapsible() { doTest(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user