Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f5cfdc0

Browse files
committed
Polishing.
Reorder methods. Tweak Javadoc, add references to parameter naming. Add usage to newly introduced methods. See #3088 Original pull request: #3272
1 parent 0e31401 commit f5cfdc0

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,32 @@ public Parameter(@Nullable String name, TypeInformation<T> type, Annotation[] an
9191
}
9292

9393
/**
94-
* Returns the name of the parameter.
94+
* Returns the name of the parameter (through constructor/method parameter naming).
9595
*
96-
* @return
96+
* @return the name of the parameter.
97+
* @see org.springframework.core.ParameterNameDiscoverer
9798
*/
9899
public @Nullable String getName() {
99100
return name;
100101
}
101102

102103
/**
103-
* Returns the required parameter name.
104+
* Returns whether the parameter has a name.
105+
*
106+
* @return whether the parameter has a name.
107+
* @since 3.5
108+
*/
109+
public boolean hasName() {
110+
return this.name != null;
111+
}
112+
113+
/**
114+
* Returns the required name of the parameter (through constructor/method parameter naming) or throws
115+
* {@link IllegalStateException} if the parameter has no name.
104116
*
105-
* @return the parameter name or throws {@link IllegalStateException} if the parameter does not have a name
117+
* @return the parameter name or throws {@link IllegalStateException} if the parameter does not have a name.
106118
* @since 3.5
119+
* @see org.springframework.core.ParameterNameDiscoverer
107120
*/
108121
public String getRequiredName() {
109122

@@ -114,16 +127,6 @@ public String getRequiredName() {
114127
return getName();
115128
}
116129

117-
/**
118-
* Returns whether the parameter has a name.
119-
*
120-
* @return whether the parameter has a name
121-
* @since 3.5
122-
*/
123-
public boolean hasName() {
124-
return this.name != null;
125-
}
126-
127130
/**
128131
* Returns the {@link TypeInformation} of the parameter.
129132
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void setProperty(PersistentProperty<?> property, @Nullable Object value)
9696

9797
creator.getParameters().forEach(it -> {
9898

99-
if (it.getName() == null) {
99+
if (!it.hasName()) {
100100
throw new IllegalStateException(
101101
String.format("Cannot detect parameter names of copy creator of %s", owner.getType()));
102102
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,23 @@ public boolean isNamedParameter() {
154154
return !isSpecialParameter() && getName().isPresent();
155155
}
156156

157+
/**
158+
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
159+
*
160+
* @return
161+
* @since 1.11
162+
* @see Param
163+
*/
164+
public boolean isExplicitlyNamed() {
165+
return parameter.hasParameterAnnotation(Param.class);
166+
}
167+
157168
/**
158169
* Returns the name of the parameter (through {@link Param} annotation or method parameter naming).
159170
*
160171
* @return the optional name of the parameter.
172+
* @see Param
173+
* @see org.springframework.core.ParameterNameDiscoverer
161174
*/
162175
public Optional<String> getName() {
163176
return this.name.get();
@@ -170,6 +183,8 @@ public Optional<String> getName() {
170183
* @return the required parameter name.
171184
* @throws IllegalStateException if the parameter has no name.
172185
* @since 3.4
186+
* @see Param
187+
* @see org.springframework.core.ParameterNameDiscoverer
173188
*/
174189
public String getRequiredName() {
175190

@@ -186,15 +201,6 @@ public Class<?> getType() {
186201
return parameterType;
187202
}
188203

189-
/**
190-
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
191-
*
192-
* @return
193-
* @since 1.11
194-
*/
195-
public boolean isExplicitlyNamed() {
196-
return parameter.hasParameterAnnotation(Param.class);
197-
}
198204

199205
@Override
200206
public String toString() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
303303
List<String> properties = new ArrayList<>(parameterCount);
304304

305305
for (Parameter<Object, ?> parameter : constructor.getParameters()) {
306-
if (parameter.getName() != null) {
307-
properties.add(parameter.getName());
306+
if (parameter.hasName()) {
307+
properties.add(parameter.getRequiredName());
308308
}
309309
}
310310

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /