mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
java: remove redundant cast: ensure operation priority
GitOrigin-RevId: cad7c6e31f088f5b9528ee3d35743fd5b4b8ef66
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f00747671
commit
1c2a41050d
@@ -7,6 +7,7 @@ import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiParenthesizedExpression;
|
||||
import com.intellij.psi.PsiTypeCastExpression;
|
||||
import com.intellij.psi.util.PsiPrecedenceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
|
||||
@@ -19,8 +20,9 @@ public class RemoveRedundantCastUtil {
|
||||
PsiExpression operand = castExpression.getOperand();
|
||||
if (operand instanceof PsiParenthesizedExpression) {
|
||||
final PsiParenthesizedExpression parExpr = (PsiParenthesizedExpression)operand;
|
||||
if (!(parent instanceof PsiExpression) ||
|
||||
!PsiPrecedenceUtil.areParenthesesNeeded(parExpr.getExpression(), (PsiExpression)parent, true)) {
|
||||
PsiElement topParent = PsiUtil.skipParenthesizedExprUp(parent);
|
||||
if (!(topParent instanceof PsiExpression) ||
|
||||
!PsiPrecedenceUtil.areParenthesesNeeded(parExpr.getExpression(), (PsiExpression)topParent, true)) {
|
||||
operand = parExpr.getExpression();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove redundant cast(s)" "true"
|
||||
class Test {
|
||||
{
|
||||
//c1
|
||||
String s = "" + (1 - 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Remove redundant cast(s)" "true"
|
||||
class Test {
|
||||
{
|
||||
String s = "" + ((in<caret>t)//c1
|
||||
(1 - 2));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user