Class SimplifyBooleanExpressionVisitor

java.lang.Object
org.openrewrite.TreeVisitor<org.openrewrite.java.tree.J,P>
org.openrewrite.java.JavaVisitor<org.openrewrite.ExecutionContext>
org.openrewrite.java.cleanup.SimplifyBooleanExpressionVisitor

public class SimplifyBooleanExpressionVisitor extends JavaVisitor<org.openrewrite.ExecutionContext>
  • Constructor Details

    • SimplifyBooleanExpressionVisitor

      public SimplifyBooleanExpressionVisitor()
  • Method Details

    • visitBinary

      public org.openrewrite.java.tree.J visitBinary(org.openrewrite.java.tree.J.Binary binary, org.openrewrite.ExecutionContext ctx)
      Overrides:
      visitBinary in class JavaVisitor<org.openrewrite.ExecutionContext>
    • visitParentheses

      public <T extends org.openrewrite.java.tree.J> org.openrewrite.java.tree.J visitParentheses(org.openrewrite.java.tree.J.Parentheses<T> parens, org.openrewrite.ExecutionContext ctx)
      Overrides:
      visitParentheses in class JavaVisitor<org.openrewrite.ExecutionContext>
    • visitUnary

      public org.openrewrite.java.tree.J visitUnary(org.openrewrite.java.tree.J.Unary unary, org.openrewrite.ExecutionContext ctx)
      Overrides:
      visitUnary in class JavaVisitor<org.openrewrite.ExecutionContext>
    • visitMethodInvocation

      public org.openrewrite.java.tree.J visitMethodInvocation(org.openrewrite.java.tree.J.MethodInvocation method, org.openrewrite.ExecutionContext executionContext)
      Overrides:
      visitMethodInvocation in class JavaVisitor<org.openrewrite.ExecutionContext>
    • shouldSimplifyEqualsOn

      protected boolean shouldSimplifyEqualsOn(org.openrewrite.java.tree.J j)
      Override this method to disable simplification of equals expressions, specifically for Kotlin while that is not yet part of the OpenRewrite/rewrite.

      Comparing Kotlin nullable type `?` with tree/false can not be simplified, e.g. `X?.fun() == true` is not equivalent to `X?.fun()`

      Subclasses will want to check if the `org.openrewrite.kotlin.marker.IsNullSafe` marker is present.

      Parameters:
      j - the expression to simplify
      Returns:
      true by default, unless overridden