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 646aea4

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 a978209 commit 646aea4

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,20 +91,33 @@ private static String getValue(MergedAnnotations annotations) {
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
@Nullable
99100
public String getName() {
100101
return name;
101102
}
102103

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

@@ -115,16 +128,6 @@ public String getRequiredName() {
115128
return getName();
116129
}
117130

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

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

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

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

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

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

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

168+
/**
169+
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
170+
*
171+
* @return
172+
* @since 1.11
173+
* @see Param
174+
*/
175+
public boolean isExplicitlyNamed() {
176+
return parameter.hasParameterAnnotation(Param.class);
177+
}
178+
168179
/**
169180
* Returns the name of the parameter (through {@link Param} annotation or method parameter naming).
170181
*
171182
* @return the optional name of the parameter.
183+
* @see Param
184+
* @see org.springframework.core.ParameterNameDiscoverer
172185
*/
173186
public Optional<String> getName() {
174187
return this.name.get();
@@ -181,6 +194,8 @@ public Optional<String> getName() {
181194
* @return the required parameter name.
182195
* @throws IllegalStateException if the parameter has no name.
183196
* @since 3.4
197+
* @see Param
198+
* @see org.springframework.core.ParameterNameDiscoverer
184199
*/
185200
public String getRequiredName() {
186201

@@ -197,15 +212,6 @@ public Class<?> getType() {
197212
return parameterType;
198213
}
199214

200-
/**
201-
* Returns whether the parameter is named explicitly, i.e. annotated with {@link Param}.
202-
*
203-
* @return
204-
* @since 1.11
205-
*/
206-
public boolean isExplicitlyNamed() {
207-
return parameter.hasParameterAnnotation(Param.class);
208-
}
209215

210216
@Override
211217
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 によって変換されたページ (->オリジナル) /