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);
}
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();
}
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;
}
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);
}
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;
}
Aggregations