SpEL supports record-style accessor methods as well

Closes gh-26029
This commit is contained in:
Juergen Hoeller
2020-11-04 16:51:54 +01:00
parent 412aa06d86
commit 079ca80854
5 changed files with 95 additions and 37 deletions

View File

@@ -395,6 +395,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
if (method == null) {
method = findMethodForProperty(getPropertyMethodSuffixes(propertyName),
"is", clazz, mustBeStatic, 0, BOOLEAN_TYPES);
if (method == null) {
// Record-style plain accessor method, e.g. name()
method = findMethodForProperty(new String[] {propertyName},
"", clazz, mustBeStatic, 0, ANY_TYPES);
}
}
return method;
}
@@ -683,12 +688,11 @@ public class ReflectivePropertyAccessor implements PropertyAccessor {
return true;
}
getterName = "is" + StringUtils.capitalize(name);
return getterName.equals(method.getName());
}
else {
Field field = (Field) this.member;
return field.getName().equals(name);
if (getterName.equals(method.getName())) {
return true;
}
}
return this.member.getName().equals(name);
}
@Override