@SuppressWarnings({ "unchecked", "rawtypes" }) private static <T, P extends PersistentProperty<P>> PreferredConstructor<T, P> buildPreferredConstructor( Constructor<?> constructor, TypeInformation<T> typeInformation, @Nullable PersistentEntity<T, P> entity) { List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor); if (parameterTypes.isEmpty()) { return new PreferredConstructor<>((Constructor<T>) constructor); } String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(constructor); Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()]; Annotation[][] parameterAnnotations = constructor.getParameterAnnotations(); for (int i = 0; i < parameterTypes.size(); i++) { String name = parameterNames == null ? null : parameterNames[i]; TypeInformation<?> type = parameterTypes.get(i); Annotation[] annotations = parameterAnnotations[i]; parameters[i] = new Parameter(name, type, annotations, entity); } return new PreferredConstructor<>((Constructor<T>) constructor, parameters); } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private PreferredConstructor<T, P> buildPreferredConstructor(Constructor<?> constructor, TypeInformation<T> typeInformation, PersistentEntity<T, P> entity) { List<TypeInformation<?>> parameterTypes = typeInformation.getParameterTypes(constructor); if (parameterTypes.isEmpty()) { return new PreferredConstructor<T, P>((Constructor<T>) constructor); } String[] parameterNames = nameDiscoverer.getParameterNames(constructor); Parameter<Object, P>[] parameters = new Parameter[parameterTypes.size()]; Annotation[][] parameterAnnotations = constructor.getParameterAnnotations(); for (int i = 0; i < parameterTypes.size(); i++) { String name = parameterNames == null ? null : parameterNames[i]; TypeInformation<?> type = parameterTypes.get(i); Annotation[] annotations = parameterAnnotations[i]; parameters[i] = new Parameter(name, type, annotations, entity); } return new PreferredConstructor<T, P>((Constructor<T>) constructor, parameters); }
private Property(TypeInformation<?> type, Optional<Field> field, Optional<PropertyDescriptor> descriptor) { Assert.notNull(type, "Type must not be null!"); Assert.isTrue(Optionals.isAnyPresent(field, descriptor), "Either field or descriptor has to be given!"); this.field = field; this.descriptor = descriptor; this.rawType = withFieldOrDescriptor( // it -> type.getRequiredProperty(it.getName()).getType(), // it -> type.getRequiredProperty(it.getName()).getType() // ); this.hashCode = Lazy.of(() -> withFieldOrDescriptor(Object::hashCode)); this.name = Lazy.of(() -> withFieldOrDescriptor(Field::getName, FeatureDescriptor::getName)); this.toString = Lazy.of(() -> withFieldOrDescriptor(Object::toString, it -> String.format("%s.%s", type.getType().getName(), it.getDisplayName()))); this.getter = descriptor.map(PropertyDescriptor::getReadMethod)// .filter(it -> getType() != null)// .filter(it -> getType().isAssignableFrom(type.getReturnType(it).getType())); this.setter = descriptor.map(PropertyDescriptor::getWriteMethod)// .filter(it -> getType() != null)// .filter(it -> type.getParameterTypes(it).get(0).getType().isAssignableFrom(getType())); this.wither = Lazy.of(() -> findWither(type, getName(), getType())); }