Browse Source

Polishing.

Reorder methods. Tweak Javadoc, add references to parameter naming. Add usage to newly introduced methods.

See #3088
Original pull request: #3272
pull/3161/merge
Mark Paluch 8 months ago
parent
commit
646aea4cc0
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 31
      src/main/java/org/springframework/data/mapping/Parameter.java
  2. 2
      src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java
  3. 24
      src/main/java/org/springframework/data/repository/query/Parameter.java
  4. 4
      src/main/java/org/springframework/data/repository/query/ReturnedType.java

31
src/main/java/org/springframework/data/mapping/Parameter.java

@ -91,9 +91,10 @@ public class Parameter<T, P extends PersistentProperty<P>> { @@ -91,9 +91,10 @@ public class Parameter<T, P extends PersistentProperty<P>> {
}
/**
* Returns the name of the parameter.
* Returns the name of the parameter (through constructor/method parameter naming).
*
* @return
* @return the name of the parameter.
* @see org.springframework.core.ParameterNameDiscoverer
*/
@Nullable
public String getName() {
@ -101,10 +102,22 @@ public class Parameter<T, P extends PersistentProperty<P>> { @@ -101,10 +102,22 @@ public class Parameter<T, P extends PersistentProperty<P>> {
}
/**
* Returns the required parameter name.
* Returns whether the parameter has a name.
*
* @return whether the parameter has a name.
* @since 3.5
*/
public boolean hasName() {
return this.name != null;
}
/**
* Returns the required name of the parameter (through constructor/method parameter naming) or throws
* {@link IllegalStateException} if the parameter has no name.
*
* @return the parameter name or throws {@link IllegalStateException} if the parameter does not have a name
* @return the parameter name or throws {@link IllegalStateException} if the parameter does not have a name.
* @since 3.5
* @see org.springframework.core.ParameterNameDiscoverer
*/
public String getRequiredName() {
@ -115,16 +128,6 @@ public class Parameter<T, P extends PersistentProperty<P>> { @@ -115,16 +128,6 @@ public class Parameter<T, P extends PersistentProperty<P>> {
return getName();
}
/**
* Returns whether the parameter has a name.
*
* @return whether the parameter has a name
* @since 3.5
*/
public boolean hasName() {
return this.name != null;
}
/**
* Returns the {@link TypeInformation} of the parameter.
*

2
src/main/java/org/springframework/data/mapping/model/InstantiationAwarePropertyAccessor.java

@ -95,7 +95,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty @@ -95,7 +95,7 @@ public class InstantiationAwarePropertyAccessor<T> implements PersistentProperty
creator.getParameters().forEach(it -> {
if (it.getName() == null) {
if (!it.hasName()) {
throw new IllegalStateException(
String.format("Cannot detect parameter names of copy creator of %s", owner.getType()));
}

24
src/main/java/org/springframework/data/repository/query/Parameter.java

@ -165,10 +165,23 @@ public class Parameter { @@ -165,10 +165,23 @@ public class Parameter {
return !isSpecialParameter() && getName().isPresent();
}
/**
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
*
* @return
* @since 1.11
* @see Param
*/
public boolean isExplicitlyNamed() {
return parameter.hasParameterAnnotation(Param.class);
}
/**
* Returns the name of the parameter (through {@link Param} annotation or method parameter naming).
*
* @return the optional name of the parameter.
* @see Param
* @see org.springframework.core.ParameterNameDiscoverer
*/
public Optional<String> getName() {
return this.name.get();
@ -181,6 +194,8 @@ public class Parameter { @@ -181,6 +194,8 @@ public class Parameter {
* @return the required parameter name.
* @throws IllegalStateException if the parameter has no name.
* @since 3.4
* @see Param
* @see org.springframework.core.ParameterNameDiscoverer
*/
public String getRequiredName() {
@ -197,15 +212,6 @@ public class Parameter { @@ -197,15 +212,6 @@ public class Parameter {
return parameterType;
}
/**
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
*
* @return
* @since 1.11
*/
public boolean isExplicitlyNamed() {
return parameter.hasParameterAnnotation(Param.class);
}
@Override
public String toString() {

4
src/main/java/org/springframework/data/repository/query/ReturnedType.java

@ -303,8 +303,8 @@ public abstract class ReturnedType { @@ -303,8 +303,8 @@ public abstract class ReturnedType {
List<String> properties = new ArrayList<>(parameterCount);
for (Parameter<Object, ?> parameter : constructor.getParameters()) {
if (parameter.getName() != null) {
properties.add(parameter.getName());
if (parameter.hasName()) {
properties.add(parameter.getRequiredName());
}
}

Loading…
Cancel
Save