PsiExpression (PsiExpression expression, @NotNull TypeEvaluator evaluator) { String content = vararg ? getVarargText(expression) : expression.getText(); String text = "{".repeat(dimensions) + content + "}".repeat(dimensions); PsiElement parent = expression.getParent(); if (!(parent instanceof PsiVariable variable && variable.getType().equals(finalComponentType))) { text = "new " + finalComponentType.getCanonicalText() + "[]".repeat(dimensions) + text; } PsiExpression newExpression = JavaPsiFacade.getElementFactory(expression.getProject()).createExpressionFromText(text, expression); if (vararg) { PsiElement last = expression; PsiElement anchor = last.getNextSibling(); while (anchor != null && !PsiUtil.isJavaToken(anchor, JavaTokenType.RPARENTH)) { last = anchor; anchor = anchor.getNextSibling(); } parent.deleteChildRange(expression, last); return (PsiExpression)parent.add(newExpression); } else { return (PsiExpression)expression.replace(newExpression); } }