Skip to content

Commit e8c5a4c

Browse files
committed
code simplify
1 parent 9da3467 commit e8c5a4c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/org/apache/ibatis/reflection/property/PropertyNamer.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.apache.ibatis.reflection.property;
1717

18-
import java.util.Locale;
18+
import java.beans.Introspector;
1919

2020
import org.apache.ibatis.reflection.ReflectionException;
2121

@@ -37,11 +37,7 @@ public static String methodToProperty(String name) {
3737
throw new ReflectionException("Error parsing property name '" + name + "'. Didn't start with 'is', 'get' or 'set'.");
3838
}
3939

40-
if (name.length() == 1 || (name.length() > 1 && !Character.isUpperCase(name.charAt(1)))) {
41-
name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
42-
}
43-
44-
return name;
40+
return Introspector.decapitalize(name);
4541
}
4642

4743
public static boolean isProperty(String name) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.apache.ibatis.reflection.property;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.*;
6+
7+
class PropertyNamerTest {
8+
9+
@Test
10+
void methodToProperty() {
11+
assertEquals("ok", PropertyNamer.methodToProperty("isOk"));
12+
assertEquals("OK", PropertyNamer.methodToProperty("isOK"));
13+
14+
assertEquals("name", PropertyNamer.methodToProperty("getName"));
15+
assertEquals("XName", PropertyNamer.methodToProperty("getXName"));
16+
assertEquals("xName", PropertyNamer.methodToProperty("getxName"));
17+
18+
assertEquals("name", PropertyNamer.methodToProperty("setName"));
19+
assertEquals("XName", PropertyNamer.methodToProperty("setXName"));
20+
assertEquals("xName", PropertyNamer.methodToProperty("setxName"));
21+
}
22+
}

0 commit comments

Comments
 (0)