use of org.gradle.model.internal.manage.schema.extract.ModelSchemaAspectExtractionResult in project gradle by gradle.
the class VariantAspectExtractionStrategy method extract.
@Nullable
@Override
public ModelSchemaAspectExtractionResult extract(ModelSchemaExtractionContext<?> extractionContext, final List<ModelPropertyExtractionResult<?>> propertyResults) {
ImmutableSet.Builder<ModelProperty<?>> dimensionsBuilder = ImmutableSet.builder();
for (ModelPropertyExtractionResult<?> propertyResult : propertyResults) {
ModelProperty<?> property = propertyResult.getProperty();
for (PropertyAccessorExtractionContext accessor : propertyResult.getAccessors()) {
if (accessor.isAnnotationPresent(Variant.class)) {
if (accessor.getAccessorType() == PropertyAccessorType.SETTER) {
throw invalidProperty(extractionContext, property, "@Variant annotation is only allowed on getter methods");
}
Class<?> propertyType = property.getType().getRawClass();
if (!String.class.equals(propertyType) && !Named.class.isAssignableFrom(propertyType)) {
throw invalidProperty(extractionContext, property, String.format("@Variant annotation only allowed for properties of type String and %s, but property has type %s", Named.class.getName(), propertyType.getName()));
}
dimensionsBuilder.add(property);
}
}
}
ImmutableSet<ModelProperty<?>> dimensions = dimensionsBuilder.build();
if (dimensions.isEmpty()) {
return null;
}
return new ModelSchemaAspectExtractionResult(new VariantAspect(dimensions));
}
Aggregations