Java: introduce another visitSwitchBlock() method

GitOrigin-RevId: 97f3edcab34837c124e1426d97a6d6590e67a053
This commit is contained in:
Bas Leijdekkers
2024-09-06 09:41:22 +02:00
committed by intellij-monorepo-bot
parent 7e0038ce14
commit 9eb3b6bb58

View File

@@ -213,27 +213,26 @@ public class EqualsWhichDoesntCheckParameterClassInspection extends BaseInspecti
@Override
public void visitSwitchExpression(@NotNull PsiSwitchExpression expression) {
super.visitSwitchExpression(expression);
if (isParameterReference(expression.getExpression()) && checksTypeOfExpression(expression)) {
makeChecked();
}
visitSwitchBlock(expression);
}
@Override
public void visitSwitchStatement(@NotNull PsiSwitchStatement statement) {
super.visitSwitchStatement(statement);
if (isParameterReference(statement.getExpression()) && checksTypeOfExpression(statement)) {
makeChecked();
}
visitSwitchBlock(statement);
}
private static boolean checksTypeOfExpression(@NotNull PsiSwitchBlock switchBlock) {
private void visitSwitchBlock(@NotNull PsiSwitchBlock switchBlock) {
if (!isParameterReference(switchBlock.getExpression())) return;
PsiCodeBlock body = switchBlock.getBody();
return body != null && PsiTreeUtil.getChildrenOfTypeAsList(body, PsiSwitchLabelStatementBase.class)
if (body == null) return;
boolean checksType = PsiTreeUtil.getChildrenOfTypeAsList(body, PsiSwitchLabelStatementBase.class)
.stream()
.map(PsiSwitchLabelStatementBase::getCaseLabelElementList)
.filter(Objects::nonNull)
.flatMap(list -> Arrays.stream(list.getElements()))
.anyMatch(element -> element instanceof PsiTypeTestPattern);
if (checksType) makeChecked();
}
@Override