mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove redundant casts when extract changed parameter type accordingly (IDEA-79743)
This commit is contained in:
@@ -27,7 +27,10 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
@@ -65,6 +68,31 @@ public class RedundantCastUtil {
|
||||
return arg;
|
||||
}
|
||||
|
||||
public static void removeCast(PsiTypeCastExpression castExpression) {
|
||||
if (castExpression == null) return;
|
||||
PsiExpression operand = castExpression.getOperand();
|
||||
if (operand instanceof PsiParenthesizedExpression) {
|
||||
final PsiParenthesizedExpression parExpr = (PsiParenthesizedExpression)operand;
|
||||
operand = parExpr.getExpression();
|
||||
}
|
||||
if (operand == null) return;
|
||||
|
||||
PsiElement toBeReplaced = castExpression;
|
||||
|
||||
PsiElement parent = castExpression.getParent();
|
||||
while (parent instanceof PsiParenthesizedExpression) {
|
||||
toBeReplaced = parent;
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
try {
|
||||
toBeReplaced.replace(operand);
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyCollectingVisitor extends MyIsRedundantVisitor {
|
||||
private final Set<PsiTypeCastExpression> myFoundCasts = new HashSet<PsiTypeCastExpression>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user