Add test of Java/Kotlin annotation naming consistency

This commit is contained in:
Chris Smowton
2022-11-09 16:57:39 +00:00
parent 24434ed0ff
commit 2fd8e61fe2
6 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
User.java:
# 0| [CompilationUnit] User
# 1| 1: [Class] User
# 3| 2: [Method] user
# 3| 3: [TypeAccess] void
#-----| 4: (Parameters)
# 3| 0: [Parameter] a1
# 3| 0: [TypeAccess] Ann1
# 3| 1: [Parameter] a2
# 3| 0: [TypeAccess] Ann2
# 3| 5: [BlockStmt] { ... }
# 4| 0: [ExprStmt] <Expr>;
# 4| 0: [MethodAccess] x(...)
# 4| -1: [VarAccess] a1
# 4| 1: [ExprStmt] <Expr>;
# 4| 0: [MethodAccess] z(...)
# 4| -1: [VarAccess] a2
# 4| 2: [ExprStmt] <Expr>;
# 4| 0: [ClassInstanceExpr] new Annotated(...)
# 4| -3: [TypeAccess] Annotated
test.kt:
# 0| [CompilationUnit] test
# 3| 1: [Interface] Ann1
# 3| 1: [Method] x
# 3| 2: [Method] y
# 5| 2: [Interface] Ann2
# 5| 1: [Method] z
# 5| 2: [Method] w
# 5| 3: [Method] v
# 5| 4: [Method] u
# 7| 3: [Interface] Ann3
# 7| 1: [Method] a
# 9| 4: [Class] Annotated
#-----| -3: (Annotations)
# 9| 2: [Annotation] Ann1
# 0| 1: [IntegerLiteral] 1
# 0| 1: [Annotation] Ann2
# 0| 1: [StringLiteral] "Hello"
# 0| 1: [TypeLiteral] String.class
# 0| 0: [TypeAccess] String
# 0| 1: [ArrayInit] {...}
# 0| 1: [IntegerLiteral] 1
# 0| 1: [IntegerLiteral] 2
# 0| 1: [IntegerLiteral] 3
# 0| 1: [ArrayInit] {...}
# 0| 1: [Annotation] Ann3
# 0| 1: [IntegerLiteral] 1
# 0| 1: [Annotation] Ann3
# 0| 1: [IntegerLiteral] 2
# 10| 1: [Constructor] Annotated
# 9| 5: [BlockStmt] { ... }
# 9| 0: [SuperConstructorInvocationStmt] super(...)
# 10| 1: [BlockStmt] { ... }

View File

@@ -0,0 +1 @@
semmle/code/java/PrintAst.ql

View File

@@ -0,0 +1,7 @@
public class User {
public static void user(Ann1 a1, Ann2 a2) {
a1.x(); a2.z(); new Annotated();
}
}

View File

@@ -0,0 +1,10 @@
import kotlin.reflect.KClass
annotation class Ann1(val x: Int, val y: Ann2) { }
annotation class Ann2(val z: String, val w: KClass<*>, val v: IntArray, val u: Array<Ann3>) { }
annotation class Ann3(val a: Int) { }
@Ann1(1, Ann2("Hello", String::class, intArrayOf(1, 2, 3), arrayOf(Ann3(1), Ann3(2))))
class Annotated { }

View File

@@ -0,0 +1,5 @@
from create_database_utils import *
os.mkdir('out')
os.mkdir('out2')
run_codeql_database_create(["kotlinc test.kt -d out", "javac User.java -cp out -d out2"], lang="java")

View File

@@ -0,0 +1,3 @@
import kotlin.reflect.KClass
fun f(x: KClass<*>) = x