Search in sources :

Example 1 with PropertyFluent

use of io.sundr.model.PropertyFluent in project sundrio by sundrio.

the class ApplyTypeParamMappingToProperty method visit.

@Override
public void visit(PropertyFluent<?> property) {
    TypeRef typeRef = property.buildTypeRef();
    if (typeRef instanceof TypeParamRef) {
        TypeParamRef typeParamRef = (TypeParamRef) typeRef;
        String key = typeParamRef.getName();
        TypeRef paramRef = mappings.get(key);
        if (paramRef != null) {
            property.withTypeRef(paramRef);
            attributeKey.ifPresent(k -> property.addToAttributes(k, typeParamRef));
        }
    } else if (typeRef instanceof ClassRef) {
        ClassRef classRef = (ClassRef) typeRef;
        if (classRef.getArguments().stream().anyMatch(a -> a instanceof TypeParamRef)) {
            List<TypeRef> mappedArguments = classRef.getArguments().stream().map(a -> a instanceof TypeParamRef ? mappings.getOrDefault(((TypeParamRef) a).getName(), a) : a).collect(Collectors.toList());
            property.withTypeRef(new ClassRefBuilder(classRef).withArguments(mappedArguments).build());
            attributeKey.ifPresent(k -> property.addToAttributes(k, classRef));
        }
    }
}
Also used : TypeParamRef(io.sundr.model.TypeParamRef) List(java.util.List) ClassRefBuilder(io.sundr.model.ClassRefBuilder) TypedVisitor(io.sundr.builder.TypedVisitor) PropertyFluent(io.sundr.model.PropertyFluent) Map(java.util.Map) TypeParamRef(io.sundr.model.TypeParamRef) Optional(java.util.Optional) TypeRef(io.sundr.model.TypeRef) Collectors(java.util.stream.Collectors) AttributeKey(io.sundr.model.AttributeKey) ClassRef(io.sundr.model.ClassRef) Maps(io.sundr.utils.Maps) ClassRef(io.sundr.model.ClassRef) TypeRef(io.sundr.model.TypeRef) ClassRefBuilder(io.sundr.model.ClassRefBuilder) List(java.util.List)

Aggregations

TypedVisitor (io.sundr.builder.TypedVisitor)1 AttributeKey (io.sundr.model.AttributeKey)1 ClassRef (io.sundr.model.ClassRef)1 ClassRefBuilder (io.sundr.model.ClassRefBuilder)1 PropertyFluent (io.sundr.model.PropertyFluent)1 TypeParamRef (io.sundr.model.TypeParamRef)1 TypeRef (io.sundr.model.TypeRef)1 Maps (io.sundr.utils.Maps)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1