public static PsiExpression inlineInitializer(PsiVariable variable, PsiExpression initializer, PsiJavaCodeReferenceElement ref) {
    Project project = variable.getProject();
    PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
    if (initializer instanceof PsiThisExpression && ((PsiThisExpression)initializer).getQualifier() == null) {
      final PsiClass varThisClass = RefactoringChangeUtil.getThisClass(variable);
      if (varThisClass != null && varThisClass != RefactoringChangeUtil.getThisClass(ref)) {
        initializer = factory.createExpressionFromText(varThisClass.getName() + ".this", variable);
      }
    }

    PsiExpression expr = inlineVariable(variable, initializer, ref);

    CommonJavaRefactoringUtil.tryToInlineArrayCreationForVarargs(expr);

    //Q: move the following code to some util? (addition to inline?)
    if (expr instanceof PsiThisExpression && expr.getParent() instanceof PsiReferenceExpression refExpr) {
      PsiElement refElement = refExpr.resolve();
      PsiExpression exprCopy = (PsiExpression)refExpr.copy();
      refExpr = (PsiReferenceExpression)refExpr.replace(factory.createExpressionFromText(
        Objects.requireNonNull(refExpr.getReferenceName()), null));
      if (refElement != null) {
        PsiElement newRefElement = refExpr.resolve();
        if (!refElement.equals(newRefElement)) {
          // change back
          refExpr.replace(exprCopy);
        }
      }
    }

    if (expr instanceof PsiLiteralExpression && PsiTypes.booleanType().equals(expr.getType())) {
      Boolean value = tryCast(((PsiLiteralExpression)expr).getValue(), Boolean.class);
      if (value != null) {
        SimplifyBooleanExpressionFix.trySimplify(expr, value);
      }
    }
    return initializer;
  }
public static PsiExpression inlineInitializer(PsiVariable variable, PsiExpression initializer, PsiJavaCodeReferenceElement ref)