private static String appendManagedCollections(
     StringBuffer s, int pad, Iterable<ModelType<?>> constructableTypes) {
   s.append(
       String.format(
           "A valid managed collection takes the form of ModelSet<T> or ModelMap<T> where 'T' is:%n        - %s",
           MANAGED_TYPE_DESCRIPTION));
   maybeAppendConstructables(s, constructableTypes, pad + 1);
   return s.toString();
 }
 private static void maybeAppendConstructables(
     StringBuffer s, Iterable<ModelType<?>> constructableTypes, int pad) {
   if (!Iterables.isEmpty(constructableTypes)) {
     String padding = pad(pad);
     s.append(String.format("%n%s- or a type which Gradle is capable of constructing:", padding));
     for (ModelType<?> modelType : constructableTypes) {
       s.append(String.format("%n    %s- %s", padding, modelType.getName()));
     }
   }
 }
 private static String toMessage(
     NodeInitializerContext context,
     ModelSchemaStore schemaStore,
     Iterable<ModelType<?>> scalarTypes,
     Iterable<ModelType<?>> constructableTypes) {
   Optional<ModelProperty<?>> modelPropertyOptional = context.getModelProperty();
   StringBuffer s = new StringBuffer();
   if (modelPropertyOptional.isPresent()) {
     s.append(
         String.format(
             "A model element of type: '%s' can not be constructed.%n",
             context.getContainingType().get().getName()));
     ModelProperty<?> modelProperty = modelPropertyOptional.get();
     if (isManagedCollection(modelProperty.getType())) {
       s.append(
           String.format(
               "Its property '%s %s' is not a valid managed collection%n",
               modelProperty.getType().getName(), modelProperty.getName()));
       ModelCollectionSchema<?, ?> schema =
           (ModelCollectionSchema) schemaStore.getSchema(modelProperty.getType());
       s.append(
           String.format("A managed collection can not contain '%s's%n", schema.getElementType()));
       appendManagedCollections(s, 1, constructableTypes);
     } else if (isScalarCollection(modelProperty.getType(), schemaStore)) {
       ModelCollectionSchema<?, ?> schema =
           (ModelCollectionSchema) schemaStore.getSchema(modelProperty.getType());
       s.append(
           String.format(
               "Its property '%s %s' is not a valid scalar collection%n",
               modelProperty.getType().getName(), modelProperty.getName()));
       s.append(
           String.format("A scalar collection can not contain '%s's%n", schema.getElementType()));
       s.append(explainScalarCollections(scalarTypes));
     } else {
       s.append(
           String.format(
               "Its property '%s %s' can not be constructed%n",
               modelProperty.getType().getName(), modelProperty.getName()));
       s.append(String.format("It must be one of:%n"));
       s.append(String.format("    - %s%n", MANAGED_TYPE_DESCRIPTION));
       s.append("    - A managed collection. ");
       appendManagedCollections(s, 1, constructableTypes);
       s.append(
           String.format(
               "%n    - A scalar collection. %s%n    - %s",
               explainScalarCollections(scalarTypes), UNMANAGED_PROPERTY_DESCRIPTION));
       maybeAppendConstructables(s, constructableTypes, 1);
     }
   } else {
     s.append(
         String.format(
             "A model element of type: '%s' can not be constructed.%n",
             context.getModelType().getName()));
     s.append(String.format("It must be one of:%n"));
     s.append(String.format("    - %s", MANAGED_TYPE_DESCRIPTION));
     maybeAppendConstructables(s, constructableTypes, 1);
   }
   return s.toString();
 }