mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] redundant cast: don't suggest to remove cast in switch branches without expected type (IDEA-296622)
GitOrigin-RevId: 24bebef33ad6d01861a68df1470f2ed2f454c4c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf5d8ffdc8
commit
2fd039b5eb
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
@@ -736,8 +736,10 @@ public final class RedundantCastUtil {
|
||||
visitSwitchBlockSelector(expression);
|
||||
|
||||
PsiType expectedTypeByParent = PsiTypesUtil.getExpectedTypeByParent(expression);
|
||||
for (PsiExpression resultExpression : PsiUtil.getSwitchResultExpressions(expression)) {
|
||||
addIfNarrowing(resultExpression, expectedTypeByParent);
|
||||
if (expectedTypeByParent != null) {
|
||||
for (PsiExpression resultExpression : PsiUtil.getSwitchResultExpressions(expression)) {
|
||||
addIfNarrowing(resultExpression, expectedTypeByParent);
|
||||
}
|
||||
}
|
||||
|
||||
super.visitSwitchExpression(expression);
|
||||
|
||||
+8
@@ -31,4 +31,12 @@ class RedundantCast {
|
||||
default -> new ArrayList<>();
|
||||
};
|
||||
}
|
||||
|
||||
void castForFunctionalExpression(String s) {
|
||||
(switch (s) {
|
||||
case "a" -> (Runnable)() -> System.out.println("a");
|
||||
case "b" -> (Runnable)() -> System.out.println("b");
|
||||
default -> throw new IllegalArgumentException();
|
||||
}).run();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user