void (PsiClass sourceClass, final PsiElement ref, final PsiElementFactory factory, final PsiClass targetClass, final PsiElement toGet) { try { if (toGet.getCopyableUserData(REMOVE_QUALIFIER_KEY) != null) { toGet.putCopyableUserData(REMOVE_QUALIFIER_KEY, null); final PsiElement qualifier = ref instanceof PsiJavaCodeReferenceElement ? ((PsiJavaCodeReferenceElement)ref).getQualifier() : ref; if (qualifier != null) qualifier.delete(); } else { PsiClass psiClass = toGet.getCopyableUserData(REPLACE_QUALIFIER_KEY); if (psiClass != null) { toGet.putCopyableUserData(REPLACE_QUALIFIER_KEY, null); PsiElement qualifier = ref instanceof PsiJavaCodeReferenceElement ? ((PsiJavaCodeReferenceElement)ref).getQualifier() : ref; if (qualifier != null) { if (psiClass == sourceClass) { psiClass = targetClass; } else if (psiClass.getContainingClass() == sourceClass) { psiClass = targetClass.findInnerClassByName(psiClass.getName(), false); if (psiClass == null) { return; } } if (!(qualifier instanceof PsiThisExpression) && !(qualifier instanceof PsiSuperExpression) && ref instanceof PsiReferenceExpression) { ((PsiReferenceExpression)ref).setQualifierExpression(factory.createReferenceExpression(psiClass)); } else { if (qualifier instanceof PsiQualifiedExpression) { qualifier = ((PsiQualifiedExpression)qualifier).getQualifier(); } qualifier.replace(factory.createReferenceElementByType(factory.createType(psiClass))); } } } } } catch (IncorrectOperationException e) { LOG.error(e); } }