Skip to content

Commit 5a47ddb

Browse files
authored
Merge pull request github#6604 from smowton/smowton/admin/marcono-record-tests
Java: Add tests for static and final modifiers relating to record classes
2 parents b9ef6c7 + 23d7633 commit 5a47ddb

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
final record MyFinalRecord() { }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Records are implicitly final
2+
record MyRecord() { }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| MyFinalRecord.java:1:14:1:26 | MyFinalRecord | final=true | static=false | Record |
2+
| MyRecord.java:2:8:2:15 | MyRecord | final=true | static=false | Record |
3+
| Test.java:3:12:3:13 | R1 | final=true | static=true | Record |
4+
| Test.java:4:25:4:26 | R2 | final=true | static=true | Record |
5+
| Test.java:8:12:8:13 | R3 | final=true | static=true | Record,SuperInterface |
6+
| Test.java:12:16:12:26 | LocalRecord | final=true | static=true | Record |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java
2+
3+
from Record r, boolean isFinal, boolean isStatic, string superTypes
4+
where
5+
(if r.isFinal() then isFinal = true else isFinal = false) and
6+
(if r.isStatic() then isStatic = true else isStatic = false) and
7+
superTypes = concat(RefType superType | superType = r.getASupertype() | superType.toString(), ",")
8+
select r, "final=" + isFinal, "static=" + isStatic, superTypes
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Test {
2+
// Nested records are implicitly static
3+
record R1() { }
4+
static final record R2() { }
5+
6+
interface SuperInterface { }
7+
8+
record R3() implements SuperInterface { }
9+
10+
void test() {
11+
// Nested records are implicitly static
12+
record LocalRecord() { }
13+
}
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//semmle-extractor-options: --javac-args -source 16 -target 16

0 commit comments

Comments
 (0)