File tree Expand file tree Collapse file tree
java/ql/lib/semmle/code/java Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -513,23 +513,20 @@ private module Input implements InputSig1, InputSig2 {
513513 )
514514 }
515515
516+ /** Holds if this switch must be exhaustive. */
517+ predicate isExhaustive ( Ast:: Switch switch ) {
518+ // Switch expressions and enhanced switch blocks (those that use pattern
519+ // cases or match null) must be exhaustive.
520+ // See https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-14.11.2
521+ switch instanceof SwitchExpr or
522+ exists ( switch .( SwitchStmt ) .getAPatternCase ( ) ) or
523+ switch .( SwitchStmt ) .hasNullCase ( )
524+ }
525+
516526 /** Holds if this case matches all possible values. */
517527 predicate matchAll ( Ast:: Case c ) {
518528 c instanceof DefaultCase
519529 or
520- // Switch expressions and enhanced switch blocks (those that use pattern
521- // cases or match null) must be exhaustive, so the last case matches all
522- // remaining values.
523- // See https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-14.11.2
524- exists ( Ast:: Switch switch , int last |
525- switch instanceof SwitchExpr or
526- exists ( switch .( SwitchStmt ) .getAPatternCase ( ) ) or
527- switch .( SwitchStmt ) .hasNullCase ( )
528- |
529- switch .getCase ( last ) = c and
530- not exists ( switch .getCase ( last + 1 ) )
531- )
532- or
533530 c .( J:: PatternCase ) .getAPattern ( ) .getType ( ) instanceof TypeObject
534531 }
535532
You can’t perform that action at this time.
0 commit comments