boolean (PsiElement element) { if (!(element instanceof PsiJavaToken token)) { return false; } final PsiElement parent = token.getParent(); if (!(parent instanceof PsiIfStatement ifStatement)) { return false; } final PsiElement nextStatement = PsiTreeUtil.skipWhitespacesForward(ifStatement); if (!(nextStatement instanceof PsiIfStatement nextIfStatement)) { return false; } if (ErrorUtil.containsError(ifStatement)) { return false; } if (ErrorUtil.containsError(nextIfStatement)) { return false; } if (!ifStatementsCanBeMerged(ifStatement, nextIfStatement)) { return false; } final PsiExpression condition = ifStatement.getCondition(); final Set<PsiVariable> variables = VariableAccessUtils.collectUsedVariables(condition); final PsiStatement thenBranch = ifStatement.getThenBranch(); if (VariableAccessUtils.isAnyVariableAssigned(variables, thenBranch)) { return false; } final PsiStatement elseBranch = ifStatement.getElseBranch(); return !VariableAccessUtils.isAnyVariableAssigned(variables, elseBranch); }