private <P> boolean isValidSetter(final Field field, Method method, final Class<P> clazz) { final Class<?>[] params = method.getParameterTypes(); final Class<?> returnType = method.getReturnType(); return params.length == 1 && (returnType.equals(Void.TYPE) || clazz.isAssignableFrom(returnType) ) && (params[0].isAssignableFrom(field.getType()) || isOptional(params[0]) && getGenericClass(method.getGenericParameterTypes()[0]).isAssignableFrom(field.getType())); }
private boolean isValidGetter(Field field, Method method) { return method.getParameterTypes().length == 0 && ( field.getType().isAssignableFrom(method.getReturnType()) || isOptional(method.getReturnType()) && field.getType().isAssignableFrom(getGenericClass(method.getGenericReturnType()))); }
private <P> PropertyWrapper<Field, ?, P> buildPropertyFieldWrapper(Field accessor) { if (isOptional(accessor.getType())) { return new PropertyWrapperDefault<>(Optional.ofNullable(accessor), OptionalValueProcessor.build()); } return new PropertyWrapperDefault<>(Optional.ofNullable(accessor), NoOpsValueProcessor.build()); }
private <P> PropertyWrapper<Method, ?, P> getSetter(final Field field, final List<Method> methods, final Class<BEAN> clazz) { Method setter = null; String setterName = ""; final List<String> validNames = Arrays.asList( FieldDefaultNaming.getDefaultSetterName(field.getName()), FieldDefaultNaming.getDefaultWitherName(field.getName()), field.getName() ); for (final Method method : methods) { if (validNames.contains(method.getName()) && isValidSetter(field, method, clazz)) { setter = method; setterName = method.getName(); break; } } this.logger.debug("setter for property [" + field.getName() + "]: [" + setterName + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ final Optional<Method> optionalSetter = Optional.ofNullable(setter); if (optionalSetter.isPresent() && isOptional(optionalSetter.get().getParameterTypes()[0])) { return new PropertyWrapperDefault<>(optionalSetter, OptionalValueProcessor.build()); } return new PropertyWrapperDefault<>(optionalSetter, NoOpsValueProcessor.build()); }
private <P> PropertyWrapper<Method, ?, P> getGetter(final Field field, final List<Method> methods) { Method getter = null; String getterName = ""; final List<String> validNames = Arrays.asList( FieldDefaultNaming.getDefaultGetterName(field.getName()), FieldDefaultNaming.getDefaultBooleanGetterName(field.getName()), field.getName() ); for (final Method method : methods) { if (validNames.contains(method.getName()) && isValidGetter(field, method)) { getter = method; getterName = method.getName(); break; } } this.logger.debug("getter for property [" + field.getName() + "]: [" + getterName + "]"); final Optional<Method> optionalGetter = Optional.ofNullable(getter); if (optionalGetter.isPresent() && isOptional(optionalGetter.get().getReturnType())) { return new PropertyWrapperDefault<>(optionalGetter, OptionalValueProcessor.build()); } return new PropertyWrapperDefault<>(optionalGetter, NoOpsValueProcessor.build()); }
private <P> FieldDescriptorImpl<BEAN, P> buildClassField(final ClassDescriptorImpl<BEAN> classMap, final Field field, final List<Method> methods, final Class<P> fieldClass) { final Class<?> realClass = field.getType(); Class<P> processedClass = (Class<P>) field.getType(); // In future this should be more generic. Not required at the moment if (isOptional(realClass)) { processedClass = getGenericClass(field.getGenericType()); } final FieldDescriptorImpl<BEAN, P> classField = new FieldDescriptorImpl<>(field.getName(), processedClass, buildPropertyFieldWrapper(field), getGetter(field, methods), getSetter(field, methods, classMap.getMappedClass()) ); setIgnored(classField); setColumnInfo(classField); setIdentifier(classField); setGeneratorInfo(classField); setVersionInfo(classField); setJsonInfo(classField); this.logger.debug("DB column [" + classField.getColumnInfo().getDBColumnName() + "]" + " will be associated with object field [" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + classField.getFieldName() + "]"); //$NON-NLS-1$ return classField; }