Skip to content

Commit b8c84a8

Browse files
committed
Hacking.
1 parent c2f8cf0 commit b8c84a8

File tree

6 files changed

+692
-10
lines changed

6 files changed

+692
-10
lines changed

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

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

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

src/main/java/org/springframework/data/core/SimplePropertyPath.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ public boolean isCollection() {
148148
return isCollection;
149149
}
150150

151-
@Override
152-
public SimplePropertyPath nested(String path) {
153-
154-
Assert.hasText(path, "Path must not be null or empty");
155-
156-
String lookup = toDotPath().concat(".").concat(path);
157-
158-
return SimplePropertyPath.from(lookup, owningType);
159-
}
160-
161151
@Override
162152
public Iterator<PropertyPath> iterator() {
163153

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+
}

0 commit comments

Comments
 (0)