diff --git a/java/ql/lib/semmle/code/java/PrettyPrintAst.qll b/java/ql/lib/semmle/code/java/PrettyPrintAst.qll index 0c6bd7fcff4..6a5e5aa698b 100644 --- a/java/ql/lib/semmle/code/java/PrettyPrintAst.qll +++ b/java/ql/lib/semmle/code/java/PrettyPrintAst.qll @@ -755,9 +755,9 @@ private class PpSwitchCase extends PpAst, SwitchCase { override string getPart(int i) { i = 0 and result = "default" and isNonNullDefaultCase(this) or - i = 0 and result = "case " and not isNonNullDefaultCase(this) + i = 0 and result = "case null, default" and this instanceof NullDefaultCase or - i = this.lastConstCaseValueIndex() and result = "default" and this instanceof NullDefaultCase + i = 0 and result = "case " and not this instanceof DefaultCase or exists(int j | i = 2 * j and j != 0 and result = ", " and exists(this.(ConstCase).getValue(j))) or @@ -768,15 +768,8 @@ private class PpSwitchCase extends PpAst, SwitchCase { i = 3 + this.lastConstCaseValueIndex() and result = ";" and exists(this.getRuleExpression()) } - private int getCaseDefaultOffset() { - if this instanceof NullDefaultCase then result = 1 else result = 0 - } - private int lastConstCaseValueIndex() { - result = - 1 + - 2 * - (max(int j | j = 0 or exists(this.(ConstCase).getValue(j))) + this.getCaseDefaultOffset()) + result = 1 + 2 * (max(int j | j = 0 or exists(this.(ConstCase).getValue(j)))) } override PpAst getChild(int i) { diff --git a/java/ql/test/library-tests/prettyprint/pp.expected b/java/ql/test/library-tests/prettyprint/pp.expected index 37d92354cff..eb4fbaf0633 100644 --- a/java/ql/test/library-tests/prettyprint/pp.expected +++ b/java/ql/test/library-tests/prettyprint/pp.expected @@ -56,7 +56,7 @@ | Test.java:1:14:1:17 | Test | 55 | } | | Test.java:1:14:1:17 | Test | 56 | case R(S(int x), String y) -> { | | Test.java:1:14:1:17 | Test | 57 | } | -| Test.java:1:14:1:17 | Test | 58 | case default -> { | +| Test.java:1:14:1:17 | Test | 58 | case null, default -> { | | Test.java:1:14:1:17 | Test | 59 | } | | Test.java:1:14:1:17 | Test | 60 | } | | Test.java:1:14:1:17 | Test | 61 | var a = switch (o) { | @@ -64,7 +64,7 @@ | Test.java:1:14:1:17 | Test | 63 | yield 1; | | Test.java:1:14:1:17 | Test | 64 | case R(S(int x), String y): | | Test.java:1:14:1:17 | Test | 65 | yield x; | -| Test.java:1:14:1:17 | Test | 66 | case default: | +| Test.java:1:14:1:17 | Test | 66 | case null, default: | | Test.java:1:14:1:17 | Test | 67 | yield 2; | | Test.java:1:14:1:17 | Test | 68 | }; | | Test.java:1:14:1:17 | Test | 69 | var b = switch (o) { | @@ -79,7 +79,7 @@ | Test.java:1:14:1:17 | Test | 78 | switch (o) { | | Test.java:1:14:1:17 | Test | 79 | case R(S(var x), var y) -> { | | Test.java:1:14:1:17 | Test | 80 | } | -| Test.java:1:14:1:17 | Test | 81 | case default -> { | +| Test.java:1:14:1:17 | Test | 81 | case null, default -> { | | Test.java:1:14:1:17 | Test | 82 | } | | Test.java:1:14:1:17 | Test | 83 | } | | Test.java:1:14:1:17 | Test | 84 | if (o instanceof R(S(var x), var y)) { |