void (@NotNull PsiReferenceExpression ref, @NotNull List<PsiExpression> sideEffects) { PsiElement element = ref.resolve(); if (!(element instanceof PsiMember member)) return; PsiClass containingClass = member.getContainingClass(); if (containingClass == null || containingClass instanceof PsiAnonymousClass) return; Project project = member.getProject(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiExpression qualifierExpression = ref.getQualifierExpression(); if (!sideEffects.isEmpty()) { Objects.requireNonNull(qualifierExpression); CodeBlockSurrounder surrounder = CodeBlockSurrounder.forExpression(ref); if (surrounder != null) { PsiStatement[] statements = StatementExtractor.generateStatements(sideEffects, qualifierExpression); CodeBlockSurrounder.SurroundResult result = surrounder.surround(); ref = (PsiReferenceExpression)result.getExpression(); qualifierExpression = ref.getQualifierExpression(); PsiStatement anchor = result.getAnchor(); if (statements.length > 0) { BlockUtils.addBefore(anchor, statements); } } } PsiElement newQualifier = factory.createReferenceExpression(containingClass); if (qualifierExpression != null) { newQualifier = qualifierExpression.replace(newQualifier); } else { ref.setQualifierExpression((PsiExpression)newQualifier); newQualifier = Objects.requireNonNull(ref.getQualifierExpression()); } PsiElement qualifiedWithClassName = ref.copy(); if (ref.getTypeParameters().length == 0 && !(containingClass.isInterface() && !containingClass.equals(PsiTreeUtil.getParentOfType(ref, PsiClass.class)))) { newQualifier.delete(); if (ref.resolve() != member) { ref.replace(qualifiedWithClassName); } } }