Class IfChainToSwitch

java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.IfChainToSwitch
All Implemented Interfaces:
BugChecker.IfTreeMatcher, Suppressible, Serializable

public final class IfChainToSwitch extends BugChecker implements BugChecker.IfTreeMatcher
Checks for chains of if statements that may be converted to a switch.
See Also:
  • Method Details

    • matchIf

      public Description matchIf(IfTree ifTree, VisitorState visitorState)
      Specified by:
      matchIf in interface BugChecker.IfTreeMatcher
    • needsBracesForArrowRhs

      public static boolean needsBracesForArrowRhs(StatementTree statementTree)
      Determines whether the given statement tree needs to be wrapped in braces when used on the right hand side of the arrow of a `case`.
    • intersectTypes

      public static @Nullable com.sun.tools.javac.code.Type intersectTypes(com.sun.tools.javac.code.Type type1, com.sun.tools.javac.code.Type type2, VisitorState state)
      Finds the intersection of two types, or null if there is no such intersection. This is not quite the same thing as the "Intersection Types" defined JLS 21 § 4.9 (it is not a distinct type; there is no IntersectionTypeTree) although they are similar in that the (non-null) return value can be assigned to both types.
    • isDominatedBy

      public static boolean isDominatedBy(com.google.errorprone.bugpatterns.IfChainToSwitch.CaseIr lhs, com.google.errorprone.bugpatterns.IfChainToSwitch.CaseIr rhs, VisitorState state, ExpressionTree subject)
      Compute whether the RHS is dominated by the LHS.

      Domination refers to the notion of "is dominated" defined in e.g. JLS 21 § 14.11.1. Note that this method does not support record types, which simplifies implementation.