Search in sources :

Example 11 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class AvailabilityChangeEventTests method getResolvableType.

@Test
void getResolvableType() {
    LivenessState state = LivenessState.CORRECT;
    AvailabilityChangeEvent<LivenessState> event = new AvailabilityChangeEvent<>(this.source, state);
    ResolvableType type = event.getResolvableType();
    assertThat(type.resolve()).isEqualTo(AvailabilityChangeEvent.class);
    assertThat(type.resolveGeneric()).isEqualTo(LivenessState.class);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 12 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class RootBeanDefinition method getResolvableType.

/**
 * Return a {@link ResolvableType} for this bean definition,
 * either from runtime-cached type information or from configuration-time
 * {@link #setTargetType(ResolvableType)} or {@link #setBeanClass(Class)},
 * also considering resolved factory method definitions.
 *
 * @see #setTargetType(ResolvableType)
 * @see #setBeanClass(Class)
 * @see #setResolvedFactoryMethod(Method)
 */
public ResolvableType getResolvableType() {
    ResolvableType targetType = this.targetType;
    if (targetType != null) {
        return targetType;
    }
    ResolvableType returnType = this.factoryMethodReturnType;
    if (returnType != null) {
        return returnType;
    }
    Method factoryMethod = this.factoryMethodToIntrospect;
    if (factoryMethod != null) {
        return ResolvableType.forReturnType(factoryMethod);
    }
    return super.getResolvableType();
}
Also used : Method(java.lang.reflect.Method) ResolvableType(cn.taketoday.core.ResolvableType)

Example 13 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class CollectionBinder method bindAggregate.

@Override
protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> target, AggregateElementBinder elementBinder) {
    Class<?> collectionType = target.getValue() != null ? List.class : target.getType().resolve(Object.class);
    ResolvableType aggregateType = ResolvableType.fromClassWithGenerics(List.class, target.getType().asCollection().getGenerics());
    ResolvableType elementType = target.getType().asCollection().getGeneric();
    IndexedCollectionSupplier result = new IndexedCollectionSupplier(() -> CollectionUtils.createCollection(collectionType, elementType.resolve(), 0));
    bindIndexed(name, target, elementBinder, aggregateType, elementType, result);
    if (result.wasSupplied()) {
        return result.get();
    }
    return null;
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType)

Example 14 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Bindable method of.

/**
 * Create a new {@link Bindable} of the specified type.
 *
 * @param <T> the source type
 * @param type the type (must not be {@code null})
 * @return a {@link Bindable} instance
 * @see #of(Class)
 */
public static <T> Bindable<T> of(ResolvableType type) {
    Assert.notNull(type, "Type must not be null");
    ResolvableType boxedType = box(type);
    return new Bindable<>(type, boxedType, null, Constant.EMPTY_ANNOTATION_ARRAY, NO_BIND_RESTRICTIONS);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType)

Example 15 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class JavaBeanBinder method bind.

private <T> boolean bind(BeanSupplier<T> beanSupplier, DataObjectPropertyBinder propertyBinder, BeanProperty property) {
    String propertyName = property.getName();
    ResolvableType type = property.getType();
    Supplier<Object> value = property.getValue(beanSupplier);
    Annotation[] annotations = property.getAnnotations();
    Object bound = propertyBinder.bindProperty(propertyName, Bindable.of(type).withSuppliedValue(value).withAnnotations(annotations));
    if (bound == null) {
        return false;
    }
    if (property.isSettable()) {
        property.setValue(beanSupplier, bound);
    } else if (value == null || !bound.equals(value.get())) {
        throw new IllegalStateException("No setter found for property: " + property.getName());
    }
    return true;
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Annotation(java.lang.annotation.Annotation)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)159 Test (org.junit.jupiter.api.Test)106 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)30 Map (java.util.Map)24 Pojo (cn.taketoday.http.codec.Pojo)20 List (java.util.List)16 MediaType (cn.taketoday.http.MediaType)15 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)14 Flux (reactor.core.publisher.Flux)12 Mono (reactor.core.publisher.Mono)10 Resource (cn.taketoday.core.io.Resource)8 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 MultiValueMap (cn.taketoday.core.MultiValueMap)6 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)6 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)6 MimeType (cn.taketoday.util.MimeType)6 Arrays (java.util.Arrays)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5