boolean (PsiSwitchBlock switchBlock) { final Collection<PsiReferenceExpression> expressions = PsiTreeUtil.findChildrenOfType(switchBlock, PsiReferenceExpression.class); final Set<PsiElement> checked = new HashSet<>(); for (PsiReferenceExpression expression : expressions) { final PsiElement parent = PsiTreeUtil.skipParentsOfType(expression, PsiParenthesizedExpression.class); if (!(parent instanceof PsiAssignmentExpression assignmentExpression)) { continue; } if (JavaTokenType.EQ != assignmentExpression.getOperationTokenType()) { continue; } if (!PsiTreeUtil.isAncestor(assignmentExpression.getLExpression(), expression, false)) { continue; } final PsiElement target = expression.resolve(); if (target != null && !checked.add(target)) { continue; } if (target instanceof PsiLocalVariable || target instanceof PsiField && ((PsiField)target).hasModifierProperty(PsiModifier.FINAL)) { final PsiVariable variable = (PsiVariable)target; if (variable.getInitializer() != null) { continue; } final PsiElement context = getContext(switchBlock); if (context == null) { return true; } try { final LocalsOrMyInstanceFieldsControlFlowPolicy policy = LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance(); final ControlFlow controlFlow = ControlFlowFactory.getInstance(context.getProject()).getControlFlow(context, policy); final int switchStart = controlFlow.getStartOffset(switchBlock); final int switchEnd = controlFlow.getEndOffset(switchBlock); final ControlFlow beforeFlow = new ControlFlowSubRange(controlFlow, 0, switchStart); final ControlFlow switchFlow = new ControlFlowSubRange(controlFlow, switchStart, switchEnd); if (!ControlFlowUtil.isVariableDefinitelyAssigned(variable, beforeFlow) && ControlFlowUtil.isVariableDefinitelyAssigned(variable, switchFlow) && ControlFlowUtil.needVariableValueAt(variable, controlFlow, switchEnd)) { return true; } } catch (AnalysisCanceledException e) { return true; } } } return false; }