File tree Expand file tree Collapse file tree
lib/semmle/code/java/metrics
src/Violations of Best Practice/Declarations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,13 +73,15 @@ class MetricCallable extends Callable {
7373// so there should be a branching point for each non-default switch
7474// case (ignoring those that just fall through to the next case).
7575private predicate branchingSwitchCase ( ConstCase sc ) {
76- not sc .( ControlFlowNode ) .getASuccessor ( ) instanceof ConstCase and
77- not sc .( ControlFlowNode ) .getASuccessor ( ) instanceof DefaultCase and
76+ not sc .( ControlFlowNode ) .getASuccessor ( ) instanceof SwitchCase and
7877 not defaultFallThrough ( sc )
7978}
8079
8180private predicate defaultFallThrough ( ConstCase sc ) {
82- exists ( DefaultCase default | default .( ControlFlowNode ) .getASuccessor ( ) = sc ) or
81+ exists ( SwitchCase default | default .hasDefaultLabel ( ) |
82+ default .( ControlFlowNode ) .getASuccessor ( ) = sc
83+ )
84+ or
8385 defaultFallThrough ( sc .( ControlFlowNode ) .getAPredecessor ( ) )
8486}
8587
@@ -90,6 +92,7 @@ private predicate branchingStmt(Stmt stmt) {
9092 stmt instanceof DoStmt or
9193 stmt instanceof ForStmt or
9294 stmt instanceof EnhancedForStmt or
95+ stmt instanceof PatternCase or
9396 branchingSwitchCase ( stmt ) or
9497 stmt instanceof CatchClause
9598}
Original file line number Diff line number Diff line change @@ -17,8 +17,7 @@ import Common
1717from SwitchStmt s , Stmt c
1818where
1919 c = s .getACase ( ) and
20- not c .( ControlFlowNode ) .getASuccessor ( ) instanceof ConstCase and
21- not c .( ControlFlowNode ) .getASuccessor ( ) instanceof DefaultCase and
20+ not c .( ControlFlowNode ) .getASuccessor ( ) instanceof SwitchCase and
2221 not s .( Annotatable ) .suppressesWarningsAbout ( "fallthrough" ) and
2322 mayDropThroughWithoutComment ( s , c )
2423select c ,
You can’t perform that action at this time.
0 commit comments