mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[java-refactoring] isFirstUse: handle static method qualifier
Fixes IDEA-356148 Inlining method creates undesirable temporary variable (cherry picked from commit 34091cb3a6c6388b2086d92e8cd4b206b9250202) IJ-CR-149087 GitOrigin-RevId: 5d38476c8ff706eb180c628d7b481d0f7b00c7ff
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6fe3ec50ef
commit
5e26c44314
@@ -543,7 +543,11 @@ public final class InlineUtil implements CommonJavaInlineUtil {
|
||||
if (!(list.getParent() instanceof PsiCallExpression call)) return false;
|
||||
PsiExpression qualifier = call instanceof PsiMethodCallExpression methodCall ? methodCall.getMethodExpression().getQualifierExpression() :
|
||||
call instanceof PsiNewExpression newExpression ? newExpression.getQualifier() : null;
|
||||
if (qualifier != null && !ExpressionUtils.isSafelyRecomputableExpression(qualifier)) return false;
|
||||
if (qualifier != null &&
|
||||
!(ExpressionUtils.isSafelyRecomputableExpression(qualifier) ||
|
||||
qualifier instanceof PsiReferenceExpression qualifierRef && qualifierRef.resolve() instanceof PsiClass)) {
|
||||
return false;
|
||||
}
|
||||
cur = call;
|
||||
} else if (parent instanceof PsiAssignmentExpression assign && assign.getRExpression() == cur) {
|
||||
PsiExpression lExpression = assign.getLExpression();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import java.util.*;
|
||||
|
||||
// IDEA-356148
|
||||
public class Example {
|
||||
|
||||
public void example() {
|
||||
|
||||
final Map<String, Object> map = Map.of();
|
||||
if (<caret>test((String)map.get("whatever"))) {
|
||||
System.out.println("??");
|
||||
}
|
||||
|
||||
final Object obj = "foo";
|
||||
if (test((String)obj)) {
|
||||
System.out.println("??");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean test(final String str) {
|
||||
return Objects.isNull(str);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import java.util.*;
|
||||
|
||||
// IDEA-356148
|
||||
public class Example {
|
||||
|
||||
public void example() {
|
||||
|
||||
final Map<String, Object> map = Map.of();
|
||||
if (Objects.isNull((String) map.get("whatever"))) {
|
||||
System.out.println("??");
|
||||
}
|
||||
|
||||
final Object obj = "foo";
|
||||
if (Objects.isNull((String) obj)) {
|
||||
System.out.println("??");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -580,6 +580,7 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testAndChainLambdaSingleLine() { doTest(); }
|
||||
|
||||
public void testInlineDoubleCall() { doTest(); }
|
||||
public void testInlineNestedCall() { doTest(); }
|
||||
|
||||
public void testTernaryBranch() { doTest(); }
|
||||
public void testTernaryBranchCollapsible() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user