mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: support switch labels syntax (IDEA-226175)
GitOrigin-RevId: afdf87f8692f610ee87b9892c61f9ab97986bab8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
31b347b263
commit
f45758ac79
@@ -646,6 +646,13 @@ public class RedundantCastUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (parent instanceof PsiExpressionStatement &&
|
||||
operand instanceof PsiFunctionalExpression &&
|
||||
parent.getParent() instanceof PsiSwitchLabeledRuleStatement &&
|
||||
!castTo.equals(PsiTypesUtil.getExpectedTypeByParent(parent))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arrayAccessAtTheLeftSideOfAssignment(parent, typeCast)) {
|
||||
if (TypeConversionUtil.isAssignable(opType, castTo, false) && opType.getArrayDimensions() == castTo.getArrayDimensions()) {
|
||||
addToResults(typeCast);
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import java.util.function.Predicate;
|
||||
|
||||
class RedundantCast {
|
||||
private static void foo(final int matchType) {
|
||||
Object o = switch (matchType) {
|
||||
default -> (Predicate<Object>) target -> target == null;
|
||||
};
|
||||
}
|
||||
}
|
||||
+5
@@ -2,6 +2,7 @@
|
||||
package com.intellij.java.codeInsight.daemon
|
||||
|
||||
import com.intellij.JavaTestUtil
|
||||
import com.intellij.codeInspection.redundantCast.RedundantCastInspection
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
|
||||
class JavaSwitchExpressionsHighlightingTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
@@ -17,6 +18,10 @@ class JavaSwitchExpressionsHighlightingTest : LightJavaCodeInsightFixtureTestCas
|
||||
fun testEnhancedSwitchUnreachable() = doTest()
|
||||
fun testSwitchExpressionHasResult() = doTest()
|
||||
fun testYieldStatements() = doTest()
|
||||
fun testRedundantCastInSwitchBranch() {
|
||||
myFixture.enableInspections(RedundantCastInspection())
|
||||
doTest()
|
||||
}
|
||||
|
||||
private fun doTest() {
|
||||
myFixture.configureByFile("${getTestName(false)}.java")
|
||||
|
||||
Reference in New Issue
Block a user