void (final PsiLambdaExpression lambdaExpression, final PsiElementFactory psiElementFactory, final PsiCodeBlock blockFromText) { ChangeContextUtil.encodeContextInfo(blockFromText, true); final PsiClass thisClass = RefactoringChangeUtil.getThisClass(lambdaExpression); final String thisClassName = thisClass != null && !(thisClass instanceof PsiSyntheticClass) ? thisClass.getName() : null; if (thisClassName != null) { final PsiThisExpression thisAccessExpr = RefactoringChangeUtil.createThisExpression(lambdaExpression.getManager(), thisClass); ChangeContextUtil.decodeContextInfo(blockFromText, thisClass, thisAccessExpr); final Set<PsiExpression> replacements = new HashSet<>(); blockFromText.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitClass(@NotNull PsiClass aClass) {} @Override public void visitSuperExpression(@NotNull PsiSuperExpression expression) { super.visitSuperExpression(expression); if (expression.getQualifier() == null) { replacements.add(expression); } } @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); final PsiMethod psiMethod = expression.resolveMethod(); final PsiReferenceExpression methodExpression = expression.getMethodExpression(); if (psiMethod != null && !psiMethod.hasModifierProperty(PsiModifier.STATIC) && methodExpression.getQualifierExpression() == null) { replacements.add(expression); } } }); for (PsiExpression expression : replacements) { if (expression instanceof PsiSuperExpression) { expression.replace(psiElementFactory.createExpressionFromText(thisClassName + "." + expression.getText(), expression)); } else if (expression instanceof PsiMethodCallExpression) { ((PsiMethodCallExpression)expression).getMethodExpression().setQualifierExpression(thisAccessExpr); } else { LOG.error("Unexpected expression"); } } } }