Polishing.
Add missing Override annotations. Eagerly compute input properties. See #3163
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -155,6 +155,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.
|
||||
@@ -170,6 +171,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
|
||||
@@ -177,6 +192,7 @@ public abstract class ReturnedType {
|
||||
return information.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsCustomConstruction() {
|
||||
return isProjecting() && information.isClosed();
|
||||
}
|
||||
@@ -194,16 +210,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +250,7 @@ public abstract class ReturnedType {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Class<?> getTypeToRead() {
|
||||
return type;
|
||||
@@ -253,6 +261,7 @@ public abstract class ReturnedType {
|
||||
return isDto();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsCustomConstruction() {
|
||||
return isDto() && !inputProperties.isEmpty();
|
||||
}
|
||||
@@ -280,7 +289,7 @@ public abstract class ReturnedType {
|
||||
properties.add(parameter.getName());
|
||||
}
|
||||
|
||||
return properties;
|
||||
return Collections.unmodifiableList(properties);
|
||||
}
|
||||
|
||||
private boolean isDto() {
|
||||
|
||||
Reference in New Issue
Block a user