private static void makeArray(PsiVariable variable, PsiElement context) throws IncorrectOperationException {
    variable.normalizeDeclaration();
    PsiType type = variable.getType();

    PsiElementFactory factory = JavaPsiFacade.getElementFactory(context.getProject());
    PsiType newType = type.createArrayType();

    PsiDeclarationStatement variableDeclarationStatement;
    PsiExpression initializer = variable.getInitializer();
    PsiExpression init;
    if (initializer == null) {
      StringBuilder expression = new StringBuilder("[1]");
      while (type instanceof PsiArrayType) {
        expression.append("[1]");
        type = ((PsiArrayType) type).getComponentType();
      }
      init = factory.createExpressionFromText("new " + type.getCanonicalText() + expression, variable);
    }
    else {
      String explicitArrayDeclaration = JavaGenericsUtil.isReifiableType(type) ? "" : "new " + TypeConversionUtil.erasure(type).getCanonicalText() + "[]";
      init = factory.createExpressionFromText(explicitArrayDeclaration + "{ " + initializer.getText() + " }", variable);
    }
    variableDeclarationStatement = factory.createVariableDeclarationStatement(variable.getName(), newType, init);
    PsiVariable newVariable = (PsiVariable)variableDeclarationStatement.getDeclaredElements()[0];
    PsiUtil.setModifierProperty(newVariable, PsiModifier.FINAL, true);
    PsiElement newExpression = factory.createExpressionFromText(variable.getName() + "[0]", variable);

    PsiElement outerCodeBlock = PsiUtil.getVariableCodeBlock(variable, null);
    if (outerCodeBlock == null) return;
    List<PsiReferenceExpression> outerReferences = new ArrayList<>();
    collectReferences(outerCodeBlock, variable, outerReferences);
    replaceReferences(outerReferences, newExpression);
    variable.replace(newVariable);
  }
private static void makeArray(PsiVariable variable, PsiElement context)