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

Skip to content

Commit 79b77ae

Browse files
committed
Add AST test for switch with null case
1 parent 05caffc commit 79b77ae

2 files changed

Lines changed: 41 additions & 28 deletions

File tree

java/ql/test/library-tests/printAst/A.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void varDecls(Object[] things) {
7878
default:
7979
yield "Something else";
8080
};
81+
var nullTest = switch(thing) {
82+
case null -> "Null";
83+
default -> "Not null";
84+
};
8185
}
8286
}
8387
catch (RuntimeException rte) {

java/ql/test/library-tests/printAst/PrintAst.expected

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,36 +208,45 @@ A.java:
208208
# 78| 4: [DefaultCase] default
209209
# 79| 5: [YieldStmt] yield ...
210210
# 79| 0: [StringLiteral] "Something else"
211-
# 83| 0: [CatchClause] catch (...)
211+
# 81| 6: [LocalVariableDeclStmt] var ...;
212+
# 81| 1: [LocalVariableDeclExpr] nullTest
213+
# 81| 0: [SwitchExpr] switch (...)
214+
# 81| -1: [VarAccess] thing
215+
# 82| 0: [ConstCase] case ...
216+
# 82| -1: [StringLiteral] "Null"
217+
# 82| 0: [NullLiteral] null
218+
# 83| 1: [DefaultCase] default
219+
# 83| -1: [StringLiteral] "Not null"
220+
# 87| 0: [CatchClause] catch (...)
212221
#-----| 0: (Single Local Variable Declaration)
213-
# 83| 0: [TypeAccess] RuntimeException
214-
# 83| 1: [LocalVariableDeclExpr] rte
215-
# 83| 1: [BlockStmt] { ... }
216-
# 84| 0: [ReturnStmt] return ...
217-
# 88| 10: [Class] E
218-
# 92| 3: [FieldDeclaration] E A;
222+
# 87| 0: [TypeAccess] RuntimeException
223+
# 87| 1: [LocalVariableDeclExpr] rte
224+
# 87| 1: [BlockStmt] { ... }
225+
# 88| 0: [ReturnStmt] return ...
226+
# 92| 10: [Class] E
227+
# 96| 3: [FieldDeclaration] E A;
219228
#-----| -3: (Javadoc)
220-
# 89| 1: [Javadoc] /** Javadoc for enum constant */
221-
# 90| 0: [JavadocText] Javadoc for enum constant
222-
# 92| -1: [TypeAccess] E
223-
# 92| 0: [ClassInstanceExpr] new E(...)
224-
# 92| -3: [TypeAccess] E
225-
# 93| 4: [FieldDeclaration] E B;
229+
# 93| 1: [Javadoc] /** Javadoc for enum constant */
230+
# 94| 0: [JavadocText] Javadoc for enum constant
231+
# 96| -1: [TypeAccess] E
232+
# 96| 0: [ClassInstanceExpr] new E(...)
233+
# 96| -3: [TypeAccess] E
234+
# 97| 4: [FieldDeclaration] E B;
226235
#-----| -3: (Javadoc)
227-
# 89| 1: [Javadoc] /** Javadoc for enum constant */
228-
# 90| 0: [JavadocText] Javadoc for enum constant
229-
# 93| -1: [TypeAccess] E
230-
# 93| 0: [ClassInstanceExpr] new E(...)
231-
# 93| -3: [TypeAccess] E
232-
# 94| 5: [FieldDeclaration] E C;
236+
# 93| 1: [Javadoc] /** Javadoc for enum constant */
237+
# 94| 0: [JavadocText] Javadoc for enum constant
238+
# 97| -1: [TypeAccess] E
239+
# 97| 0: [ClassInstanceExpr] new E(...)
240+
# 97| -3: [TypeAccess] E
241+
# 98| 5: [FieldDeclaration] E C;
233242
#-----| -3: (Javadoc)
234-
# 89| 1: [Javadoc] /** Javadoc for enum constant */
235-
# 90| 0: [JavadocText] Javadoc for enum constant
236-
# 94| -1: [TypeAccess] E
237-
# 94| 0: [ClassInstanceExpr] new E(...)
238-
# 94| -3: [TypeAccess] E
239-
# 100| 11: [FieldDeclaration] int i, ...;
243+
# 93| 1: [Javadoc] /** Javadoc for enum constant */
244+
# 94| 0: [JavadocText] Javadoc for enum constant
245+
# 98| -1: [TypeAccess] E
246+
# 98| 0: [ClassInstanceExpr] new E(...)
247+
# 98| -3: [TypeAccess] E
248+
# 104| 11: [FieldDeclaration] int i, ...;
240249
#-----| -3: (Javadoc)
241-
# 97| 1: [Javadoc] /** Javadoc for fields */
242-
# 98| 0: [JavadocText] Javadoc for fields
243-
# 100| -1: [TypeAccess] int
250+
# 101| 1: [Javadoc] /** Javadoc for fields */
251+
# 102| 0: [JavadocText] Javadoc for fields
252+
# 104| -1: [TypeAccess] int

0 commit comments

Comments
 (0)