private Source source(ModelDescription model, String name) { for (Source s : model.getPropertiesAsSources()) { if (name.equals(s.getName())) { return s; } } throw new AssertionError(name); }
private List<Source> sources(ModelDescription model, String... names) { List<Source> results = Lists.create(); Set<String> targets = Sets.create(); Collections.addAll(targets, names); for (Source s : model.getPropertiesAsSources()) { if (targets.contains(s.getName())) { results.add(s); } } return results; }
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)); }