Skip to content

Commit d8c8054

Browse files
committed
Polishing.
Add missing Override annotations. Eagerly compute input properties. See #3163
1 parent 14eb7be commit d8c8054

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.apache.commons.logging.Log;
3131
import org.apache.commons.logging.LogFactory;
32+
3233
import org.springframework.beans.BeanUtils;
3334
import org.springframework.core.log.LogMessage;
3435
import org.springframework.core.type.AnnotationMetadata;
@@ -53,6 +54,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
5354

5455
private final Class<?> projectionType;
5556
private final List<PropertyDescriptor> properties;
57+
private final List<PropertyDescriptor> inputProperties;
5658

5759
/**
5860
* Creates a new {@link DefaultProjectionInformation} for the given type.
@@ -65,19 +67,20 @@ class DefaultProjectionInformation implements ProjectionInformation {
6567

6668
this.projectionType = type;
6769
this.properties = new PropertyDescriptorSource(type).getDescriptors();
70+
this.inputProperties = properties.stream()//
71+
.filter(this::isInputProperty)//
72+
.distinct()//
73+
.toList();
6874
}
6975

7076
@Override
7177
public Class<?> getType() {
7278
return projectionType;
7379
}
7480

81+
@Override
7582
public List<PropertyDescriptor> getInputProperties() {
76-
77-
return properties.stream()//
78-
.filter(this::isInputProperty)//
79-
.distinct()//
80-
.collect(Collectors.toList());
83+
return inputProperties;
8184
}
8285

8386
@Override

src/main/java/org/springframework/data/repository/query/ReturnedType.java

+20-11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ private static final class ReturnedInterface extends ReturnedType {
143143

144144
private final ProjectionInformation information;
145145
private final Class<?> domainType;
146+
private final List<String> inputProperties;
146147

147148
/**
148149
* Creates a new {@link ReturnedInterface} from the given {@link ProjectionInformation} and domain type.
@@ -158,13 +159,28 @@ public ReturnedInterface(ProjectionInformation information, Class<?> domainType)
158159

159160
this.information = information;
160161
this.domainType = domainType;
162+
this.inputProperties = detectInputProperties(information);
163+
}
164+
165+
private static List<String> detectInputProperties(ProjectionInformation information) {
166+
167+
List<String> properties = new ArrayList<>();
168+
169+
for (PropertyDescriptor descriptor : information.getInputProperties()) {
170+
if (!properties.contains(descriptor.getName())) {
171+
properties.add(descriptor.getName());
172+
}
173+
}
174+
175+
return Collections.unmodifiableList(properties);
161176
}
162177

163178
@Override
164179
public Class<?> getReturnedType() {
165180
return information.getType();
166181
}
167182

183+
@Override
168184
public boolean needsCustomConstruction() {
169185
return isProjecting() && information.isClosed();
170186
}
@@ -182,16 +198,7 @@ public Class<?> getTypeToRead() {
182198

183199
@Override
184200
public List<String> getInputProperties() {
185-
186-
List<String> properties = new ArrayList<>();
187-
188-
for (PropertyDescriptor descriptor : information.getInputProperties()) {
189-
if (!properties.contains(descriptor.getName())) {
190-
properties.add(descriptor.getName());
191-
}
192-
}
193-
194-
return properties;
201+
return inputProperties;
195202
}
196203
}
197204

@@ -231,6 +238,7 @@ public Class<?> getReturnedType() {
231238
return type;
232239
}
233240

241+
@Override
234242
@NonNull
235243
public Class<?> getTypeToRead() {
236244
return type;
@@ -241,6 +249,7 @@ public boolean isProjecting() {
241249
return isDto();
242250
}
243251

252+
@Override
244253
public boolean needsCustomConstruction() {
245254
return isDto() && !inputProperties.isEmpty();
246255
}
@@ -268,7 +277,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
268277
properties.add(parameter.getName());
269278
}
270279

271-
return properties;
280+
return Collections.unmodifiableList(properties);
272281
}
273282

274283
private boolean isDto() {

0 commit comments

Comments
 (0)