mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
java redundant cast: allow warnings in poly conditional when target type remains the same
GitOrigin-RevId: f953fc42882a1eaad0b0a8c65d1e94236f0ec99e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b4993721fb
commit
349c96eaee
@@ -13,7 +13,6 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.ig.psiutils.ExpectedTypeUtils;
|
||||
@@ -509,10 +508,12 @@ public class RedundantCastUtil {
|
||||
return;
|
||||
}
|
||||
if (!checkResolveAfterRemoveCast(parent)) return;
|
||||
final PsiExpression thenExpression = ((PsiConditionalExpression)parent).getThenExpression();
|
||||
final PsiExpression elseExpression = ((PsiConditionalExpression)parent).getElseExpression();
|
||||
final PsiExpression opposite = thenExpression == typeCast ? elseExpression : thenExpression;
|
||||
if (opposite == null || !Comparing.equal(conditionalType, opposite.getType())) return;
|
||||
if (!PsiPolyExpressionUtil.isPolyExpression((PsiExpression)parent)) {
|
||||
final PsiExpression thenExpression = ((PsiConditionalExpression)parent).getThenExpression();
|
||||
final PsiExpression elseExpression = ((PsiConditionalExpression)parent).getElseExpression();
|
||||
final PsiExpression opposite = thenExpression == typeCast ? elseExpression : thenExpression;
|
||||
if (opposite == null || !Comparing.equal(conditionalType, opposite.getType())) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiSynchronizedStatement &&
|
||||
|
||||
@@ -5,6 +5,7 @@ class Test {
|
||||
Object o = true ? ((Supplier<String>) () -> "") : null;
|
||||
Supplier<String> s1 = true ? ((<warning descr="Casting '() -> {...}' to 'Supplier<String>' is redundant">Supplier<String></warning>) () -> "") : null;
|
||||
Supplier<String> s2 = true ? ((A) () -> "") : null;
|
||||
A s3 = true ? ((<warning descr="Casting '() -> {...}' to 'A' is redundant">A</warning>) () -> "") : null;
|
||||
}
|
||||
|
||||
interface A extends Supplier<String> {}
|
||||
|
||||
Reference in New Issue
Block a user