|
1 | 1 | /******************************************************************************* |
2 | | - * Copyright (c) 2016-2017 Red Hat, Inc. |
| 2 | + * Copyright (c) 2016, 2024 Red Hat, Inc. |
3 | 3 | * All rights reserved. This program and the accompanying materials |
4 | 4 | * are made available under the terms of the Eclipse Public License 2.0 |
5 | 5 | * which accompanies this distribution, and is available at |
|
28 | 28 | import java.util.Collections; |
29 | 29 | import java.util.List; |
30 | 30 | import java.util.Map; |
| 31 | +import java.util.stream.Collectors; |
31 | 32 |
|
32 | 33 | public class JDTUtils { |
33 | 34 | // Percent encoding obtained from: https://en.wikipedia.org/wiki/Percent-encoding#Reserved_characters |
34 | 35 | private static final String LEVEL1_URI_REGEX = "(?:\\/(?:(?:\\{(\\w|-|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+\\})|(?:(\\w|%20|%21|%23|%24|%25|%26|%27|%28|%29|%2A|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40|%5B|%5D)+)))*\\/?"; |
35 | 36 |
|
| 37 | + // Unmodifiable list of accessor prefixes |
| 38 | + private static final List<String> ACCESSOR_PREFIXES = List.of("get", "set", "is"); |
| 39 | + |
36 | 40 | /** |
37 | 41 | * Check if a URI starts with a leading slash. |
38 | 42 | * |
@@ -66,11 +70,8 @@ public static boolean isValidLevel1URI(String uriString) { |
66 | 70 | public static List<PsiMethod> getFieldAccessors(PsiJavaFile unit, PsiField field) { |
67 | 71 | List<PsiMethod> accessors = new ArrayList<PsiMethod>(); |
68 | 72 | String fieldName = field.getName(); |
69 | | - fieldName = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
70 | | - List<String> accessorNames = new ArrayList<String>(); |
71 | | - accessorNames.add("get" + fieldName); |
72 | | - accessorNames.add("set" + fieldName); |
73 | | - accessorNames.add("is" + fieldName); |
| 73 | + String accessorSuffix = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); |
| 74 | + List<String> accessorNames = ACCESSOR_PREFIXES.stream().map(s -> s + accessorSuffix).collect(Collectors.toList()); |
74 | 75 |
|
75 | 76 | for (PsiClass type : unit.getClasses()) { |
76 | 77 | for (PsiMethod method : type.getMethods()) { |
|
0 commit comments