void (PsiElement context, final PsiVariable variable, final PsiElement newExpression) { context.accept(new JavaRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { if (expression.resolve() == variable) try { expression.replace(newExpression); } catch (IncorrectOperationException e) { LOG.error(e); } super.visitReferenceExpression(expression); } }); }