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

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -118,7 +118,7 @@ public final class Property {
}
// package private
// Package private
MethodParameter getMethodParameter() {
return this.methodParameter;
@@ -132,7 +132,7 @@ public final class Property {
}
// internal helpers
// Internal helpers
private String resolveName() {
if (this.readMethod != null) {
@@ -142,10 +142,13 @@ public final class Property {
}
else {
index = this.readMethod.getName().indexOf("is");
if (index == -1) {
throw new IllegalArgumentException("Not a getter method");
if (index != -1) {
index += 2;
}
else {
// Record-style plain accessor method, e.g. name()
index = 0;
}
index += 2;
}
return StringUtils.uncapitalize(this.readMethod.getName().substring(index));
}