GrListOrMap (GrNamedArgument @NotNull [] args, Project project) { StringBuilder builder = new StringBuilder(); builder.append("["); Arrays.sort(args, (o1, o2) -> { final String l1 = o1.getLabelName(); final String l2 = o2.getLabelName(); assert l1 != null && l2 != null; return l1.compareTo(l2); }); for (GrNamedArgument arg : args) { builder.append(arg.getText()).append(",\n"); } builder.replace(builder.length() - 2, builder.length(), "]"); return (GrListOrMap)GroovyPsiElementFactory.getInstance(project).createExpressionFromText(builder); }