Skip to content

Commit 8ae54ad

Browse files
committed
Hacking.
1 parent c3edbd5 commit 8ae54ad

File tree

6 files changed

+692
-10
lines changed

6 files changed

+692
-10
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mapping;
17+
18+
import java.util.Iterator;
19+
import java.util.List;
20+
21+
import org.springframework.data.util.TypeInformation;
22+
23+
record ComposedPropertyPath<T, M, R>(TypedPropertyPath<T, M> first,
24+
TypedPropertyPath<M, R> second) implements TypedPropertyPath<T, R> {
25+
26+
@Override
27+
public R get(T obj) {
28+
M intermediate = first.get(obj);
29+
return intermediate != null ? second.get(intermediate) : null;
30+
}
31+
32+
@Override
33+
public TypeInformation<?> getOwningType() {
34+
return first.getOwningType();
35+
}
36+
37+
@Override
38+
public String getSegment() {
39+
return first().getSegment();
40+
}
41+
42+
@Override
43+
public PropertyPath getLeafProperty() {
44+
return second.getLeafProperty();
45+
}
46+
47+
@Override
48+
public TypeInformation<?> getTypeInformation() {
49+
return first.getTypeInformation();
50+
}
51+
52+
@Override
53+
public PropertyPath next() {
54+
return second;
55+
}
56+
57+
@Override
58+
public boolean hasNext() {
59+
return true;
60+
}
61+
62+
@Override
63+
public String toDotPath() {
64+
return first.toDotPath() + "." + second.toDotPath();
65+
}
66+
67+
@Override
68+
public Iterator<PropertyPath> iterator() {
69+
return List.<PropertyPath> of(this, second).iterator();
70+
}
71+
72+
}

src/main/java/org/springframework/data/mapping/PropertyPath.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@
3535
*/
3636
public interface PropertyPath extends Streamable<PropertyPath> {
3737

38+
/**
39+
* Syntax sugar to create a {@link TypedPropertyPath} from an existing one, ideal for method handles.
40+
*
41+
* @param propertyPath
42+
* @return
43+
* @param <T> owning type.
44+
* @param <R> property type.
45+
* @since xxx
46+
*/
47+
public static <T, R> TypedPropertyPath<T, R> of(TypedPropertyPath<T, R> propertyPath) {
48+
PropertyPathExtractor.getPropertyPathInformation(propertyPath);
49+
return propertyPath;
50+
}
51+
3852
/**
3953
* Returns the owning type of the {@link PropertyPath}.
4054
*

0 commit comments

Comments
 (0)