@Override
 protected ModelPath calculateTarget(MutableModelNode target) {
   if (targetProperty != null) {
     return ((ManagedInstance) values.get(targetProperty.getName())).getBackingNode().getPath();
   }
   return target.getPath();
 }
 @Override
 public ModelView<List<T>> toView(
     MutableModelNode modelNode, ModelRuleDescriptor ruleDescriptor, boolean writable) {
   ModelType<List<T>> listType = ModelTypes.list(elementType);
   DefaultModelViewState state =
       new DefaultModelViewState(listType, ruleDescriptor, writable, !writable);
   ListBackedCollection<T> list = new ListBackedCollection<T>(modelNode, state, elementType);
   return InstanceModelView.of(modelNode.getPath(), listType, list, state.closer());
 }
 private void addPropertyLinks(
     MutableModelNode modelNode,
     ModelSchemaStore schemaStore,
     NodeInitializerRegistry nodeInitializerRegistry) {
   for (ManagedProperty<?> property : bindings.getManagedProperties().values()) {
     addPropertyLink(modelNode, property, schemaStore, nodeInitializerRegistry);
   }
   if (isNamedType()) {
     // Only initialize "name" child node if the schema has such a managed property.
     // This is not the case for a managed subtype of an unmanaged type that implements Named.
     if (bindings.getManagedProperties().containsKey("name")) {
       MutableModelNode nameLink = modelNode.getLink("name");
       if (nameLink == null) {
         throw new IllegalStateException("expected name node for " + modelNode.getPath());
       }
       nameLink.setPrivateData(ModelType.of(String.class), modelNode.getPath().getName());
     }
   }
 }
  private <P> void addPropertyLink(
      MutableModelNode modelNode,
      ManagedProperty<P> property,
      ModelSchemaStore schemaStore,
      NodeInitializerRegistry nodeInitializerRegistry) {
    ModelType<P> propertyType = property.getType();
    ModelSchema<P> propertySchema = schemaStore.getSchema(propertyType);
    ModelType<T> publicType = bindings.getPublicSchema().getType();

    validateProperty(propertySchema, property, nodeInitializerRegistry);

    ModelPath childPath = modelNode.getPath().child(property.getName());
    if (propertySchema instanceof ManagedImplSchema) {
      if (!property.isWritable()) {
        ModelRegistrations.Builder builder =
            managedRegistrationBuilder(childPath, property, nodeInitializerRegistry, publicType);
        addLink(modelNode, builder, property.isInternal());
      } else {
        if (propertySchema instanceof ScalarCollectionSchema) {
          ModelRegistrations.Builder builder =
              managedRegistrationBuilder(childPath, property, nodeInitializerRegistry, publicType);
          addLink(modelNode, builder, property.isInternal());
        } else {
          modelNode.addReference(property.getName(), propertyType, modelNode.getDescriptor());
        }
      }
    } else {
      ModelRegistrations.Builder registrationBuilder;
      if (shouldHaveANodeInitializer(property, propertySchema)) {
        registrationBuilder =
            managedRegistrationBuilder(childPath, property, nodeInitializerRegistry, publicType);
      } else {
        registrationBuilder = ModelRegistrations.of(childPath);
      }
      registrationBuilder.withProjection(new UnmanagedModelProjection<P>(propertyType));
      addLink(modelNode, registrationBuilder, property.isInternal());
    }
  }
 protected ModelPath calculateTarget(MutableModelNode target) {
   return target.getPath();
 }