Class IfChainToSwitch
java.lang.Object
com.google.errorprone.bugpatterns.BugChecker
com.google.errorprone.bugpatterns.IfChainToSwitch
- All Implemented Interfaces:
BugChecker.IfTreeMatcher, Suppressible, Serializable
Checks for chains of if statements that may be converted to a switch.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class BugChecker
BugChecker.AnnotatedTypeTreeMatcher, BugChecker.AnnotationTreeMatcher, BugChecker.ArrayAccessTreeMatcher, BugChecker.ArrayTypeTreeMatcher, BugChecker.AssertTreeMatcher, BugChecker.AssignmentTreeMatcher, BugChecker.BinaryTreeMatcher, BugChecker.BindingPatternTreeMatcher, BugChecker.BlockTreeMatcher, BugChecker.BreakTreeMatcher, BugChecker.CaseTreeMatcher, BugChecker.CatchTreeMatcher, BugChecker.ClassTreeMatcher, BugChecker.CompilationUnitTreeMatcher, BugChecker.CompoundAssignmentTreeMatcher, BugChecker.ConditionalExpressionTreeMatcher, BugChecker.ConstantCaseLabelTreeMatcher, BugChecker.ContinueTreeMatcher, BugChecker.DeconstructionPatternTreeMatcher, BugChecker.DefaultCaseLabelTreeMatcher, BugChecker.DoWhileLoopTreeMatcher, BugChecker.EmptyStatementTreeMatcher, BugChecker.EnhancedForLoopTreeMatcher, BugChecker.ExportsTreeMatcher, BugChecker.ExpressionStatementTreeMatcher, BugChecker.ForLoopTreeMatcher, BugChecker.IdentifierTreeMatcher, BugChecker.IfTreeMatcher, BugChecker.ImportTreeMatcher, BugChecker.InstanceOfTreeMatcher, BugChecker.IntersectionTypeTreeMatcher, BugChecker.LabeledStatementTreeMatcher, BugChecker.LambdaExpressionTreeMatcher, BugChecker.LiteralTreeMatcher, BugChecker.MemberReferenceTreeMatcher, BugChecker.MemberSelectTreeMatcher, BugChecker.MethodInvocationTreeMatcher, BugChecker.MethodTreeMatcher, BugChecker.ModifiersTreeMatcher, BugChecker.ModuleTreeMatcher, BugChecker.NewArrayTreeMatcher, BugChecker.NewClassTreeMatcher, BugChecker.OpensTreeMatcher, BugChecker.PackageTreeMatcher, BugChecker.ParameterizedTypeTreeMatcher, BugChecker.ParenthesizedTreeMatcher, BugChecker.PatternCaseLabelTreeMatcher, BugChecker.PrimitiveTypeTreeMatcher, BugChecker.ProvidesTreeMatcher, BugChecker.RequiresTreeMatcher, BugChecker.ReturnTreeMatcher, BugChecker.SuppressibleTreePathScanner<R,P>, BugChecker.SwitchExpressionTreeMatcher, BugChecker.SwitchTreeMatcher, BugChecker.SynchronizedTreeMatcher, BugChecker.ThrowTreeMatcher, BugChecker.TryTreeMatcher, BugChecker.TypeCastTreeMatcher, BugChecker.TypeParameterTreeMatcher, BugChecker.UnaryTreeMatcher, BugChecker.UnionTypeTreeMatcher, BugChecker.UsesTreeMatcher, BugChecker.VariableTreeMatcher, BugChecker.WhileLoopTreeMatcher, BugChecker.WildcardTreeMatcher, BugChecker.YieldTreeMatcher -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable com.sun.tools.javac.code.TypeintersectTypes(com.sun.tools.javac.code.Type type1, com.sun.tools.javac.code.Type type2, VisitorState state) Finds the intersection of two types, ornullif there is no such intersection.static booleanisDominatedBy(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.matchIf(IfTree ifTree, VisitorState visitorState) static booleanneedsBracesForArrowRhs(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`.Methods inherited from class BugChecker
allNames, buildDescription, buildDescription, buildDescription, buildDescription, canonicalName, customSuppressionAnnotations, defaultSeverity, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, describeMatch, disableable, equals, hashCode, isSuppressed, isSuppressed, linkUrl, message, supportsSuppressWarnings, suppressedByAnyOf, suppressedRegionsMethods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Suppressible
allNames, canonicalName, customSuppressionAnnotations, supportsSuppressWarnings, suppressedByAnyOf
-
Method Details
-
matchIf
- Specified by:
matchIfin interfaceBugChecker.IfTreeMatcher
-
needsBracesForArrowRhs
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, ornullif 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 noIntersectionTypeTree) 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.
-