private AstSummarize generateTerm(ModelReference sourceModel, List<Source> group) {
    Map<String, ModelProperty> resolver = new HashMap<String, ModelProperty>();
    List<AstPropertyFolding> foldings = new ArrayList<AstPropertyFolding>();
    for (ModelProperty property : model.getProperties()) {
      Source source = property.getSource();
      assert source.getDeclaring().equals(sourceModel);
      resolver.put(source.getName(), property);
      foldings.add(
          new AstPropertyFolding(
              null,
              AstBuilder.getDesciption("{0}({1})", source.getAggregator().name(), source.getName()),
              Arrays.asList(
                  new AstAttribute[] {
                    AstBuilder.getOriginalName(property.getName()),
                  }),
              AstBuilder.toName(source.getAggregator()),
              AstBuilder.toName(source),
              AstBuilder.toName(property)));
    }

    List<AstSimpleName> grouping = new ArrayList<AstSimpleName>();
    for (Source source : group) {
      ModelProperty property = resolver.get(source.getName());
      assert property != null : source;
      grouping.add(AstBuilder.toName(property));
    }

    return new AstSummarize(
        null,
        new AstModelReference(null, AstBuilder.toName(sourceModel)),
        new AstModelFolding(null, foldings),
        grouping.isEmpty() ? null : new AstGrouping(null, grouping));
  }
 /**
  * Returns the corresponded DMDL model definition.
  *
  * @param model the thundergate model
  * @return the converted model
  * @throws IllegalArgumentException if some parameters were {@code null}
  */
 public static AstModelDefinition<AstSummarize> generate(SummarizedModelDescription model) {
   if (model == null) {
     throw new IllegalArgumentException("model must not be null"); // $NON-NLS-1$
   }
   return new AstModelDefinition<AstSummarize>(
       null,
       ModelDefinitionKind.SUMMARIZED,
       AstBuilder.getDesciption("{0}を集約したモデル", model.getOriginalModel().getSimpleName()),
       Arrays.asList(
           new AstAttribute[] {
             AstBuilder.getAutoProjection(),
             AstBuilder.getNamespace(AstBuilder.toDmdlName(Constants.SOURCE_VIEW)),
             AstBuilder.getOriginalName(model.getReference().getSimpleName()),
           }),
       AstBuilder.toName(model.getReference()),
       new SummarizedModelGenerator(model).generateExpression());
 }
 private AstSummarize generateExpression() {
   return generateTerm(model.getOriginalModel(), model.getGroupBy());
 }