Browse Source

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.
pull/303/head
Mark Paluch 8 years ago committed by Oliver Gierke
parent
commit
7ddd0ecac5
  1. 28
      src/main/java/org/springframework/data/projection/DefaultProjectionInformation.java
  2. 1
      src/main/java/org/springframework/data/type/classreading/DefaultMethodsMetadataReader.java
  3. 19
      src/test/java/org/springframework/data/projection/DefaultProjectionInformationUnitTests.java

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

@ -117,7 +117,7 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -117,7 +117,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
Method method = descriptor.getReadMethod();
return method == null ? false : method.isDefault();
return method != null && method.isDefault();
}
/**
@ -136,10 +136,10 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -136,10 +136,10 @@ class DefaultProjectionInformation implements ProjectionInformation {
/**
* Creates a new {@link PropertyDescriptorSource} for the given type.
*
*
* @param type must not be {@literal null}.
*/
public PropertyDescriptorSource(Class<?> type) {
PropertyDescriptorSource(Class<?> type) {
Assert.notNull(type, "Type must not be null!");
@ -152,7 +152,7 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -152,7 +152,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
*
* @return
*/
public List<PropertyDescriptor> getDescriptors() {
List<PropertyDescriptor> getDescriptors() {
return collectDescriptors().distinct().collect(StreamUtils.toUnmodifiableList());
}
@ -178,9 +178,9 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -178,9 +178,9 @@ class DefaultProjectionInformation implements ProjectionInformation {
}
/**
* Returns a Stream of {@link PropertyDescriptor} ordered following the given {@link MethodsMetadata} only returning
* methods seen by the given {@link MethodsMetadata}.
*
* Returns a {@link Stream} of {@link PropertyDescriptor} ordered following the given {@link MethodsMetadata} only
* returning methods seen by the given {@link MethodsMetadata}.
*
* @param source must not be {@literal null}.
* @param metadata must not be {@literal null}.
* @return
@ -194,13 +194,14 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -194,13 +194,14 @@ class DefaultProjectionInformation implements ProjectionInformation {
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())));
}
/**
* Returns a {@link Stream} of interfaces using the given {@link MethodsMetadata} as primary source for ordering.
*
*
* @param metadata must not be {@literal null}.
* @return
*/
@ -209,8 +210,8 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -209,8 +210,8 @@ 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
*/
private Stream<Class<?>> fromType() {
@ -243,7 +244,7 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -243,7 +244,7 @@ class DefaultProjectionInformation implements ProjectionInformation {
/**
* Find the type with the given name in the given array of {@link Class}.
*
*
* @param name must not be {@literal null} or empty.
* @param types must not be {@literal null}.
* @return
@ -253,7 +254,8 @@ class DefaultProjectionInformation implements ProjectionInformation { @@ -253,7 +254,8 @@ class DefaultProjectionInformation implements ProjectionInformation {
return Arrays.stream(types) //
.filter(it -> name.equals(it.getName())) //
.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))));
}
/**

1
src/main/java/org/springframework/data/type/classreading/DefaultMethodsMetadataReader.java

@ -43,6 +43,7 @@ import org.springframework.util.Assert; @@ -43,6 +43,7 @@ import org.springframework.util.Assert;
* {@link MethodsMetadataReader} implementation based on an ASM {@link org.springframework.asm.ClassReader}.
*
* @author Mark Paluch
* @author Oliver Gierke
* @since 2.1
*/
@Getter

19
src/test/java/org/springframework/data/projection/DefaultProjectionInformationUnitTests.java

@ -23,6 +23,7 @@ import java.util.List; @@ -23,6 +23,7 @@ import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Value;
/**
* Unit tests for {@link DefaultProjectionInformation}.
@ -40,6 +41,14 @@ public class DefaultProjectionInformationUnitTests { @@ -40,6 +41,14 @@ public class DefaultProjectionInformationUnitTests {
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
public void discoversAllInputProperties() {
@ -66,7 +75,7 @@ public class DefaultProjectionInformationUnitTests { @@ -66,7 +75,7 @@ public class DefaultProjectionInformationUnitTests {
}
@Test // DATACMNS-967
public void doesNotConsiderDefaultMethodInputProperties() throws Exception {
public void doesNotConsiderDefaultMethodInputProperties() {
ProjectionInformation information = new DefaultProjectionInformation(WithDefaultMethod.class);
@ -89,6 +98,14 @@ public class DefaultProjectionInformationUnitTests { @@ -89,6 +98,14 @@ public class DefaultProjectionInformationUnitTests {
String getLastname();
}
interface ProjectionAcceptingArguments {
@Value("foo")
String getFirstname(int i);
String getLastname();
}
interface ExtendedProjection extends CustomerProjection {
int getAge();

Loading…
Cancel
Save