List<PsiVariable> (@NotNull PsiExpression expression) { final ControlFlow controlFlow; try { controlFlow = ControlFlowFactory.getControlFlow(expression, new MyControlFlowPolicy(expression), ControlFlowOptions.NO_CONST_EVALUATE); } catch (AnalysisCanceledException e) { return null; } Collection<PsiVariable> writtenVariables = ControlFlowUtil.getWrittenVariables(controlFlow, 0, controlFlow.getSize(), false); if (!writtenVariables.isEmpty()) return null; return ContainerUtil .filter(ControlFlowUtil.getUsedVariables(controlFlow, 0, controlFlow.getSize()), v -> !v.hasModifierProperty(PsiModifier.FINAL)); }