[java-refactoring] IDEA-361117 Inline method does not collapse lambda expression back after single-line method inlining

GitOrigin-RevId: e54db7c5b175b264ac37c28a0cdab8ffd194c93f
This commit is contained in:
Tagir Valeev
2024-10-22 12:20:34 +00:00
committed by intellij-monorepo-bot
parent e757903e8c
commit f1473af5f4
7 changed files with 32 additions and 4 deletions
@@ -748,6 +748,13 @@ public class InlineMethodProcessor extends BaseRefactoringProcessor {
CommentTracker tracker = new CommentTracker();
PsiElement anchor = CommonJavaRefactoringUtil.getParentStatement(methodCall, true);
assert anchor != null;
if (anchor instanceof PsiReturnStatement oldReturn &&
PsiTreeUtil.skipWhitespacesAndCommentsBackward(anchor) instanceof PsiReturnStatement newReturn &&
newReturn.getReturnValue() != null) {
// Remove new return instead of old return to preserve surrounder anchors
tracker.replace(Objects.requireNonNull(oldReturn.getReturnValue()), newReturn.getReturnValue());
anchor = newReturn;
}
if (firstAdded != null) {
tracker.delete(anchor);
tracker.insertCommentsBefore(firstAdded);
@@ -7,5 +7,5 @@ class Test {
s1 = s1.trim();
if (s1.isEmpty()) return true;
return s1.length() % 2 != 0;
}
}
}
@@ -0,0 +1,11 @@
import java.util.function.*;
class InlineTest {
Predicate<String> getPredicate(int value) {
return str -> str.length() > value && <caret>checkString(str);
}
boolean checkString(String value) {
return value.startsWith("prefix") && value.endsWith("suffix");
}
}
@@ -0,0 +1,8 @@
import java.util.function.*;
class InlineTest {
Predicate<String> getPredicate(int value) {
return str -> str.length() > value && str.startsWith("prefix") && str.endsWith("suffix");
}
}
@@ -5,7 +5,7 @@ class Foo {
final Computable<String> elementComputable,
Object processingContext) {
return new WeighingComparable<String, ProximityLocation>(elementComputable, new ProximityLocation(), new Weigher[0]);
}
}
public static final Key<ProximityWeigher> WEIGHER_KEY = null;
}
@@ -4,9 +4,9 @@ class Temp {
}
public Object foo(Set bar) {
if (bar.size() < 2) {// Inline this
if (bar.size() < 2) {
bar.size(); // or online this
return null;
return null; // Inline this
}
return bar;
@@ -593,6 +593,8 @@ public class InlineMethodTest extends LightRefactoringTestCase {
public void testRenameLocalClassDoubleConflict() { doTest(); }
public void testBooleanResultInIfChain() { doTest(); }
public void testLambdaIfAnd() { doTest(); }
public void testInlineSingleImplementation() {
TestDialogManager.setTestDialog(TestDialog.YES, getTestRootDisposable());