5252 */
5353class TypedPropertyPaths {
5454
55- private static final Map <ClassLoader , Map <Object , PropertyPathMetadata >> lambdas = new WeakHashMap <>();
5655 private static final Map <ClassLoader , Map <Serializable , ResolvedTypedPropertyPath <?, ?>>> resolved = new WeakHashMap <>();
5756
5857 private static final SerializableLambdaReader reader = new SerializableLambdaReader (PropertyPath .class ,
@@ -125,7 +124,7 @@ public static <P, T> TypedPropertyPath<T, P> of(PropertyReference<T, P> lambda)
125124 return new PropertyReferenceWrapper <>(resolved );
126125 }
127126
128- PropertyPathMetadata metadata = getMetadata (lambda );
127+ PropertyPathMetadata metadata = read (lambda );
129128
130129 if (KotlinDetector .isKotlinReflectPresent ()) {
131130 if (metadata instanceof KPropertyPathMetadata kMetadata
@@ -137,45 +136,6 @@ public static <P, T> TypedPropertyPath<T, P> of(PropertyReference<T, P> lambda)
137136 return new ResolvedPropertyReference <>(lambda , metadata );
138137 }
139138
140- /**
141- * Delegate to handle property path composition of single-property and property-path KProperty1 references.
142- */
143- static class KotlinDelegate {
144-
145- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
146- public static <T , P > TypedPropertyPath <T , P > of (Object property ) {
147-
148- if (property instanceof KPropertyPath paths ) {
149-
150- TypedPropertyPath parent = of (paths .getProperty ());
151- TypedPropertyPath child = of (paths .getLeaf ());
152-
153- return TypedPropertyPaths .compose (parent , child );
154- }
155-
156- if (property instanceof KPropertyImpl impl ) {
157-
158- Class <?> owner = impl .getJavaField () != null ? impl .getJavaField ().getDeclaringClass ()
159- : impl .getGetter ().getCaller ().getMember ().getDeclaringClass ();
160- KPropertyPathMetadata metadata = TypedPropertyPaths .KPropertyPathMetadata
161- .of (MemberDescriptor .KPropertyReferenceDescriptor .create (owner , (KProperty1 ) impl ));
162- return new TypedPropertyPaths .ResolvedKPropertyPath (metadata );
163- }
164-
165- if (property instanceof KProperty1 kProperty ) {
166-
167- if (kProperty .getGetter ().getProperty () instanceof KProperty1Impl impl ) {
168- return of (impl );
169- }
170-
171- throw new IllegalArgumentException ("Property " + kProperty .getName () + " is not a KProperty" );
172- }
173-
174- throw new IllegalArgumentException ("Property " + property + " is not a KProperty" );
175- }
176-
177- }
178-
179139 /**
180140 * Introspect {@link TypedPropertyPath} and return an introspected {@link ResolvedTypedPropertyPath} variant.
181141 */
@@ -193,14 +153,14 @@ public static <P, T> TypedPropertyPath<T, P> of(TypedPropertyPath<T, P> lambda)
193153 }
194154
195155 return (TypedPropertyPath ) cache .computeIfAbsent (lambda ,
196- o -> new ResolvedTypedPropertyPath (o , doGetMetadata (lambda )));
156+ o -> new ResolvedTypedPropertyPath (o , read (lambda )));
197157 }
198158
199159 /**
200160 * Retrieve {@link PropertyPathMetadata} for a given {@link TypedPropertyPath}.
201161 */
202162 @ SuppressWarnings ({ "unchecked" , "rawtypes" })
203- public static <T , P > TypedPropertyPath <T , P > of (TypedPropertyPath <T , P > delegate , PropertyPathMetadata metadata ) {
163+ private static <T , P > TypedPropertyPath <T , P > aaa (TypedPropertyPath <T , P > delegate , PropertyPathMetadata metadata ) {
204164
205165 if (KotlinDetector .isKotlinReflectPresent () && metadata instanceof KPropertyPathMetadata ) {
206166 return new ResolvedKPropertyPath (((KPropertyPathMetadata ) metadata ).getProperty (), metadata );
@@ -209,31 +169,6 @@ public static <T, P> TypedPropertyPath<T, P> of(TypedPropertyPath<T, P> delegate
209169 return new ResolvedTypedPropertyPath <>(delegate , metadata );
210170 }
211171
212- /**
213- * Retrieve {@link PropertyPathMetadata} for a given {@link PropertyReference}.
214- */
215- public static PropertyPathMetadata getMetadata (PropertyReference <?, ?> lambda ) {
216- return doGetMetadata (lambda );
217- }
218-
219- /**
220- * Retrieve {@link PropertyPathMetadata} for a given {@link TypedPropertyPath}.
221- */
222- public static PropertyPathMetadata getMetadata (TypedPropertyPath <?, ?> lambda ) {
223- return doGetMetadata (lambda );
224- }
225-
226- private static PropertyPathMetadata doGetMetadata (Object lambda ) {
227-
228- Map <Object , PropertyPathMetadata > cache ;
229-
230- synchronized (lambdas ) {
231- cache = lambdas .computeIfAbsent (lambda .getClass ().getClassLoader (), k -> new ConcurrentReferenceHashMap <>());
232- }
233-
234- return cache .computeIfAbsent (lambda , o -> read (lambda ));
235- }
236-
237172 private static PropertyPathMetadata read (Object lambda ) {
238173
239174 MemberDescriptor reference = reader .read (lambda );
@@ -363,6 +298,48 @@ public KProperty<?> getProperty() {
363298 }
364299 }
365300
301+ /**
302+ * Delegate to handle property path composition of single-property and property-path KProperty1 references.
303+ */
304+ static class KotlinDelegate {
305+
306+ @ SuppressWarnings ({ "rawtypes" , "unchecked" })
307+ public static <T , P > TypedPropertyPath <T , P > of (Object property ) {
308+
309+ if (property instanceof KPropertyPath paths ) {
310+
311+ TypedPropertyPath parent = of (paths .getProperty ());
312+ TypedPropertyPath child = of (paths .getLeaf ());
313+
314+ return TypedPropertyPaths .compose (parent , child );
315+ }
316+
317+ if (property instanceof KPropertyImpl impl ) {
318+
319+ Class <?> owner = impl .getJavaField () != null ? impl .getJavaField ().getDeclaringClass ()
320+ : impl .getGetter ().getCaller ().getMember ().getDeclaringClass ();
321+ KPropertyPathMetadata metadata = TypedPropertyPaths .KPropertyPathMetadata
322+ .of (MemberDescriptor .KPropertyReferenceDescriptor .create (owner , (KProperty1 ) impl ));
323+ return new TypedPropertyPaths .ResolvedKPropertyPath (metadata );
324+ }
325+
326+ if (property instanceof KProperty1 kProperty ) {
327+
328+ if (kProperty .getGetter ().getProperty () instanceof KProperty1Impl impl ) {
329+ return of (impl );
330+ }
331+
332+ throw new IllegalArgumentException ("Property " + kProperty .getName () + " is not a KProperty" );
333+ }
334+
335+ throw new IllegalArgumentException ("Property " + property + " is not a KProperty" );
336+ }
337+
338+ }
339+
340+ /**
341+ * Marker interface to indicate a resolved and processed property path.
342+ */
366343 interface Resolved {
367344
368345 }
0 commit comments