Skip to content

Commit dde5b37

Browse files
committed
Polishing.
Add missing Override annotations. Eagerly compute input properties. See #3163
1 parent 52e10da commit dde5b37

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

Lines changed: 8 additions & 5 deletions
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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private static final class ReturnedInterface extends ReturnedType {
155155

156156
private final ProjectionInformation information;
157157
private final Class<?> domainType;
158+
private final List<String> inputProperties;
158159

159160
/**
160161
* Creates a new {@link ReturnedInterface} from the given {@link ProjectionInformation} and domain type.
@@ -170,13 +171,28 @@ public ReturnedInterface(ProjectionInformation information, Class<?> domainType)
170171

171172
this.information = information;
172173
this.domainType = domainType;
174+
this.inputProperties = detectInputProperties(information);
175+
}
176+
177+
private static List<String> detectInputProperties(ProjectionInformation information) {
178+
179+
List<String> properties = new ArrayList<>();
180+
181+
for (PropertyDescriptor descriptor : information.getInputProperties()) {
182+
if (!properties.contains(descriptor.getName())) {
183+
properties.add(descriptor.getName());
184+
}
185+
}
186+
187+
return Collections.unmodifiableList(properties);
173188
}
174189

175190
@Override
176191
public Class<?> getReturnedType() {
177192
return information.getType();
178193
}
179194

195+
@Override
180196
public boolean needsCustomConstruction() {
181197
return isProjecting() && information.isClosed();
182198
}
@@ -194,16 +210,7 @@ public Class<?> getTypeToRead() {
194210

195211
@Override
196212
public List<String> getInputProperties() {
197-
198-
List<String> properties = new ArrayList<>();
199-
200-
for (PropertyDescriptor descriptor : information.getInputProperties()) {
201-
if (!properties.contains(descriptor.getName())) {
202-
properties.add(descriptor.getName());
203-
}
204-
}
205-
206-
return properties;
213+
return inputProperties;
207214
}
208215
}
209216

@@ -243,6 +250,7 @@ public Class<?> getReturnedType() {
243250
return type;
244251
}
245252

253+
@Override
246254
@NonNull
247255
public Class<?> getTypeToRead() {
248256
return type;
@@ -253,6 +261,7 @@ public boolean isProjecting() {
253261
return isDto();
254262
}
255263

264+
@Override
256265
public boolean needsCustomConstruction() {
257266
return isDto() && !inputProperties.isEmpty();
258267
}
@@ -280,7 +289,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
280289
properties.add(parameter.getName());
281290
}
282291

283-
return properties;
292+
return Collections.unmodifiableList(properties);
284293
}
285294

286295
private boolean isDto() {

0 commit comments

Comments
 (0)