1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection.property;
17
18 import java.util.Locale;
19
20 import org.apache.ibatis.reflection.ReflectionException;
21
22
23
24
25 public final class PropertyNamer {
26
27 private PropertyNamer() {
28
29 }
30
31 public static String methodToProperty(String name) {
32 if (name.startsWith("is")) {
33 name = name.substring(2);
34 } else if (name.startsWith("get") || name.startsWith("set")) {
35 name = name.substring(3);
36 } else {
37 throw new ReflectionException(
38 "Error parsing property name '" + name + "'. Didn't start with 'is', 'get' or 'set'.");
39 }
40
41 if (name.length() == 1 || name.length() > 1 && !Character.isUpperCase(name.charAt(1))) {
42 name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1);
43 }
44
45 return name;
46 }
47
48 public static boolean isProperty(String name) {
49 return isGetter(name) || isSetter(name);
50 }
51
52 public static boolean isGetter(String name) {
53 return name.startsWith("get") && name.length() > 3 || name.startsWith("is") && name.length() > 2;
54 }
55
56 public static boolean isSetter(String name) {
57 return name.startsWith("set") && name.length() > 3;
58 }
59
60 }