@NotNull
  public static <T extends PsiElement> T replaceVarReference(@NotNull T expressionOrCodeBlock,
                                                             @NotNull String name,
                                                             String replacement,
                                                             ChainContext context) {
    if (name.equals(replacement)) return expressionOrCodeBlock;
    PsiLambdaExpression lambda = (PsiLambdaExpression)context.createExpression(name + "->" + expressionOrCodeBlock.getText());
    PsiParameter var = lambda.getParameterList().getParameters()[0];
    PsiElement body = lambda.getBody();
    LOG.assertTrue(body != null);
    PsiExpression replacementExpression = context.createExpression(replacement);
    for (PsiReference ref : ReferencesSearch.search(var, new LocalSearchScope(body)).findAll()) {
      ref.getElement().replace(replacementExpression);
    }
    //noinspection unchecked
    return (T)lambda.getBody();
  }
@NotNull
  public static <T extends PsiElement> T replaceVarReference(@NotNull T expressionOrCodeBlock,
                                                             @NotNull String name,
                                                             String replacement,
                                                             ChainContext context)