void (@NotNull GrReferenceExpression refExpr, @NotNull PsiMember member, String name) { assert refExpr.getQualifierExpression() == null; final PsiClass clazz = member.getContainingClass(); assert clazz != null; if (member.hasModifierProperty(PsiModifier.STATIC)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getQualifiedName() + "." + name); refExpr.replace(newRefExpr); } else { final PsiClass containingClass = PsiTreeUtil.getParentOfType(refExpr, PsiClass.class); if (member.getManager().areElementsEquivalent(containingClass, clazz)) { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText("this." + name); refExpr.replace(newRefExpr); } else { final GrReferenceExpression newRefExpr = GroovyPsiElementFactory.getInstance(member.getProject()) .createReferenceExpressionFromText(clazz.getName() + ".this." + name); refExpr.replace(newRefExpr); } } }