Skip to content

Commit d99a005

Browse files
committed
Fix pretty-printing case null, default
1 parent 4bff795 commit d99a005

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ private class PpSwitchCase extends PpAst, SwitchCase {
755755
override string getPart(int i) {
756756
i = 0 and result = "default" and isNonNullDefaultCase(this)
757757
or
758-
i = 0 and result = "case " and not isNonNullDefaultCase(this)
758+
i = 0 and result = "case null, default" and this instanceof NullDefaultCase
759759
or
760-
i = this.lastConstCaseValueIndex() and result = "default" and this instanceof NullDefaultCase
760+
i = 0 and result = "case " and not this instanceof DefaultCase
761761
or
762762
exists(int j | i = 2 * j and j != 0 and result = ", " and exists(this.(ConstCase).getValue(j)))
763763
or
@@ -768,15 +768,8 @@ private class PpSwitchCase extends PpAst, SwitchCase {
768768
i = 3 + this.lastConstCaseValueIndex() and result = ";" and exists(this.getRuleExpression())
769769
}
770770

771-
private int getCaseDefaultOffset() {
772-
if this instanceof NullDefaultCase then result = 1 else result = 0
773-
}
774-
775771
private int lastConstCaseValueIndex() {
776-
result =
777-
1 +
778-
2 *
779-
(max(int j | j = 0 or exists(this.(ConstCase).getValue(j))) + this.getCaseDefaultOffset())
772+
result = 1 + 2 * (max(int j | j = 0 or exists(this.(ConstCase).getValue(j))))
780773
}
781774

782775
override PpAst getChild(int i) {

java/ql/test/library-tests/prettyprint/pp.expected

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@
5656
| Test.java:1:14:1:17 | Test | 55 | } |
5757
| Test.java:1:14:1:17 | Test | 56 | case R(S(int x), String y) -> { |
5858
| Test.java:1:14:1:17 | Test | 57 | } |
59-
| Test.java:1:14:1:17 | Test | 58 | case default -> { |
59+
| Test.java:1:14:1:17 | Test | 58 | case null, default -> { |
6060
| Test.java:1:14:1:17 | Test | 59 | } |
6161
| Test.java:1:14:1:17 | Test | 60 | } |
6262
| Test.java:1:14:1:17 | Test | 61 | var a = switch (o) { |
6363
| Test.java:1:14:1:17 | Test | 62 | case String s: |
6464
| Test.java:1:14:1:17 | Test | 63 | yield 1; |
6565
| Test.java:1:14:1:17 | Test | 64 | case R(S(int x), String y): |
6666
| Test.java:1:14:1:17 | Test | 65 | yield x; |
67-
| Test.java:1:14:1:17 | Test | 66 | case default: |
67+
| Test.java:1:14:1:17 | Test | 66 | case null, default: |
6868
| Test.java:1:14:1:17 | Test | 67 | yield 2; |
6969
| Test.java:1:14:1:17 | Test | 68 | }; |
7070
| Test.java:1:14:1:17 | Test | 69 | var b = switch (o) { |
@@ -79,7 +79,7 @@
7979
| Test.java:1:14:1:17 | Test | 78 | switch (o) { |
8080
| Test.java:1:14:1:17 | Test | 79 | case R(S(var x), var y) -> { |
8181
| Test.java:1:14:1:17 | Test | 80 | } |
82-
| Test.java:1:14:1:17 | Test | 81 | case default -> { |
82+
| Test.java:1:14:1:17 | Test | 81 | case null, default -> { |
8383
| Test.java:1:14:1:17 | Test | 82 | } |
8484
| Test.java:1:14:1:17 | Test | 83 | } |
8585
| Test.java:1:14:1:17 | Test | 84 | if (o instanceof R(S(var x), var y)) { |

0 commit comments

Comments
 (0)