Skip to content

Commit b2ac7d2

Browse files
committed
2 parents bd4bef4 + c797bc1 commit b2ac7d2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/main/java/com/bruce/intellijplugin/generatesetter/actions/GenerateAllSetterBase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
public abstract class GenerateAllSetterBase extends PsiElementBaseIntentionAction {
4545
public static final String IS = "is";
4646
public static final String GET = "get";
47+
private static final String SET_SETTER_PREFIX = "set";
48+
private static final String WITH_SETTER_PREFIX = "with";
4749
private final GenerateAllHandler generateAllHandler;
4850

4951
public GenerateAllSetterBase(GenerateAllHandler generateAllHandler) {
@@ -245,8 +247,14 @@ private String generateStringForParam(String generateName,
245247
StringBuilder builder = new StringBuilder();
246248
builder.append(splitText);
247249
for (PsiMethod method : methodList) {
248-
if (method.getName().startsWith("set")) {
249-
String fieldToLower = method.getName().substring(3)
250+
String setterMethodNamePrefix =
251+
method.getName().startsWith(SET_SETTER_PREFIX)
252+
? SET_SETTER_PREFIX
253+
: method.getName().startsWith(WITH_SETTER_PREFIX)
254+
? WITH_SETTER_PREFIX
255+
: null;
256+
if (setterMethodNamePrefix != null) {
257+
String fieldToLower = method.getName().substring(setterMethodNamePrefix.length())
250258
.toLowerCase();
251259
PsiMethod s = info.getNameToMethodMap().get(fieldToLower);
252260
if (s != null) {

src/main/java/com/bruce/intellijplugin/generatesetter/utils/PsiClassUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public static boolean isNotSystemClass(PsiClass psiClass) {
4040
}
4141

4242
public static boolean isValidSetMethod(PsiMethod m) {
43-
return m.hasModifierProperty("public") && !m.hasModifierProperty("static") && m.getName().startsWith("set");
43+
return m.hasModifierProperty("public") &&
44+
!m.hasModifierProperty("static") &&
45+
(m.getName().startsWith("set") || m.getName().startsWith("with"));
4446
}
4547

4648
public static boolean isValidGetMethod(PsiMethod m) {

0 commit comments

Comments
 (0)