[java-highlighting] Use JavaPsiSwitchUtil.isBooleanSwitchWithTrueAndFalse

Part of IDEA-365344 Create a new Java error highlighter with minimal dependencies (PSI only)

GitOrigin-RevId: bde4078ac2d09977730c7803a3565c9bbe683a06
This commit is contained in:
Tagir Valeev
2025-02-27 16:13:31 +00:00
committed by intellij-monorepo-bot
parent a7bdd63a2e
commit b3b3fcf587
3 changed files with 20 additions and 23 deletions
@@ -315,9 +315,18 @@ public final class JavaPsiSwitchUtil {
return null;
}
public static boolean hasTrueAndFalse(@NotNull PsiSwitchBlock block) {
/**
* @param block block to check
* @return true if this switch block is a boolean switch that contains both true and false branches.
* All unrelated branches or duplicate branches are ignored.
*/
public static boolean isBooleanSwitchWithTrueAndFalse(@NotNull PsiSwitchBlock block) {
PsiCodeBlock body = block.getBody();
if (body == null) return false;
PsiExpression selector = block.getExpression();
if (selector == null) return false;
PsiType selectorType = selector.getType();
if (selectorType == null || getSwitchSelectorKind(selector.getType()) != SelectorKind.BOOLEAN) return false;
PsiConstantEvaluationHelper helper = JavaPsiFacade.getInstance(block.getProject()).getConstantEvaluationHelper();
boolean hasTrue = false, hasFalse = false;