PsiExpression (final PsiExpression expression) { final PsiManager manager = expression.getManager(); if (ExpressionUtils.isReferenceTo(expression, myTargetVariable)) { return createThisExpr(manager); } expression.accept(new JavaRecursiveElementVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); if (expression.isReferenceTo(myTargetVariable)) { try { expression.replace(createThisExpr(manager)); } catch (IncorrectOperationException e) { LOG.error(e); } } } }); return expression; }