use of org.gradle.model.internal.inspect.ProjectionOnlyNodeInitializer 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;
}
Aggregations