boolean (@NotNull PsiLoopStatement loopStatement, @NotNull PsiIfStatement ifStatement, @Nullable PsiStatement branch) { if (branch == null) return false; Set<String> variablesCreatedInBranch = VariableAccessUtils.findDeclaredVariables(branch).stream() .map(PsiVariable::getName) .collect(Collectors.toSet()); Set<String> otherVariablesUsedInLoop = VariableAccessUtils.collectUsedVariables(loopStatement.getBody()).stream() .filter(variable -> !PsiTreeUtil.isAncestor(ifStatement, variable, false)) .map(PsiVariable::getName) .collect(Collectors.toSet()); return !Collections.disjoint(variablesCreatedInBranch, otherVariablesUsedInLoop); }