Polishing.

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

See #3088
Original pull request: #3272
This commit is contained in:
Mark Paluch
2025-04-22 09:03:51 +02:00
parent a978209497
commit 646aea4cc0
4 changed files with 35 additions and 26 deletions

View File

@@ -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,11 +102,23 @@ public class Parameter<T, P extends PersistentProperty<P>> {
}
/**
* Returns the required parameter name.
* Returns whether the parameter has a name.
*
* @return the parameter name or throws {@link IllegalStateException} if the parameter does not have 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.
* @since 3.5
* @see org.springframework.core.ParameterNameDiscoverer
*/
public String getRequiredName() {
if (!hasName()) {
@@ -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.
*

View File

@@ -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()));
}

View File

@@ -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 {
* @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 {
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() {

View File

@@ -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());
}
}