|
22 | 22 |
|
23 | 23 | public class CSharpNamingService implements NamingService {
|
24 | 24 |
|
| 25 | + private static final Pattern STANDARD_METHOD_NAME = Pattern.compile("^[A-Z][a-zA-Z0-9]*$"); |
25 | 26 | private static final Pattern SNAKE_CASE = Pattern.compile("^[a-zA-Z0-9]+_\\w+$");
|
26 | 27 |
|
27 | 28 | @Override
|
28 |
| - public String getMethodName(String oldMethodName) { |
29 |
| - StringBuilder result = new StringBuilder(); |
30 |
| - if (SNAKE_CASE.matcher(oldMethodName).matches()) { |
31 |
| - result.append(NameCaseConvention.format(NameCaseConvention.UPPER_CAMEL, oldMethodName)); |
32 |
| - } else { |
33 |
| - int nameLength = oldMethodName.length(); |
34 |
| - for (int i = 0; i < nameLength; i++) { |
35 |
| - char c = oldMethodName.charAt(i); |
| 29 | + public String standardizeMethodName(String oldMethodName) { |
| 30 | + if (!STANDARD_METHOD_NAME.matcher(oldMethodName).matches()) { |
| 31 | + StringBuilder result = new StringBuilder(); |
| 32 | + if (SNAKE_CASE.matcher(oldMethodName).matches()) { |
| 33 | + result.append(NameCaseConvention.format(NameCaseConvention.UPPER_CAMEL, oldMethodName)); |
| 34 | + } else { |
| 35 | + int nameLength = oldMethodName.length(); |
| 36 | + for (int i = 0; i < nameLength; i++) { |
| 37 | + char c = oldMethodName.charAt(i); |
36 | 38 |
|
37 |
| - if (i == 0) { |
38 |
| - // the java specification requires identifiers to start with [a-zA-Z$_] |
39 |
| - if (c != '$' && c != '_') { |
40 |
| - result.append(Character.toUpperCase(c)); |
41 |
| - } |
42 |
| - } else { |
43 |
| - if (!Character.isLetterOrDigit(c)) { |
44 |
| - while (i < nameLength && (!Character.isLetterOrDigit(c) || c > 'z')) { |
45 |
| - c = oldMethodName.charAt(i++); |
46 |
| - } |
47 |
| - if (i < nameLength) { |
| 39 | + if (i == 0) { |
| 40 | + // the java specification requires identifiers to start with [a-zA-Z$_] |
| 41 | + if (c != '$' && c != '_') { |
48 | 42 | result.append(Character.toUpperCase(c));
|
49 | 43 | }
|
50 | 44 | } else {
|
51 |
| - result.append(c); |
| 45 | + if (!Character.isLetterOrDigit(c)) { |
| 46 | + while (i < nameLength && (!Character.isLetterOrDigit(c) || c > 'z')) { |
| 47 | + c = oldMethodName.charAt(i++); |
| 48 | + } |
| 49 | + if (i < nameLength) { |
| 50 | + result.append(Character.toUpperCase(c)); |
| 51 | + } |
| 52 | + } else { |
| 53 | + result.append(c); |
| 54 | + } |
52 | 55 | }
|
53 | 56 | }
|
54 | 57 | }
|
| 58 | + return result.toString(); |
55 | 59 | }
|
56 |
| - return result.toString(); |
| 60 | + return oldMethodName; |
57 | 61 | }
|
58 | 62 | }
|
0 commit comments