Skip to content

Commit d96bca0

Browse files
committed
Add test for repeatable annotations
1 parent eaa9595 commit d96bca0

File tree

8 files changed

+67
-0
lines changed

8 files changed

+67
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public @interface JavaDefinedContainer {
2+
3+
public JavaDefinedRepeatable[] value();
4+
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@java.lang.annotation.Repeatable(JavaDefinedContainer.class)
2+
public @interface JavaDefinedRepeatable { }
3+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@LibRepeatable
2+
@LibRepeatable
3+
@ExplicitContainerRepeatable
4+
@ExplicitContainerRepeatable
5+
@JavaDefinedRepeatable
6+
@JavaDefinedRepeatable
7+
public class JavaUser { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@Repeatable
2+
public annotation class LibRepeatable { }
3+
4+
annotation class KtDefinedContainer(val value: Array<ExplicitContainerRepeatable>) { }
5+
6+
@java.lang.annotation.Repeatable(KtDefinedContainer::class)
7+
annotation class ExplicitContainerRepeatable() { }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| JavaUser.java:7:14:7:21 | JavaUser | out2/JavaUser.class:0:0:0:0 | Container | value | out2/JavaUser.class:0:0:0:0 | {...} |
2+
| JavaUser.java:7:14:7:21 | JavaUser | out2/JavaUser.class:0:0:0:0 | JavaDefinedContainer | value | out2/JavaUser.class:0:0:0:0 | {...} |
3+
| JavaUser.java:7:14:7:21 | JavaUser | out2/JavaUser.class:0:0:0:0 | KtDefinedContainer | value | out2/JavaUser.class:0:0:0:0 | {...} |
4+
| out/ExplicitContainerRepeatable.class:0:0:0:0 | ExplicitContainerRepeatable | out/ExplicitContainerRepeatable.class:0:0:0:0 | Repeatable | value | out/ExplicitContainerRepeatable.class:0:0:0:0 | KtDefinedContainer.class |
5+
| out/ExplicitContainerRepeatable.class:0:0:0:0 | ExplicitContainerRepeatable | out/ExplicitContainerRepeatable.class:0:0:0:0 | Retention | value | out/ExplicitContainerRepeatable.class:0:0:0:0 | RetentionPolicy.RUNTIME |
6+
| out/JavaDefinedRepeatable.class:0:0:0:0 | JavaDefinedRepeatable | out/JavaDefinedRepeatable.class:0:0:0:0 | Repeatable | value | out/JavaDefinedRepeatable.class:0:0:0:0 | JavaDefinedContainer.class |
7+
| out/KtDefinedContainer.class:0:0:0:0 | KtDefinedContainer | out/KtDefinedContainer.class:0:0:0:0 | Retention | value | out/KtDefinedContainer.class:0:0:0:0 | RetentionPolicy.RUNTIME |
8+
| out/LibRepeatable.class:0:0:0:0 | LibRepeatable | out/LibRepeatable.class:0:0:0:0 | Repeatable | value | out/LibRepeatable.class:0:0:0:0 | Container.class |
9+
| out/LibRepeatable.class:0:0:0:0 | LibRepeatable | out/LibRepeatable.class:0:0:0:0 | Retention | value | out/LibRepeatable.class:0:0:0:0 | RetentionPolicy.RUNTIME |
10+
| test.kt:1:1:2:43 | LocalRepeatable | test.kt:0:0:0:0 | Repeatable | value | test.kt:0:0:0:0 | Container.class |
11+
| test.kt:1:1:2:43 | LocalRepeatable | test.kt:0:0:0:0 | Retention | value | test.kt:0:0:0:0 | RetentionPolicy.RUNTIME |
12+
| test.kt:4:1:12:21 | User | test.kt:0:0:0:0 | Container | value | test.kt:0:0:0:0 | {...} |
13+
| test.kt:4:1:12:21 | User | test.kt:0:0:0:0 | Container | value | test.kt:0:0:0:0 | {...} |
14+
| test.kt:4:1:12:21 | User | test.kt:0:0:0:0 | JavaDefinedContainer | value | test.kt:0:0:0:0 | {...} |
15+
| test.kt:4:1:12:21 | User | test.kt:0:0:0:0 | KtDefinedContainer | value | test.kt:0:0:0:0 | {...} |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@Repeatable
2+
public annotation class LocalRepeatable { }
3+
4+
@LocalRepeatable
5+
@LocalRepeatable
6+
@LibRepeatable
7+
@LibRepeatable
8+
@ExplicitContainerRepeatable
9+
@ExplicitContainerRepeatable
10+
@JavaDefinedRepeatable
11+
@JavaDefinedRepeatable
12+
public class User { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from create_database_utils import *
2+
3+
os.mkdir('out')
4+
os.mkdir('out2')
5+
runSuccessfully([get_cmd("kotlinc"), "lib.kt", "-d", "out"])
6+
runSuccessfully([get_cmd("javac"), "JavaDefinedContainer.java", "JavaDefinedRepeatable.java", "-d", "out"])
7+
run_codeql_database_create(["javac JavaUser.java -cp out -d out2", "kotlinc test.kt -cp out -d out2"], lang="java")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java
2+
3+
from ClassOrInterface annotated, Annotation a, string valName, Expr val
4+
where
5+
a.getValue(valName) = val and
6+
annotated = a.getAnnotatedElement() and
7+
annotated.getName() in [
8+
"JavaDefinedRepeatable", "JavaDefinedContainer", "KtDefinedContainer", "LibRepeatable",
9+
"ExplicitContainerRepeatable", "LocalRepeatable", "User", "JavaUser"
10+
]
11+
select a.getAnnotatedElement(), a, valName, val

0 commit comments

Comments
 (0)