26
26
27
27
import org .springframework .data .util .Lazy ;
28
28
import org .springframework .data .util .Optionals ;
29
+ import org .springframework .data .util .TypeInformation ;
29
30
import org .springframework .lang .Nullable ;
30
31
import org .springframework .util .Assert ;
31
32
@@ -49,68 +50,75 @@ public class Property {
49
50
private final Lazy <String > name ;
50
51
private final Lazy <String > toString ;
51
52
52
- private Property (Optional <Field > field , Optional <PropertyDescriptor > descriptor ) {
53
+ private Property (TypeInformation <?> type , Optional <Field > field , Optional <PropertyDescriptor > descriptor ) {
53
54
55
+ Assert .notNull (type , "Type must not be null!" );
54
56
Assert .isTrue (Optionals .isAnyPresent (field , descriptor ), "Either field or descriptor has to be given!" );
55
57
56
58
this .field = field ;
57
59
this .descriptor = descriptor ;
58
60
59
- this .rawType = withFieldOrDescriptor (Field ::getType , PropertyDescriptor ::getPropertyType );
61
+ this .rawType = withFieldOrDescriptor ( //
62
+ it -> type .getRequiredProperty (it .getName ()).getType (), //
63
+ it -> type .getRequiredProperty (it .getName ()).getType () //
64
+ );
60
65
this .hashCode = Lazy .of (() -> withFieldOrDescriptor (Object ::hashCode ));
61
66
this .name = Lazy .of (() -> withFieldOrDescriptor (Field ::getName , FeatureDescriptor ::getName ));
62
67
this .toString = Lazy .of (() -> withFieldOrDescriptor (Object ::toString ));
63
68
64
69
this .getter = descriptor .map (PropertyDescriptor ::getReadMethod )//
65
70
.filter (it -> getType () != null )//
66
- .filter (it -> getType ().isAssignableFrom (it .getReturnType ()));
71
+ .filter (it -> getType ().isAssignableFrom (type .getReturnType ( it ). getType ()));
67
72
68
73
this .setter = descriptor .map (PropertyDescriptor ::getWriteMethod )//
69
74
.filter (it -> getType () != null )//
70
- .filter (it -> it .getParameterTypes ()[ 0 ] .isAssignableFrom (getType ()));
75
+ .filter (it -> type .getParameterTypes (it ). get ( 0 ). getType () .isAssignableFrom (getType ()));
71
76
}
72
77
73
78
/**
74
79
* Creates a new {@link Property} backed by the given field.
75
80
*
81
+ * @param type the owning type, must not be {@literal null}.
76
82
* @param field must not be {@literal null}.
77
83
* @return
78
84
*/
79
- public static Property of (Field field ) {
85
+ public static Property of (TypeInformation <?> type , Field field ) {
80
86
81
87
Assert .notNull (field , "Field must not be null!" );
82
88
83
- return new Property (Optional .of (field ), Optional .empty ());
89
+ return new Property (type , Optional .of (field ), Optional .empty ());
84
90
}
85
91
86
92
/**
87
93
* Creates a new {@link Property} backed by the given {@link Field} and {@link PropertyDescriptor}.
88
94
*
95
+ * @param type the owning type, must not be {@literal null}.
89
96
* @param field must not be {@literal null}.
90
97
* @param descriptor must not be {@literal null}.
91
98
* @return
92
99
*/
93
- public static Property of (Field field , PropertyDescriptor descriptor ) {
100
+ public static Property of (TypeInformation <?> type , Field field , PropertyDescriptor descriptor ) {
94
101
95
102
Assert .notNull (field , "Field must not be null!" );
96
103
Assert .notNull (descriptor , "PropertyDescriptor must not be null!" );
97
104
98
- return new Property (Optional .of (field ), Optional .of (descriptor ));
105
+ return new Property (type , Optional .of (field ), Optional .of (descriptor ));
99
106
}
100
107
101
108
/**
102
109
* Creates a new {@link Property} for the given {@link PropertyDescriptor}. The creation might fail if the given
103
110
* property is not representing a proper property.
104
111
*
112
+ * @param type the owning type, must not be {@literal null}.
105
113
* @param descriptor must not be {@literal null}.
106
114
* @return
107
115
* @see #supportsStandalone(PropertyDescriptor)
108
116
*/
109
- public static Property of (PropertyDescriptor descriptor ) {
117
+ public static Property of (TypeInformation <?> type , PropertyDescriptor descriptor ) {
110
118
111
119
Assert .notNull (descriptor , "PropertyDescriptor must not be null!" );
112
120
113
- return new Property (Optional .empty (), Optional .of (descriptor ));
121
+ return new Property (type , Optional .empty (), Optional .of (descriptor ));
114
122
}
115
123
116
124
/**
0 commit comments