public static void replaceMapWithClass(Project project,
                                         final GrListOrMap map,
                                         PsiClass generatedClass,
                                         boolean replaceReturnType,
                                         boolean variableDeclaration,
                                         GrParameter parameter) {
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(generatedClass);

    final String text = map.getText();
    int begin = 0;
    int end = text.length();
    if (text.startsWith("[")) begin++;
    if (text.endsWith("]")) end--;
    final GrExpression newExpression = GroovyPsiElementFactory.getInstance(project)
      .createExpressionFromText("new " + generatedClass.getQualifiedName() + "(" + text.substring(begin, end) + ")");
    final GrExpression replacedNewExpression = ((GrExpression)map.replace(newExpression));

    if (replaceReturnType) {
      final PsiType type = replacedNewExpression.getType();
      final GrMethod method = PsiTreeUtil.getParentOfType(replacedNewExpression, GrMethod.class, true, GrClosableBlock.class);
      LOG.assertTrue(method != null);
      GrReferenceAdjuster.shortenAllReferencesIn(method.setReturnType(type));
    }

    if (variableDeclaration) {
      final PsiElement parent = PsiUtil.skipParentheses(replacedNewExpression.getParent(), true);
      ((GrVariable)parent).setType(replacedNewExpression.getType());
    }
    if (parameter != null) {
      parameter.setType(newExpression.getType());
    }

    JavaCodeStyleManager.getInstance(project).shortenClassReferences(replacedNewExpression);

    IntentionUtils.positionCursor(project, generatedClass.getContainingFile(), generatedClass);
  }
public static void replaceMapWithClass(Project project,
                                         final GrListOrMap map,
                                         PsiClass generatedClass,
                                         boolean replaceReturnType,
                                         boolean variableDeclaration,
                                         GrParameter parameter)