Add tests for static and final modifiers relating to record classes

This commit is contained in:
Chris Smowton
2021-09-03 18:20:16 +01:00
parent ec0066d5a4
commit 23d7633cd5
6 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1 @@
final record MyFinalRecord() { }

View File

@@ -0,0 +1,2 @@
// Records are implicitly final
record MyRecord() { }

View File

@@ -0,0 +1,6 @@
| MyFinalRecord.java:1:14:1:26 | MyFinalRecord | final=true | static=false | Record |
| MyRecord.java:2:8:2:15 | MyRecord | final=true | static=false | Record |
| Test.java:3:12:3:13 | R1 | final=true | static=true | Record |
| Test.java:4:25:4:26 | R2 | final=true | static=true | Record |
| Test.java:8:12:8:13 | R3 | final=true | static=true | Record,SuperInterface |
| Test.java:12:16:12:26 | LocalRecord | final=true | static=true | Record |

View File

@@ -0,0 +1,8 @@
import java
from Record r, boolean isFinal, boolean isStatic, string superTypes
where
(if r.isFinal() then isFinal = true else isFinal = false) and
(if r.isStatic() then isStatic = true else isStatic = false) and
superTypes = concat(RefType superType | superType = r.getASupertype() | superType.toString(), ",")
select r, "final=" + isFinal, "static=" + isStatic, superTypes

View File

@@ -0,0 +1,14 @@
class Test {
// Nested records are implicitly static
record R1() { }
static final record R2() { }
interface SuperInterface { }
record R3() implements SuperInterface { }
void test() {
// Nested records are implicitly static
record LocalRecord() { }
}
}

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args -source 16 -target 16