diff --git a/src/main/java/io/github/timoa/lombok/ConvertNoArgsConstructor.java b/src/main/java/io/github/timoa/lombok/ConvertNoArgsConstructor.java index 823ccd4..bd5ae5d 100644 --- a/src/main/java/io/github/timoa/lombok/ConvertNoArgsConstructor.java +++ b/src/main/java/io/github/timoa/lombok/ConvertNoArgsConstructor.java @@ -41,8 +41,8 @@ public String getDisplayName() { @Override public String getDescription() { //language=markdown - return "Prefer the lombok annotation `@NoArgsConstructor` over explicitly written out constructors.\n" - + "This recipe does not create annotations for implicit constructors."; + return "Prefer the lombok annotation `@NoArgsConstructor` over explicitly written out constructors.\n" + + "This recipe does not create annotations for implicit constructors."; } @Override @@ -66,11 +66,9 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex AccessLevel accessLevel = LombokUtils.getAccessLevel(message.getModifiers()); - J.ClassDeclaration annotatedClass = getAnnotation(accessLevel).apply( + return getAnnotation(accessLevel).apply( updateCursor(classDeclAfterVisit), classDeclAfterVisit.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName))); - - return annotatedClass; } private JavaTemplate getAnnotation(AccessLevel accessLevel) { diff --git a/src/main/java/io/github/timoa/lombok/ConvertSetter.java b/src/main/java/io/github/timoa/lombok/ConvertSetter.java index fc88ee6..ce35e65 100644 --- a/src/main/java/io/github/timoa/lombok/ConvertSetter.java +++ b/src/main/java/io/github/timoa/lombok/ConvertSetter.java @@ -145,8 +145,9 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m } //we only want to annotate fields and not e.g. method parameters, so we require a lass declaration to be close in the cursor. - if (getCursor().getPathAsStream().limit(4).noneMatch(e -> e instanceof J.ClassDeclaration)) + if (getCursor().getPathAsStream().limit( 4 ).noneMatch( e -> e instanceof J.ClassDeclaration )) { return multiVariable; + } J.VariableDeclarations.NamedVariable variable = multiVariable.getVariables().get(0); Optional field = fieldsToDecorate.stream() @@ -165,7 +166,6 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m multiVariable.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName))); maybeAddImport("lombok.Setter"); maybeAddImport("lombok.AccessLevel"); - System.out.println("annotating " + variable); return annotated; } } diff --git a/src/main/java/io/github/timoa/lombok/LombokUtils.java b/src/main/java/io/github/timoa/lombok/LombokUtils.java index 6496776..82cde97 100644 --- a/src/main/java/io/github/timoa/lombok/LombokUtils.java +++ b/src/main/java/io/github/timoa/lombok/LombokUtils.java @@ -21,7 +21,7 @@ public class LombokUtils { public static boolean isEffectivelyGetter(J.MethodDeclaration method) { boolean takesNoParameters = method.getParameters().get(0) instanceof J.Empty; boolean singularReturn = method.getBody() != null //abstract methods can be null - && method.getBody().getStatements().size() == 1 + && method.getBody().getStatements().size() == 1 // && method.getBody().getStatements().get(0) instanceof J.Return; if (takesNoParameters && singularReturn) { @@ -30,8 +30,7 @@ public static boolean isEffectivelyGetter(J.MethodDeclaration method) { if (returnExpression instanceof J.Identifier) { J.Identifier identifier = (J.Identifier) returnExpression; JavaType.Variable fieldType = identifier.getFieldType(); - boolean typeMatch = method.getType().equals(fieldType.getType()); - return typeMatch; + return method.getType().equals(fieldType.getType()); //type match } } return false; @@ -51,7 +50,7 @@ public static boolean isEffectivelySetter(J.MethodDeclaration method) { String paramName = param.getName().toString(); boolean singularStatement = method.getBody() != null //abstract methods can be null - && method.getBody().getStatements().size() == 1 + && method.getBody().getStatements().size() == 1 // && method.getBody().getStatements().get(0) instanceof J.Assignment; if (!singularStatement) { @@ -75,8 +74,7 @@ public static String deriveGetterMethodName(JavaType.Variable fieldType) { final String fieldName = fieldType.getName(); - boolean alreadyStartsWithIs = fieldName.length() >= 3 - && fieldName.substring(0, 3).matches("is[A-Z]"); + boolean alreadyStartsWithIs = fieldName.length() >= 3 && fieldName.substring(0, 3).matches("is[A-Z]"); if (isPrimitiveBoolean) if (alreadyStartsWithIs) diff --git a/src/main/java/io/github/timoa/lombok/NegligentlyConvertEquals.java b/src/main/java/io/github/timoa/lombok/NegligentlyConvertEquals.java index d54c37a..3094427 100644 --- a/src/main/java/io/github/timoa/lombok/NegligentlyConvertEquals.java +++ b/src/main/java/io/github/timoa/lombok/NegligentlyConvertEquals.java @@ -20,7 +20,10 @@ import org.openrewrite.ExecutionContext; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; -import org.openrewrite.java.*; +import org.openrewrite.java.JavaIsoVisitor; +import org.openrewrite.java.JavaParser; +import org.openrewrite.java.JavaTemplate; +import org.openrewrite.java.MethodMatcher; import org.openrewrite.java.tree.J; import static java.util.Comparator.comparing; diff --git a/src/main/java/io/github/timoa/lombok/NormalizeGetter.java b/src/main/java/io/github/timoa/lombok/NormalizeGetter.java index dbb5d28..cb46639 100644 --- a/src/main/java/io/github/timoa/lombok/NormalizeGetter.java +++ b/src/main/java/io/github/timoa/lombok/NormalizeGetter.java @@ -18,8 +18,8 @@ import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.*; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.*; import org.openrewrite.java.tree.*; @@ -155,12 +155,12 @@ public TreeVisitor getVisitor(MethodAcc acc) { return new TreeVisitor() { @Override - public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext executionContext) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { for (RenameRecord rr : acc.renameRecords) { String methodPattern = String.format("%s %s()", rr.pathToClass_, rr.methodName_); tree = new ChangeMethodName(methodPattern, rr.newMethodName_, true, null) - .getVisitor().visit(tree, executionContext); + .getVisitor().visit(tree, ctx); } return tree; } diff --git a/src/main/java/io/github/timoa/lombok/NormalizeSetter.java b/src/main/java/io/github/timoa/lombok/NormalizeSetter.java index 5c4d4ce..e828792 100644 --- a/src/main/java/io/github/timoa/lombok/NormalizeSetter.java +++ b/src/main/java/io/github/timoa/lombok/NormalizeSetter.java @@ -18,11 +18,11 @@ import lombok.EqualsAndHashCode; import lombok.RequiredArgsConstructor; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.ScanningRecipe; import org.openrewrite.Tree; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.ChangeMethodName; import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.tree.J; @@ -166,12 +166,12 @@ public TreeVisitor getVisitor(MethodAcc acc) { return new TreeVisitor() { @Override - public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext executionContext) { + public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { for (RenameRecord rr : acc.renameRecords) { String methodPattern = String.format("%s %s(%s)", rr.pathToClass_, rr.methodName_, rr.parameterType_); tree = new ChangeMethodName(methodPattern, rr.newMethodName_, true, null) - .getVisitor().visit(tree, executionContext); + .getVisitor().visit(tree, ctx); } return tree; } diff --git a/src/main/java/io/github/timoa/lombok/SummarizeData.java b/src/main/java/io/github/timoa/lombok/SummarizeData.java index 61d9924..d22b81a 100644 --- a/src/main/java/io/github/timoa/lombok/SummarizeData.java +++ b/src/main/java/io/github/timoa/lombok/SummarizeData.java @@ -18,7 +18,6 @@ import lombok.EqualsAndHashCode; import lombok.Value; import org.openrewrite.ExecutionContext; -import org.openrewrite.NlsRewrite; import org.openrewrite.Recipe; import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaIsoVisitor; @@ -36,12 +35,12 @@ @EqualsAndHashCode(callSuper = false) public class SummarizeData extends Recipe { @Override - public @NlsRewrite.DisplayName String getDisplayName() { + public String getDisplayName() { return "Summarize class annotations into @Data"; } @Override - public @NlsRewrite.Description String getDescription() { + public String getDescription() { return "Summarize class annotations into @Data."; } @@ -63,6 +62,7 @@ private static class Summarizer extends JavaIsoVisitor { "RequiredArgsConstructor") .collect(Collectors.toSet()); + @Override public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { J.ClassDeclaration visited = super.visitClassDeclaration(classDecl, ctx); diff --git a/src/main/java/io/github/timoa/lombok/SummarizeGetter.java b/src/main/java/io/github/timoa/lombok/SummarizeGetter.java index 11c0ff6..1fb9b33 100644 --- a/src/main/java/io/github/timoa/lombok/SummarizeGetter.java +++ b/src/main/java/io/github/timoa/lombok/SummarizeGetter.java @@ -23,7 +23,6 @@ import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; -import org.openrewrite.java.TreeVisitingPrinter; import org.openrewrite.java.tree.J; import static java.util.Comparator.comparing; diff --git a/src/main/java/io/github/timoa/lombok/SummarizeSetter.java b/src/main/java/io/github/timoa/lombok/SummarizeSetter.java index 13be265..aa83d7b 100644 --- a/src/main/java/io/github/timoa/lombok/SummarizeSetter.java +++ b/src/main/java/io/github/timoa/lombok/SummarizeSetter.java @@ -23,7 +23,6 @@ import org.openrewrite.java.JavaIsoVisitor; import org.openrewrite.java.JavaParser; import org.openrewrite.java.JavaTemplate; -import org.openrewrite.java.TreeVisitingPrinter; import org.openrewrite.java.tree.J; import static java.util.Comparator.comparing; diff --git a/src/main/java/io/github/timoa/lombok/log/ConvertCommons.java b/src/main/java/io/github/timoa/lombok/log/ConvertCommons.java index e0a6106..665cded 100644 --- a/src/main/java/io/github/timoa/lombok/log/ConvertCommons.java +++ b/src/main/java/io/github/timoa/lombok/log/ConvertCommons.java @@ -17,10 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaTemplate; @Value diff --git a/src/main/java/io/github/timoa/lombok/log/ConvertJBoss.java b/src/main/java/io/github/timoa/lombok/log/ConvertJBoss.java index 7e9f0df..dc6da38 100644 --- a/src/main/java/io/github/timoa/lombok/log/ConvertJBoss.java +++ b/src/main/java/io/github/timoa/lombok/log/ConvertJBoss.java @@ -17,10 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaTemplate; @Value diff --git a/src/main/java/io/github/timoa/lombok/log/ConvertLog4j2.java b/src/main/java/io/github/timoa/lombok/log/ConvertLog4j2.java index 4dbc9d6..7e877e3 100644 --- a/src/main/java/io/github/timoa/lombok/log/ConvertLog4j2.java +++ b/src/main/java/io/github/timoa/lombok/log/ConvertLog4j2.java @@ -17,10 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaTemplate; @Value diff --git a/src/main/java/io/github/timoa/lombok/log/ConvertSlf4j.java b/src/main/java/io/github/timoa/lombok/log/ConvertSlf4j.java index 5398bda..f806260 100644 --- a/src/main/java/io/github/timoa/lombok/log/ConvertSlf4j.java +++ b/src/main/java/io/github/timoa/lombok/log/ConvertSlf4j.java @@ -17,10 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaTemplate; @Value diff --git a/src/main/java/io/github/timoa/lombok/log/ConvertUtilLog.java b/src/main/java/io/github/timoa/lombok/log/ConvertUtilLog.java index 619751d..df3da7d 100644 --- a/src/main/java/io/github/timoa/lombok/log/ConvertUtilLog.java +++ b/src/main/java/io/github/timoa/lombok/log/ConvertUtilLog.java @@ -17,10 +17,10 @@ import lombok.EqualsAndHashCode; import lombok.Value; +import org.jspecify.annotations.Nullable; import org.openrewrite.ExecutionContext; import org.openrewrite.Option; import org.openrewrite.TreeVisitor; -import org.openrewrite.internal.lang.Nullable; import org.openrewrite.java.JavaTemplate; @Value diff --git a/src/main/java/io/github/timoa/lombok/log/LogVisitor.java b/src/main/java/io/github/timoa/lombok/log/LogVisitor.java index 311403b..13b8979 100644 --- a/src/main/java/io/github/timoa/lombok/log/LogVisitor.java +++ b/src/main/java/io/github/timoa/lombok/log/LogVisitor.java @@ -47,10 +47,9 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex } switchImports(); - J.ClassDeclaration annotatedClass = getLombokTemplate().apply( + return getLombokTemplate().apply( updateCursor(visitClassDeclaration), visitClassDeclaration.getCoordinates().addAnnotation(comparing(J.Annotation::getSimpleName))); - return annotatedClass; } protected abstract JavaTemplate getLombokTemplate(); diff --git a/src/main/java/io/github/timoa/misc/NormalizeBigDecimalCreation.java b/src/main/java/io/github/timoa/misc/NormalizeBigDecimalCreation.java index 4d1da01..5b72654 100644 --- a/src/main/java/io/github/timoa/misc/NormalizeBigDecimalCreation.java +++ b/src/main/java/io/github/timoa/misc/NormalizeBigDecimalCreation.java @@ -2,9 +2,9 @@ import lombok.EqualsAndHashCode; import lombok.Value; -import org.openrewrite.*; -import org.openrewrite.NlsRewrite.Description; -import org.openrewrite.NlsRewrite.DisplayName; +import org.openrewrite.ExecutionContext; +import org.openrewrite.Recipe; +import org.openrewrite.TreeVisitor; import org.openrewrite.java.JavaTemplate; import org.openrewrite.java.JavaVisitor; import org.openrewrite.java.MethodMatcher; @@ -14,16 +14,16 @@ import java.util.StringJoiner; @Value -@EqualsAndHashCode(callSuper = true) +@EqualsAndHashCode(callSuper = false) public class NormalizeBigDecimalCreation extends Recipe { @Override - public @DisplayName String getDisplayName() { + public String getDisplayName() { return "Use Strings for BigDecimal instantiation"; } @Override - public @Description String getDescription() { + public String getDescription() { return new StringJoiner("\n") .add("Converts BigDecimal instantiation with a double literal to instantiation with a String. ") .add("CAUTION: This Recipe can change semantics. ") diff --git a/src/main/java/io/github/timoa/misc/UseRanges.java b/src/main/java/io/github/timoa/misc/UseRanges.java index f2c4e01..591a900 100644 --- a/src/main/java/io/github/timoa/misc/UseRanges.java +++ b/src/main/java/io/github/timoa/misc/UseRanges.java @@ -20,10 +20,10 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.UseImportPolicy; -import java.time.LocalDate; import org.openrewrite.java.template.RecipeDescriptor; import java.math.BigDecimal; +import java.time.LocalDate; @RecipeDescriptor( name = "Use Guava Ranges", @@ -71,6 +71,7 @@ boolean after(BigDecimal from, BigDecimal candidate, BigDecimal to) { return Range.closed(from, to).contains(candidate); } } + @RecipeDescriptor( name = "Replace `from.compareTo(candidate) < 0 && candidate.compareTo(to) < 0` with a guava `Range.open(from, to).contains(candidate)`", description = "Replace a hand crafted range check for membership in an open interval ( candidate € (from, to) ) with a guava range expression`." @@ -152,6 +153,7 @@ boolean after(BigDecimal from, BigDecimal candidate, BigDecimal to) { return Range.closedOpen(from, to).contains(candidate); } } + @RecipeDescriptor( name = "Replace `from.compareTo(candidate) < 0 && candidate.compareTo(to) <= 0` with a guava `Range.openClosed(from, to).contains(candidate)`", description = "Replace a hand crafted range check for membership in an interval that is open to the left ( candidate € (from, to] ) with a guava range expression`." @@ -233,6 +235,7 @@ boolean after(LocalDate from, LocalDate candidate, LocalDate to) { return Range.closed(from, to).contains(candidate); } } + @RecipeDescriptor( name = "Replace `from.compareTo(candidate) < 0 && candidate.compareTo(to) < 0` with a guava `Range.open(from, to).contains(candidate)`", description = "Replace a hand crafted range check for membership in an open interval ( candidate € (from, to) ) with a guava range expression`." @@ -314,6 +317,7 @@ boolean after(LocalDate from, LocalDate candidate, LocalDate to) { return Range.closedOpen(from, to).contains(candidate); } } + @RecipeDescriptor( name = "Replace `from.compareTo(candidate) < 0 && candidate.compareTo(to) <= 0` with a guava `Range.openClosed(from, to).contains(candidate)`", description = "Replace a hand crafted range check for membership in an interval that is open to the left ( candidate € (from, to] ) with a guava range expression`." @@ -357,4 +361,4 @@ boolean after(LocalDate from, LocalDate candidate, LocalDate to) { -} \ No newline at end of file +} diff --git a/src/test/java/io/github/timoa/lombok/log/ConvertAnyLogTest.java b/src/test/java/io/github/timoa/lombok/log/ConvertAnyLogTest.java index 269f6fc..f6c1bf1 100644 --- a/src/test/java/io/github/timoa/lombok/log/ConvertAnyLogTest.java +++ b/src/test/java/io/github/timoa/lombok/log/ConvertAnyLogTest.java @@ -8,7 +8,7 @@ import static org.openrewrite.java.Assertions.java; -public class ConvertAnyLogTest implements RewriteTest { +class ConvertAnyLogTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { diff --git a/src/test/java/io/github/timoa/misc/NormalizeBigDecimalCreationTest.java b/src/test/java/io/github/timoa/misc/NormalizeBigDecimalCreationTest.java index 218ddc0..c3a052d 100644 --- a/src/test/java/io/github/timoa/misc/NormalizeBigDecimalCreationTest.java +++ b/src/test/java/io/github/timoa/misc/NormalizeBigDecimalCreationTest.java @@ -8,7 +8,7 @@ import static org.openrewrite.java.Assertions.java; -public class NormalizeBigDecimalCreationTest implements RewriteTest { +class NormalizeBigDecimalCreationTest implements RewriteTest { @Override public void defaults(RecipeSpec spec) { diff --git a/src/test/java/io/github/timoa/misc/UseRangesTest.java b/src/test/java/io/github/timoa/misc/UseRangesTest.java index 9757803..41fd359 100644 --- a/src/test/java/io/github/timoa/misc/UseRangesTest.java +++ b/src/test/java/io/github/timoa/misc/UseRangesTest.java @@ -165,4 +165,4 @@ boolean booleanExpression() { ) ); } -} \ No newline at end of file +}