String (@NotNull PsiExpression expression, @NotNull String varName, @NotNull PsiVariable exprVariable) { PsiExpression copy = (PsiExpression)expression.copy(); ReferencesSearch.search(exprVariable, new LocalSearchScope(copy)) .forEach(reference ->{ PsiReferenceExpression ref = tryCast(reference.getElement(), PsiReferenceExpression.class); if(ref == null) return; ExpressionUtils.bindReferenceTo(ref, varName); }); return copy.getText(); }