mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
RedundantCastUtil: some fixes for doubly parenthesized qualifiers
This commit is contained in:
@@ -19,10 +19,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -243,7 +240,7 @@ public class RedundantCastUtil {
|
||||
PsiReferenceExpression methodExpr = methodCall.getMethodExpression();
|
||||
PsiExpression qualifier = methodExpr.getQualifierExpression();
|
||||
if (!(qualifier instanceof PsiParenthesizedExpression)) return;
|
||||
PsiExpression operand = ((PsiParenthesizedExpression)qualifier).getExpression();
|
||||
PsiExpression operand = PsiUtil.skipParenthesizedExprDown(qualifier);
|
||||
if (!(operand instanceof PsiTypeCastExpression)) return;
|
||||
PsiTypeCastExpression typeCast = (PsiTypeCastExpression)operand;
|
||||
PsiExpression castOperand = typeCast.getOperand();
|
||||
@@ -266,7 +263,8 @@ public class RedundantCastUtil {
|
||||
if (!(expressionFromText instanceof PsiMethodCallExpression)) return;
|
||||
PsiMethodCallExpression newCall = (PsiMethodCallExpression)expressionFromText;
|
||||
PsiExpression newQualifier = newCall.getMethodExpression().getQualifierExpression();
|
||||
PsiExpression newOperand = ((PsiTypeCastExpression)((PsiParenthesizedExpression)newQualifier).getExpression()).getOperand();
|
||||
PsiTypeCastExpression newCast = Objects.requireNonNull((PsiTypeCastExpression)PsiUtil.skipParenthesizedExprDown(newQualifier));
|
||||
PsiExpression newOperand = Objects.requireNonNull(newCast.getOperand());
|
||||
newQualifier.replace(newOperand);
|
||||
|
||||
final JavaResolveResult newResult = newCall.getMethodExpression().advancedResolve(false);
|
||||
@@ -545,7 +543,8 @@ public class RedundantCastUtil {
|
||||
(expr.getType() instanceof PsiPrimitiveType || expr instanceof PsiFunctionalExpression)) {
|
||||
return;
|
||||
} else if (expr instanceof PsiLambdaExpression || expr instanceof PsiMethodReferenceExpression) {
|
||||
if (parent instanceof PsiParenthesizedExpression && parent.getParent() instanceof PsiReferenceExpression) {
|
||||
if (parent instanceof PsiParenthesizedExpression &&
|
||||
PsiUtil.skipParenthesizedExprUp(parent.getParent()) instanceof PsiReferenceExpression) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
private void doSomething() {
|
||||
(((Runnable) () -> System.out.println())).run();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with lambda" "true"
|
||||
class Test {
|
||||
private void doSomething() {
|
||||
((new <caret>Runnable() {
|
||||
public void run() {
|
||||
System.out.println();
|
||||
}
|
||||
})).run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user