mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[java-refactoring] Inline method: support invert transformer in polyadic
GitOrigin-RevId: 516bb8355466a6f994c30692e1432353885d8b04
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5cc55e2d0e
commit
447ff452ae
@@ -26,6 +26,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.RedundantCastUtil;
|
||||
import com.intellij.refactoring.inline.InlineTransformer;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.CommonJavaRefactoringUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -214,7 +215,14 @@ public final class InlineUtil implements CommonJavaInlineUtil {
|
||||
}
|
||||
if (callParent instanceof PsiExpression && BoolUtils.isNegation((PsiExpression)callParent)) {
|
||||
PsiElement negationParent = PsiUtil.skipParenthesizedExprUp(callParent.getParent());
|
||||
if (negationParent instanceof PsiReturnStatement || negationParent instanceof PsiLambdaExpression) {
|
||||
if (negationParent instanceof PsiPolyadicExpression polyOp &&
|
||||
(polyOp.getOperationTokenType().equals(JavaTokenType.ANDAND) || polyOp.getOperationTokenType().equals(JavaTokenType.OROR)) &&
|
||||
PsiTreeUtil.isAncestor(ArrayUtil.getLastElement(polyOp.getOperands()), callParent, false)) {
|
||||
negationParent = PsiUtil.skipParenthesizedExprUp(negationParent.getParent());
|
||||
}
|
||||
if (negationParent instanceof PsiReturnStatement ||
|
||||
negationParent instanceof PsiYieldStatement ||
|
||||
negationParent instanceof PsiLambdaExpression) {
|
||||
return TailCallType.Invert;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.function.*;
|
||||
import java.util.*;
|
||||
|
||||
class InlineTest {
|
||||
Predicate<List<String>> getPredicate(String pivot) {
|
||||
return list -> list != null && !has<caret>Greater(list, pivot);
|
||||
}
|
||||
|
||||
<T extends Comparable<T>> boolean hasGreater(List<T> list, T pivot) {
|
||||
for (T t : list) {
|
||||
if (t.compareTo(pivot) > 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.function.*;
|
||||
import java.util.*;
|
||||
|
||||
class InlineTest {
|
||||
Predicate<List<String>> getPredicate(String pivot) {
|
||||
return list -> {
|
||||
if (list == null) return false;
|
||||
for (String t : list) {
|
||||
if (t.compareTo(pivot) > 0) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -595,6 +595,8 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testBooleanResultInIfChain() { doTest(); }
|
||||
|
||||
public void testLambdaIfAnd() { doTest(); }
|
||||
|
||||
public void testLambdaIfAndGenericNot() { doTest(); }
|
||||
|
||||
public void testInlineSingleImplementation() {
|
||||
TestDialogManager.setTestDialog(TestDialog.YES, getTestRootDisposable());
|
||||
|
||||
Reference in New Issue
Block a user