DATACMNS-1206 - Polishing.
Convert type array to string to construct the exception message. Slight Javadoc tweaks. Reduce method visibility. Simplify hasDefaultGetter check. Remove superfluous throws declaration. Strip trailing whitespaces. Ignore property descriptors without getter (e.g. indexed properties). Original pull request: #263.
This commit is contained in:
@@ -117,7 +117,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
|
|
||||||
Method method = descriptor.getReadMethod();
|
Method method = descriptor.getReadMethod();
|
||||||
|
|
||||||
return method == null ? false : method.isDefault();
|
return method != null && method.isDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,7 +139,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
*
|
*
|
||||||
* @param type must not be {@literal null}.
|
* @param type must not be {@literal null}.
|
||||||
*/
|
*/
|
||||||
public PropertyDescriptorSource(Class<?> type) {
|
PropertyDescriptorSource(Class<?> type) {
|
||||||
|
|
||||||
Assert.notNull(type, "Type must not be null!");
|
Assert.notNull(type, "Type must not be null!");
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public List<PropertyDescriptor> getDescriptors() {
|
List<PropertyDescriptor> getDescriptors() {
|
||||||
return collectDescriptors().distinct().collect(StreamUtils.toUnmodifiableList());
|
return collectDescriptors().distinct().collect(StreamUtils.toUnmodifiableList());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,8 +178,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Stream of {@link PropertyDescriptor} ordered following the given {@link MethodsMetadata} only returning
|
* Returns a {@link Stream} of {@link PropertyDescriptor} ordered following the given {@link MethodsMetadata} only
|
||||||
* methods seen by the given {@link MethodsMetadata}.
|
* returning methods seen by the given {@link MethodsMetadata}.
|
||||||
*
|
*
|
||||||
* @param source must not be {@literal null}.
|
* @param source must not be {@literal null}.
|
||||||
* @param metadata must not be {@literal null}.
|
* @param metadata must not be {@literal null}.
|
||||||
@@ -194,7 +194,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
return source.filter(descriptor -> orderedMethods.containsKey(descriptor.getReadMethod().getName()))
|
return source.filter(descriptor -> descriptor.getReadMethod() != null)
|
||||||
|
.filter(descriptor -> orderedMethods.containsKey(descriptor.getReadMethod().getName()))
|
||||||
.sorted(Comparator.comparingInt(left -> orderedMethods.get(left.getReadMethod().getName())));
|
.sorted(Comparator.comparingInt(left -> orderedMethods.get(left.getReadMethod().getName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +210,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Stream of interfaces using the given type as primary source for ordering.
|
* Returns a {@link Stream} of interfaces using the given type as primary source for ordering.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -253,7 +254,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
|
|||||||
return Arrays.stream(types) //
|
return Arrays.stream(types) //
|
||||||
.filter(it -> name.equals(it.getName())) //
|
.filter(it -> name.equals(it.getName())) //
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow(() -> new IllegalStateException(String.format("Did not find type %s in %s!", name, types)));
|
.orElseThrow(() -> new IllegalStateException(
|
||||||
|
String.format("Did not find type %s in %s!", name, Arrays.toString(types))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import org.springframework.util.Assert;
|
|||||||
* {@link MethodsMetadataReader} implementation based on an ASM {@link org.springframework.asm.ClassReader}.
|
* {@link MethodsMetadataReader} implementation based on an ASM {@link org.springframework.asm.ClassReader}.
|
||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Oliver Gierke
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link DefaultProjectionInformation}.
|
* Unit tests for {@link DefaultProjectionInformation}.
|
||||||
@@ -40,6 +41,14 @@ public class DefaultProjectionInformationUnitTests {
|
|||||||
assertThat(toNames(information.getInputProperties())).contains("firstname", "lastname");
|
assertThat(toNames(information.getInputProperties())).contains("firstname", "lastname");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATACMNS-1206
|
||||||
|
public void omitsInputPropertiesAcceptingArguments() {
|
||||||
|
|
||||||
|
ProjectionInformation information = new DefaultProjectionInformation(ProjectionAcceptingArguments.class);
|
||||||
|
|
||||||
|
assertThat(toNames(information.getInputProperties())).containsOnly("lastname");
|
||||||
|
}
|
||||||
|
|
||||||
@Test // DATACMNS-89
|
@Test // DATACMNS-89
|
||||||
public void discoversAllInputProperties() {
|
public void discoversAllInputProperties() {
|
||||||
|
|
||||||
@@ -66,7 +75,7 @@ public class DefaultProjectionInformationUnitTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATACMNS-967
|
@Test // DATACMNS-967
|
||||||
public void doesNotConsiderDefaultMethodInputProperties() throws Exception {
|
public void doesNotConsiderDefaultMethodInputProperties() {
|
||||||
|
|
||||||
ProjectionInformation information = new DefaultProjectionInformation(WithDefaultMethod.class);
|
ProjectionInformation information = new DefaultProjectionInformation(WithDefaultMethod.class);
|
||||||
|
|
||||||
@@ -89,6 +98,14 @@ public class DefaultProjectionInformationUnitTests {
|
|||||||
String getLastname();
|
String getLastname();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ProjectionAcceptingArguments {
|
||||||
|
|
||||||
|
@Value("foo")
|
||||||
|
String getFirstname(int i);
|
||||||
|
|
||||||
|
String getLastname();
|
||||||
|
}
|
||||||
|
|
||||||
interface ExtendedProjection extends CustomerProjection {
|
interface ExtendedProjection extends CustomerProjection {
|
||||||
|
|
||||||
int getAge();
|
int getAge();
|
||||||
|
|||||||
Reference in New Issue
Block a user