Search in sources :

Example 1 with ModelElementProjection

use of org.gradle.model.internal.inspect.ModelElementProjection in project gradle by gradle.

the class ScalarCollectionNodeInitializerExtractionStrategy method extractNodeInitializer.

@Override
protected <T, E> NodeInitializer extractNodeInitializer(CollectionSchema<T, E> schema, NodeInitializerContext<T> context) {
    ModelType<T> type = schema.getType();
    Class<? super T> rawClass = type.getRawClass();
    ModelType<? super T> rawCollectionType = ModelType.of(rawClass);
    if (TYPES.contains(rawCollectionType) && (schema.getElementTypeSchema() instanceof ScalarValueSchema)) {
        Optional<NodeInitializerContext.PropertyContext> propertyContext = context.getPropertyContextOptional();
        boolean writable = !propertyContext.isPresent() || propertyContext.get().isWritable();
        if (schema.getType().getRawClass() == List.class) {
            return new ProjectionOnlyNodeInitializer(ScalarCollectionModelProjection.forList(schema.getElementType(), !writable), new ModelElementProjection(schema.getType()));
        } else {
            return new ProjectionOnlyNodeInitializer(ScalarCollectionModelProjection.forSet(schema.getElementType(), !writable), new ModelElementProjection(schema.getType()));
        }
    }
    return null;
}
Also used : ProjectionOnlyNodeInitializer(org.gradle.model.internal.inspect.ProjectionOnlyNodeInitializer) ModelElementProjection(org.gradle.model.internal.inspect.ModelElementProjection) ScalarValueSchema(org.gradle.model.internal.manage.schema.ScalarValueSchema)

Aggregations

ModelElementProjection (org.gradle.model.internal.inspect.ModelElementProjection)1 ProjectionOnlyNodeInitializer (org.gradle.model.internal.inspect.ProjectionOnlyNodeInitializer)1 ScalarValueSchema (org.gradle.model.internal.manage.schema.ScalarValueSchema)1