コード例 #1
0
 @Override
 public Map<String, Model> dependencies(ModelContext modelContext) {
   Map<String, Model> models = newHashMap();
   for (ResolvedType resolvedType : dependencyProvider.dependentModels(modelContext)) {
     ModelContext parentContext = ModelContext.fromParent(modelContext, resolvedType);
     Optional<Model> model = modelFor(parentContext).or(mapModel(parentContext, resolvedType));
     if (model.isPresent()) {
       models.put(model.get().getName(), model.get());
     }
   }
   return models;
 }
コード例 #2
0
  @Override
  public com.google.common.base.Optional<Model> modelFor(ModelContext modelContext) {
    ResolvedType propertiesHost = modelContext.alternateFor(modelContext.resolvedType(resolver));
    if (isContainerType(propertiesHost)
        || isMapType(propertiesHost)
        || propertiesHost.getErasedType().isEnum()
        || isBaseType(Types.typeNameFor(propertiesHost.getErasedType()))
        || modelContext.hasSeenBefore(propertiesHost)) {
      LOG.debug(
          "Skipping model of type {} as its either a container type, map, enum or base type, or its already "
              + "been handled",
          resolvedTypeSignature(propertiesHost).or("<null>"));
      return Optional.absent();
    }
    ImmutableMap<String, ModelProperty> propertiesIndex =
        uniqueIndex(properties(modelContext, propertiesHost), byPropertyName());
    LOG.debug(
        "Inferred {} properties. Properties found {}",
        propertiesIndex.size(),
        Joiner.on(", ").join(propertiesIndex.keySet()));

    SortedSet<Map.Entry<String, ModelProperty>> sortedProperties =
        new TreeSet<Map.Entry<String, ModelProperty>>(
            new Comparator<Map.Entry<String, ModelProperty>>() {
              @Override
              public int compare(
                  Map.Entry<String, ModelProperty> e1, Map.Entry<String, ModelProperty> e2) {
                if ((e1.getValue().getPosition().compareTo(e2.getValue().getPosition()) == 0)) {
                  return e1.getValue().getName().compareTo(e2.getValue().getName());
                }
                return new Integer(e1.getValue().getPosition())
                    .compareTo(e2.getValue().getPosition());
              }
            });

    sortedProperties.addAll(propertiesIndex.entrySet());

    Map<String, ModelProperty> properties = new LinkedHashMap<String, ModelProperty>();

    // Map<String, ModelProperty> properties = newTreeMap();
    // properties.putAll(propertiesIndex);
    for (Map.Entry<String, ModelProperty> value : sortedProperties) {
      properties.put(value.getKey(), value.getValue());
    }
    return Optional.of(modelBuilder(propertiesHost, properties, modelContext));
  }