void (PsiElement element) { Set<PsiLocalVariable> locals = new HashSet<>(); PsiTreeUtil.processElements(element, e -> { if (e instanceof PsiReferenceExpression) { PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable((PsiExpression)e); if (variable != null && variable.getInitializer() == null && PsiTreeUtil.isAncestor(myBlock, variable, true)) { locals.add(variable); } } return true; }); if (!locals.isEmpty()) { ControlFlow flow; try { flow = ControlFlowFactory.getControlFlow(myBlock, new LocalsControlFlowPolicy(myBlock), ControlFlowOptions.NO_CONST_EVALUATE); } catch (AnalysisCanceledException ignored) { return; } int offset = flow.getStartOffset(element); if (offset == -1) return; for (PsiLocalVariable local : locals) { if (ControlFlowUtil.getVariablePossiblyUnassignedOffsets(local, flow)[offset]) { local.setInitializer(myFactory.createExpressionFromText(PsiTypesUtil.getDefaultValueOfType(local.getType()), null)); } } } }