void (@NotNull PsiType type, @NotNull PsiArrayInitializerExpression initializer) { Project project = initializer.getProject(); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); @NonNls String text = "new " + type.getCanonicalText() + "[]{}"; PsiNewExpression newExpr = (PsiNewExpression) factory.createExpressionFromText(text, null); Objects.requireNonNull(newExpr.getArrayInitializer()).replace(initializer); newExpr = (PsiNewExpression) CodeStyleManager.getInstance(project).reformat(newExpr); initializer.replace(newExpr); }