Skip to content

Commit

Permalink
openrewrite#141 re-order static member
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin0x90 committed Oct 16, 2023
1 parent 1c005f4 commit b66f1cb
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {

private static class LombokValueToRecordVisitor extends JavaIsoVisitor<ExecutionContext> {

private static final Pattern LOMBOK_ANNOTATION_PATTERN = Pattern.compile("^lombok.*");

private static final JavaTemplate TO_STRING_TEMPLATE = JavaTemplate
.builder("@Override public String toString() { return \"#{}(\" +\n#{}\n\")\"; }")
.contextSensitive()
Expand Down Expand Up @@ -214,15 +216,6 @@ public J.ClassDeclaration visitClassDeclaration(final J.ClassDeclaration cd, fin
return maybeAutoFormat(cd, classDeclaration, ctx);
}

private static boolean isRelevantClass(final J.ClassDeclaration classDeclaration) {
return !isRecord(classDeclaration)
&& hasOnlyLombokValueAnnotation(classDeclaration)
&& !hasGenericTypeParameter(classDeclaration)
&& !hasExplicitMethods(classDeclaration)
&& !hasExplicitConstructor(classDeclaration)
&& classDeclaration.getType() != null;
}

private J.ClassDeclaration addExactToStringMethod(final J.ClassDeclaration classDeclaration,
final List<J.VariableDeclarations> memberVariables) {
return classDeclaration.withBody(TO_STRING_TEMPLATE
Expand All @@ -232,6 +225,15 @@ private J.ClassDeclaration addExactToStringMethod(final J.ClassDeclaration class
memberVariablesToString(getMemberVariableNames(memberVariables))));
}

private static boolean isRelevantClass(final J.ClassDeclaration classDeclaration) {
return !isRecord(classDeclaration)
&& hasOnlyLombokValueAnnotation(classDeclaration)
&& !hasGenericTypeParameter(classDeclaration)
&& !hasExplicitMethods(classDeclaration)
&& !hasExplicitConstructor(classDeclaration)
&& classDeclaration.getType() != null;
}

private static String memberVariablesToString(final Set<String> memberVariables) {
return memberVariables
.stream()
Expand Down Expand Up @@ -336,8 +338,6 @@ private static boolean hasMemberVariableAssignments(final List<J.VariableDeclara
.anyMatch(J.Literal.class::isInstance);
}

private static final Pattern LOMBOK_ANNOTATION_PATTERN = Pattern.compile("^lombok.*");

private static boolean hasOnlyLombokValueAnnotation(final J.ClassDeclaration cd) {
return cd.getAllAnnotations()
.stream()
Expand Down

0 comments on commit b66f1cb

Please sign in to comment.