Skip to content

Commit

Permalink
Resolve compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Dec 15, 2024
1 parent 989d7c9 commit 6fd95b7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
68 changes: 36 additions & 32 deletions src/main/java/org/openrewrite/java/migrate/lombok/LombokUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,6 @@ static boolean isGetter(J.MethodDeclaration method) {
return false;
}

private static boolean hasMatchingTypeAndName(J.MethodDeclaration method, @Nullable JavaType type, String simpleName) {
if (method.getType() == type) {
String deriveGetterMethodName = deriveGetterMethodName(type, simpleName);
return method.getSimpleName().equals(deriveGetterMethodName);
}
return false;
}

private static String deriveGetterMethodName(@Nullable JavaType type, String fieldName) {
if (type == JavaType.Primitive.Boolean) {
boolean alreadyStartsWithIs = fieldName.length() >= 3 &&
fieldName.substring(0, 3).matches("is[A-Z]");
if (alreadyStartsWithIs) {
return fieldName;
} else {
return "is" + StringUtils.capitalize(fieldName);
}
}
return "get" + StringUtils.capitalize(fieldName);
}

static AccessLevel getAccessLevel(J.MethodDeclaration modifiers) {
if (modifiers.hasModifier(Public)) {
return PUBLIC;
} else if (modifiers.hasModifier(Protected)) {
return PROTECTED;
} else if (modifiers.hasModifier(Private)) {
return PRIVATE;
}
return PACKAGE;
}

static boolean isEffectivelySetter(J.MethodDeclaration method) {
boolean isVoid = "void".equals(method.getType().toString());
List<Statement> actualParameters = method.getParameters().stream()
Expand Down Expand Up @@ -131,4 +99,40 @@ static boolean isEffectivelySetter(J.MethodDeclaration method) {
param.getType().equals(fieldAccess.getType());

}

private static boolean hasMatchingTypeAndName(J.MethodDeclaration method, @Nullable JavaType type, String simpleName) {
if (method.getType() == type) {
String deriveGetterMethodName = deriveGetterMethodName(type, simpleName);
return method.getSimpleName().equals(deriveGetterMethodName);
}
return false;
}

private static String deriveGetterMethodName(@Nullable JavaType type, String fieldName) {
if (type == JavaType.Primitive.Boolean) {
boolean alreadyStartsWithIs = fieldName.length() >= 3 &&
fieldName.substring(0, 3).matches("is[A-Z]");
if (alreadyStartsWithIs) {
return fieldName;
} else {
return "is" + StringUtils.capitalize(fieldName);
}
}
return "get" + StringUtils.capitalize(fieldName);
}

static String deriveSetterMethodName(JavaType.Variable fieldType) {
return "set" + StringUtils.capitalize(fieldType.getName());
}

static AccessLevel getAccessLevel(J.MethodDeclaration methodDeclaration) {
if (methodDeclaration.hasModifier(Public)) {
return PUBLIC;
} else if (methodDeclaration.hasModifier(Protected)) {
return PROTECTED;
} else if (methodDeclaration.hasModifier(Private)) {
return PRIVATE;
}
return PACKAGE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
boolean nameMatch = method.getSimpleName().equals(LombokUtils.deriveSetterMethodName(fieldType));
if (nameMatch) {
Set<Finding> set = getCursor().getNearestMessage(FIELDS_TO_DECORATE_KEY);
set.add(new Finding(fieldType.getName(), LombokUtils.getAccessLevel(method.getModifiers())));
set.add(new Finding(fieldType.getName(), LombokUtils.getAccessLevel(method)));
return null; //delete
}
}
Expand Down

0 comments on commit 6fd95b7

Please sign in to comment.