Set<UExpression> (@NotNull UExpression body, @NotNull UElement context) { Queue<UExpression> workList = findDirectExpressions(body, context); Set<UExpression> processed = new HashSet<>(); Set<UExpression> leafs = new HashSet<>(); while (!workList.isEmpty() && processed.size() < MAX_EXPRESSIONS_TO_PROCESS) { UExpression next = workList.poll(); next = UastUtils.skipParenthesizedExprDown(next); if (!processed.add(next)) continue; if (next instanceof UIfExpression) { ContainerUtil.addIfNotNull(workList, ((UIfExpression)next).getThenExpression()); ContainerUtil.addIfNotNull(workList, ((UIfExpression)next).getElseExpression()); } else if (next instanceof UBlockExpression) { ContainerUtil.addIfNotNull(workList, ContainerUtil.getLastItem(((UBlockExpression)next).getExpressions())); } else if (next instanceof UReferenceExpression) { PsiElement psiVar = ((UReferenceExpression)next).resolve(); ULocalVariable uVar = UastContextKt.toUElement(psiVar, ULocalVariable.class); if (uVar != null) { ContainerUtil.addIfNotNull(workList, uVar.getUastInitializer()); PsiElement bodyPsi = body.getSourcePsi(); if (bodyPsi != null) { for (PsiReference ref : ReferencesSearch.search(psiVar, new LocalSearchScope(bodyPsi))) { UExpression lValue = UastContextKt.toUElement(ref.getElement(), UExpression.class); if (lValue != null) { UBinaryExpression parent = ObjectUtils.tryCast(lValue.getUastParent(), UBinaryExpression.class); if (parent != null && parent.getOperator() == UastBinaryOperator.ASSIGN && lValue.equals(parent.getLeftOperand())) { ContainerUtil.addIfNotNull(workList, parent.getRightOperand()); } } } } } } else if (next instanceof UCallExpression) { leafs.add(next); } } return leafs; }