Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e868d2

Browse files
committed
Make DefaultCase include NullDefaultCase
1 parent d2ff1ba commit 6e868d2

4 files changed

Lines changed: 13 additions & 21 deletions

File tree

java/ql/lib/semmle/code/java/Expr.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
15351535
*
15361536
* Note this may be `default` or `case null, default`.
15371537
*/
1538-
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
1538+
DefaultCase getDefaultCase() { result = this.getACase() }
15391539

15401540
/** Gets the expression of this `switch` expression. */
15411541
Expr getExpr() { result.getParent() = this }
@@ -1738,9 +1738,7 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
17381738

17391739
/** A local variable declaration that occurs within a record pattern. */
17401740
class RecordBindingVariableExpr extends LocalVariableDeclExpr {
1741-
RecordBindingVariableExpr() {
1742-
this.getParent() instanceof RecordPatternExpr
1743-
}
1741+
RecordBindingVariableExpr() { this.getParent() instanceof RecordPatternExpr }
17441742
}
17451743

17461744
/** An update of a variable or an initialization of the variable. */

java/ql/lib/semmle/code/java/Statement.qll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class SwitchStmt extends Stmt, @switchstmt {
408408
*
409409
* Note this may be `default` or `case null, default`.
410410
*/
411-
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
411+
DefaultCase getDefaultCase() { result = this.getACase() }
412412

413413
/** Gets the expression of this `switch` statement. */
414414
Expr getExpr() { result.getParent() = this }
@@ -492,12 +492,6 @@ class SwitchCase extends Stmt, @case {
492492
Stmt getRuleStatementOrExpressionStatement() {
493493
result.getParent() = this and result.getIndex() = -1
494494
}
495-
496-
/**
497-
* Holds if this case statement includes the default label, i.e. it is either `default`
498-
* or `case null, default`.
499-
*/
500-
predicate hasDefaultLabel() { this instanceof DefaultCase or this instanceof NullDefaultCase }
501495
}
502496

503497
/**
@@ -553,12 +547,14 @@ class PatternCase extends SwitchCase {
553547
}
554548

555549
/**
556-
* A `default` case of a `switch` statement.
557-
*
558-
* Note this does not include `case null, default` -- for that, see `NullDefaultCase`.
550+
* A `default` or `case null, default` case of a `switch` statement or expression.
559551
*/
560552
class DefaultCase extends SwitchCase {
561-
DefaultCase() { not exists(Expr e | e.getParent() = this | e.getIndex() >= 0) }
553+
DefaultCase() {
554+
isNullDefaultCase(this)
555+
or
556+
not exists(Expr e | e.getParent() = this | e.getIndex() >= 0)
557+
}
562558

563559
override string pp() { result = "default" }
564560

@@ -570,7 +566,7 @@ class DefaultCase extends SwitchCase {
570566
}
571567

572568
/** A `case null, default` statement of a `switch` statement or expression. */
573-
class NullDefaultCase extends SwitchCase {
569+
class NullDefaultCase extends DefaultCase {
574570
NullDefaultCase() { isNullDefaultCase(this) }
575571

576572
override string pp() { result = "case null, default" }

java/ql/lib/semmle/code/java/controlflow/internal/GuardsLogic.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ predicate implies_v1(Guard g1, boolean b1, Guard g2, boolean b2) {
5555
)
5656
)
5757
or
58-
exists(SwitchCase sc | g1 = sc and sc.hasDefaultLabel() |
58+
exists(DefaultCase sc | g1 = sc |
5959
sc.getSwitch().getAConstCase() = g2 and b1 = true and b2 = false
6060
)
6161
or
62-
exists(SwitchCase sc | g1 = sc and sc.hasDefaultLabel() |
62+
exists(DefaultCase sc | g1 = sc |
6363
sc.getSwitchExpr().getAConstCase() = g2 and b1 = true and b2 = false
6464
)
6565
or

java/ql/lib/semmle/code/java/metrics/MetricCallable.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ private predicate branchingSwitchCase(ConstCase sc) {
7878
}
7979

8080
private predicate defaultFallThrough(ConstCase sc) {
81-
exists(SwitchCase default | default.hasDefaultLabel() |
82-
default.(ControlFlowNode).getASuccessor() = sc
83-
)
81+
exists(DefaultCase default | default.(ControlFlowNode).getASuccessor() = sc)
8482
or
8583
defaultFallThrough(sc.(ControlFlowNode).getAPredecessor())
8684
}

0 commit comments

Comments
 (0)