boolean (PsiExpression expression, PsiExpression switchExpression, LanguageLevel languageLevel, Set<Object> existingCaseValues, boolean isPatternMatch) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (isPatternMatch) { if (canBePatternSwitchCase(expression, switchExpression)) { final PsiCaseLabelElement pattern = createPatternFromExpression(expression); if (pattern == null) return true; for (Object caseValue : existingCaseValues) { if (caseValue instanceof PsiPattern && JavaPsiPatternUtil.dominates((PsiPattern) caseValue, pattern)) { return false; } } existingCaseValues.add(pattern); return true; } else { return false; } } if (languageLevel.isAtLeast(LanguageLevel.JDK_1_7)) { final PsiExpression stringSwitchExpression = determinePossibleJdk17SwitchExpression(expression, existingCaseValues); if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(switchExpression, stringSwitchExpression)) { return true; } } final EqualityCheck check = EqualityCheck.from(expression); if (check != null) { final PsiExpression left = check.getLeft(); final PsiExpression right = check.getRight(); if (canBeCaseLabel(left, languageLevel, null)) { return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(switchExpression, right); } else if (canBeCaseLabel(right, languageLevel, null)) { return EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(switchExpression, left); } } if (!(expression instanceof PsiPolyadicExpression polyadicExpression)) { return false; } final IElementType operation = polyadicExpression.getOperationTokenType(); final PsiExpression[] operands = polyadicExpression.getOperands(); if (operation.equals(JavaTokenType.OROR)) { for (PsiExpression operand : operands) { if (!canBeSwitchCase(operand, switchExpression, languageLevel, existingCaseValues, false)) { return false; } } return true; } else if (operation.equals(JavaTokenType.EQEQ) && operands.length == 2) { return (canBeCaseLabel(operands[0], languageLevel, existingCaseValues) && EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(switchExpression, operands[1])) || (canBeCaseLabel(operands[1], languageLevel, existingCaseValues) && EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(switchExpression, operands[0])); } else { return false; } }