Skip to content

Commit a87d5f8

Browse files
committed
Make PropertyMatches public
Issue: SPR-13054
1 parent 6fb3190 commit a87d5f8

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

spring-beans/src/main/java/org/springframework/beans/PropertyMatches.java

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,21 @@
2727
import org.springframework.util.StringUtils;
2828

2929
/**
30-
* Helper class for calculating bean property matches, according to.
31-
* Used by BeanWrapperImpl to suggest alternatives for an invalid property name.
30+
* Helper class for calculating property matches, according to a configurable
31+
* distance. Provide the list of potential matches and an easy way to generate
32+
* an error message. Works for both java bean properties and fields.
33+
* <p>
34+
* Mainly for use within the framework and in particular the binding facility
3235
*
3336
* @author Alef Arendsen
3437
* @author Arjen Poutsma
3538
* @author Juergen Hoeller
3639
* @author Stephane Nicoll
3740
* @since 2.0
3841
* @see #forProperty(String, Class)
42+
* @see #forField(String, Class)
3943
*/
40-
abstract class PropertyMatches {
44+
public abstract class PropertyMatches {
4145

4246
//---------------------------------------------------------------------
4347
// Static section
@@ -123,6 +127,21 @@ public String[] getPossibleMatches() {
123127
*/
124128
public abstract String buildErrorMessage();
125129

130+
protected void appendHintMessage(StringBuilder msg) {
131+
msg.append("Did you mean ");
132+
for (int i = 0; i < this.possibleMatches.length; i++) {
133+
msg.append('\'');
134+
msg.append(this.possibleMatches[i]);
135+
if (i < this.possibleMatches.length - 2) {
136+
msg.append("', ");
137+
}
138+
else if (i == this.possibleMatches.length - 2) {
139+
msg.append("', or ");
140+
}
141+
}
142+
msg.append("'?");
143+
}
144+
126145
/**
127146
* Calculate the distance between the given two Strings
128147
* according to the Levenshtein algorithm.
@@ -208,18 +227,7 @@ public String buildErrorMessage() {
208227
msg.append("Does the parameter type of the setter match the return type of the getter?");
209228
}
210229
else {
211-
msg.append("Did you mean ");
212-
for (int i = 0; i < possibleMatches.length; i++) {
213-
msg.append('\'');
214-
msg.append(possibleMatches[i]);
215-
if (i < possibleMatches.length - 2) {
216-
msg.append("', ");
217-
}
218-
else if (i == possibleMatches.length - 2) {
219-
msg.append("', or ");
220-
}
221-
}
222-
msg.append("'?");
230+
appendHintMessage(msg);
223231
}
224232
return msg.toString();
225233
}
@@ -258,18 +266,7 @@ public String buildErrorMessage() {
258266
msg.append("' has no matching field. ");
259267

260268
if (!ObjectUtils.isEmpty(possibleMatches)) {
261-
msg.append("Did you mean ");
262-
for (int i = 0; i < possibleMatches.length; i++) {
263-
msg.append('\'');
264-
msg.append(possibleMatches[i]);
265-
if (i < possibleMatches.length - 2) {
266-
msg.append("', ");
267-
}
268-
else if (i == possibleMatches.length - 2) {
269-
msg.append("', or ");
270-
}
271-
}
272-
msg.append("'?");
269+
appendHintMessage(msg);
273270
}
274271
return msg.toString();
275272
}

0 commit comments

Comments
 (0)