Polishing.

Add missing Override annotations. Eagerly compute input properties.

See #3163
This commit is contained in:
Mark Paluch
2024-09-24 16:04:48 +02:00
parent 22066eced3
commit 4633380ae4
2 changed files with 28 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ import java.util.stream.Stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.core.log.LogMessage;
import org.springframework.core.type.AnnotationMetadata;
@@ -53,6 +54,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
private final Class<?> projectionType;
private final List<PropertyDescriptor> properties;
private final List<PropertyDescriptor> inputProperties;
/**
* Creates a new {@link DefaultProjectionInformation} for the given type.
@@ -65,6 +67,10 @@ class DefaultProjectionInformation implements ProjectionInformation {
this.projectionType = type;
this.properties = new PropertyDescriptorSource(type).getDescriptors();
this.inputProperties = properties.stream()//
.filter(this::isInputProperty)//
.distinct()//
.toList();
}
@Override
@@ -72,12 +78,9 @@ class DefaultProjectionInformation implements ProjectionInformation {
return projectionType;
}
@Override
public List<PropertyDescriptor> getInputProperties() {
return properties.stream()//
.filter(this::isInputProperty)//
.distinct()//
.collect(Collectors.toList());
return inputProperties;
}
@Override

View File

@@ -143,6 +143,7 @@ public abstract class ReturnedType {
private final ProjectionInformation information;
private final Class<?> domainType;
private final List<String> inputProperties;
/**
* Creates a new {@link ReturnedInterface} from the given {@link ProjectionInformation} and domain type.
@@ -158,6 +159,20 @@ public abstract class ReturnedType {
this.information = information;
this.domainType = domainType;
this.inputProperties = detectInputProperties(information);
}
private static List<String> detectInputProperties(ProjectionInformation information) {
List<String> properties = new ArrayList<>();
for (PropertyDescriptor descriptor : information.getInputProperties()) {
if (!properties.contains(descriptor.getName())) {
properties.add(descriptor.getName());
}
}
return Collections.unmodifiableList(properties);
}
@Override
@@ -165,6 +180,7 @@ public abstract class ReturnedType {
return information.getType();
}
@Override
public boolean needsCustomConstruction() {
return isProjecting() && information.isClosed();
}
@@ -182,16 +198,7 @@ public abstract class ReturnedType {
@Override
public List<String> getInputProperties() {
List<String> properties = new ArrayList<>();
for (PropertyDescriptor descriptor : information.getInputProperties()) {
if (!properties.contains(descriptor.getName())) {
properties.add(descriptor.getName());
}
}
return properties;
return inputProperties;
}
}
@@ -231,6 +238,7 @@ public abstract class ReturnedType {
return type;
}
@Override
@NonNull
public Class<?> getTypeToRead() {
return type;
@@ -241,6 +249,7 @@ public abstract class ReturnedType {
return isDto();
}
@Override
public boolean needsCustomConstruction() {
return isDto() && !inputProperties.isEmpty();
}
@@ -268,7 +277,7 @@ public abstract class ReturnedType {
properties.add(parameter.getName());
}
return properties;
return Collections.unmodifiableList(properties);
}
private boolean isDto() {