mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java redundant cast: preserve multiple type casts around functional interface when if expected type is the same as cast
isAssignable check may fail otherwise GitOrigin-RevId: d02c9d50645a2bbb0e957f077a4a66813c94afd6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b088cbd746
commit
c879ed4e4a
@@ -146,7 +146,7 @@ public class RedundantCastUtil {
|
||||
private void processTypeCastWithExpectedType(PsiExpression rExpr, @Nullable PsiType lType) {
|
||||
rExpr = deparenthesizeExpression(rExpr);
|
||||
if (rExpr instanceof PsiTypeCastExpression) {
|
||||
PsiExpression castOperand = getInnerMostOperand(((PsiTypeCastExpression)rExpr).getOperand());
|
||||
PsiExpression castOperand = deparenthesizeExpression(((PsiTypeCastExpression)rExpr).getOperand());
|
||||
if (castOperand != null) {
|
||||
if (castOperand instanceof PsiFunctionalExpression) {
|
||||
if (lType != null) {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
abstract class MyTest {
|
||||
public <T> T m() {
|
||||
//noinspection unchecked
|
||||
return (T)(Function)t -> t;
|
||||
}
|
||||
|
||||
public Function m1() {
|
||||
//noinspection unchecked
|
||||
return (<warning descr="Casting '(Function)t -> {...}' to 'Function' is redundant">Function</warning>)(<warning descr="Casting 't -> {...}' to 'Function' is redundant">Function</warning>)t -> t;
|
||||
}
|
||||
}
|
||||
+1
@@ -88,6 +88,7 @@ public class LambdaRedundantCastTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testThrowsStatementInLambdaBody() { doTest(); }
|
||||
public void testSynchronizeCasts() { doTest(); }
|
||||
public void testBoxingInConditionalOfLambdaReturn() { doTest(); }
|
||||
public void testRawMiddleMan() { doTest(); }
|
||||
public void testRejectReturnTypeChange() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user