From 767d6837da34fc1a73841fd7eb7fdd05dfa48931 Mon Sep 17 00:00:00 2001 From: Tim te Beek Date: Sat, 19 Aug 2023 19:05:12 +0200 Subject: [PATCH] Revert "SimplifyBooleanExpressionVisitor removed need for UnnecessaryParenthesesVisitor" This reverts commit c752297d03392ac53468149c062575c3a2c498c1. --- .../openrewrite/java/template/RefasterTemplateProcessor.java | 1 + src/test/resources/recipes/MultipleDereferencesRecipes.java | 2 ++ src/test/resources/recipes/NestedPreconditionsRecipe.java | 1 + src/test/resources/recipes/ShouldAddImportsRecipes.java | 3 +++ .../resources/recipes/ShouldSupportNestedClassesRecipes.java | 2 ++ src/test/resources/recipes/UseStringIsEmptyRecipe.java | 1 + 6 files changed, 10 insertions(+) diff --git a/src/main/java/org/openrewrite/java/template/RefasterTemplateProcessor.java b/src/main/java/org/openrewrite/java/template/RefasterTemplateProcessor.java index 87252f57..116b6cc8 100644 --- a/src/main/java/org/openrewrite/java/template/RefasterTemplateProcessor.java +++ b/src/main/java/org/openrewrite/java/template/RefasterTemplateProcessor.java @@ -94,6 +94,7 @@ public class RefasterTemplateProcessor extends AbstractProcessor { static Set DO_AFTER_VISIT = Stream.of( "new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()", + "new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()", "new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()" ).collect(Collectors.toCollection(LinkedHashSet::new)); diff --git a/src/test/resources/recipes/MultipleDereferencesRecipes.java b/src/test/resources/recipes/MultipleDereferencesRecipes.java index 1728be2a..bc109b10 100644 --- a/src/test/resources/recipes/MultipleDereferencesRecipes.java +++ b/src/test/resources/recipes/MultipleDereferencesRecipes.java @@ -58,6 +58,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { JavaTemplate.Matcher matcher; if ((matcher = before.matcher(getCursor())).find()) { doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(0)); } @@ -92,6 +93,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) { JavaTemplate.Matcher matcher; if ((matcher = before.matcher(getCursor())).find()) { doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace()); } diff --git a/src/test/resources/recipes/NestedPreconditionsRecipe.java b/src/test/resources/recipes/NestedPreconditionsRecipe.java index e1fcc381..80a94f74 100644 --- a/src/test/resources/recipes/NestedPreconditionsRecipe.java +++ b/src/test/resources/recipes/NestedPreconditionsRecipe.java @@ -43,6 +43,7 @@ public J visitExpression(Expression elem, ExecutionContext ctx) { maybeRemoveImport("java.util.HashMap"); maybeAddImport("java.util.Hashtable"); doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return hashtable.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); } diff --git a/src/test/resources/recipes/ShouldAddImportsRecipes.java b/src/test/resources/recipes/ShouldAddImportsRecipes.java index b993e43b..fd74e9c6 100644 --- a/src/test/resources/recipes/ShouldAddImportsRecipes.java +++ b/src/test/resources/recipes/ShouldAddImportsRecipes.java @@ -63,6 +63,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { if ((matcher = before.matcher(getCursor())).find()) { maybeAddImport("java.util.Objects"); doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); } @@ -99,6 +100,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { if ((matcher = equals.matcher(getCursor())).find() || (matcher = compareZero.matcher(getCursor())).find()) { maybeRemoveImport("java.util.Objects"); doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return isis.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0), matcher.parameter(1)); } @@ -136,6 +138,7 @@ public J visitMethodInvocation(J.MethodInvocation elem, ExecutionContext ctx) { if ((matcher = before.matcher(getCursor())).find()) { maybeRemoveImport("java.util.Objects.hash"); doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); } diff --git a/src/test/resources/recipes/ShouldSupportNestedClassesRecipes.java b/src/test/resources/recipes/ShouldSupportNestedClassesRecipes.java index 90ffb3a4..086f7302 100644 --- a/src/test/resources/recipes/ShouldSupportNestedClassesRecipes.java +++ b/src/test/resources/recipes/ShouldSupportNestedClassesRecipes.java @@ -58,6 +58,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) { JavaTemplate.Matcher matcher; if ((matcher = before.matcher(getCursor())).find()) { doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); } @@ -92,6 +93,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) { JavaTemplate.Matcher matcher; if ((matcher = before.matcher(getCursor())).find()) { doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); } diff --git a/src/test/resources/recipes/UseStringIsEmptyRecipe.java b/src/test/resources/recipes/UseStringIsEmptyRecipe.java index 893e9e1d..2f300aef 100644 --- a/src/test/resources/recipes/UseStringIsEmptyRecipe.java +++ b/src/test/resources/recipes/UseStringIsEmptyRecipe.java @@ -34,6 +34,7 @@ public J visitBinary(J.Binary elem, ExecutionContext ctx) { JavaTemplate.Matcher matcher; if ((matcher = before.matcher(getCursor())).find()) { doAfterVisit(new org.openrewrite.java.ShortenFullyQualifiedTypeReferences().getVisitor()); + doAfterVisit(new org.openrewrite.java.cleanup.UnnecessaryParenthesesVisitor()); doAfterVisit(new org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor()); return after.apply(getCursor(), elem.getCoordinates().replace(), matcher.parameter(0)); }