Add type access tests

This commit is contained in:
Tamas Vajk
2022-04-14 14:01:23 +02:00
committed by Ian Lynagh
parent 7ef9420bfd
commit dcac285a99
4 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
class A {
class C<T> {
fun fn(){
val a = C<C<Int>>()
}
}
constructor() {
println("")
}
val prop = this.fn(1)
fun fn() {}
fun fn(i: C<C<Int>>) = i
fun fn(i: Int) : Int {
val x = this.fn(1)
val e = Enu.A
return 5
}
enum class Enu {
A, B, C
}
}

View File

@@ -0,0 +1,23 @@
public class B {
public B() {
;
}
public void fn() { }
public C<C<Integer>> fn(C<C<Integer>> i) { return i; }
public int fn(int i) {
int x = this.fn(1);
Enu e = Enu.A;
return 5;
}
public static class C<T> {
public void fn() {
new C<C<Integer>>();
}
}
public static enum Enu {
A, B, C
}
}

View File

@@ -0,0 +1,138 @@
A.kt:
# 0| [CompilationUnit] A
# 2| 1: [Class] A
# 3| 3: [Class,GenericType,ParameterizedType] C
#-----| -2: (Generic Parameters)
# 3| 0: [TypeVariable] T
# 3| 1: [Constructor] C
# 3| 5: [BlockStmt] { ... }
# 3| 0: [SuperConstructorInvocationStmt] super(...)
# 3| 1: [BlockStmt] { ... }
# 4| 2: [Method] fn
# 4| 5: [BlockStmt] { ... }
# 5| 0: [LocalVariableDeclStmt] var ...;
# 5| 1: [LocalVariableDeclExpr] a
# 5| 0: [ClassInstanceExpr] new C<C<Integer>>(...)
# 5| -3: [TypeAccess] C<C<Integer>>
# 5| 0: [TypeAccess] C<Integer>
# 5| 0: [TypeAccess] Integer
# 9| 5: [Constructor] A
# 9| 5: [BlockStmt] { ... }
# 9| 0: [SuperConstructorInvocationStmt] super(...)
# 9| 1: [BlockStmt] { ... }
# 13| 0: [ExprStmt] <Expr>;
# 13| 0: [KtInitializerAssignExpr] ...=...
# 13| 0: [VarAccess] prop
# 10| 2: [ExprStmt] <Expr>;
# 10| 0: [MethodAccess] println(...)
# 10| -1: [TypeAccess] ConsoleKt
# 10| 0: [StringLiteral]
# 13| 6: [Method] getProp
# 13| 5: [BlockStmt] { ... }
# 13| 0: [ReturnStmt] return ...
# 13| 0: [VarAccess] this.prop
# 13| -1: [ThisAccess] this
# 13| 6: [FieldDeclaration] int prop;
# 13| -1: [TypeAccess] int
# 13| 0: [MethodAccess] fn(...)
# 13| -1: [ThisAccess] A.this
# 13| 0: [TypeAccess] A
# 13| 0: [IntegerLiteral] 1
# 15| 8: [Method] fn
# 15| 5: [BlockStmt] { ... }
# 16| 9: [Method] fn
#-----| 4: (Parameters)
# 16| 0: [Parameter] i
# 16| 5: [BlockStmt] { ... }
# 16| 0: [ReturnStmt] return ...
# 16| 0: [VarAccess] i
# 17| 10: [Method] fn
#-----| 4: (Parameters)
# 17| 0: [Parameter] i
# 17| 5: [BlockStmt] { ... }
# 18| 0: [LocalVariableDeclStmt] var ...;
# 18| 1: [LocalVariableDeclExpr] x
# 18| 0: [MethodAccess] fn(...)
# 18| -1: [ThisAccess] this
# 18| 0: [IntegerLiteral] 1
# 19| 1: [LocalVariableDeclStmt] var ...;
# 19| 1: [LocalVariableDeclExpr] e
# 19| 0: [VarAccess] A
# 20| 2: [ReturnStmt] return ...
# 20| 0: [IntegerLiteral] 5
# 23| 11: [Class] Enu
# 0| 1: [Method] values
# 0| 1: [Method] valueOf
#-----| 4: (Parameters)
# 0| 0: [Parameter] value
# 23| 3: [Constructor] Enu
# 23| 5: [BlockStmt] { ... }
# 23| 0: [ExprStmt] <Expr>;
# 23| 0: [ClassInstanceExpr] new Enum(...)
# 23| -3: [TypeAccess] Unit
# 23| 0: [TypeAccess] Enu
# 23| 1: [BlockStmt] { ... }
B.java:
# 0| [CompilationUnit] B
# 1| 1: [Class] B
# 2| 1: [Constructor] B
# 2| 5: [BlockStmt] { ... }
# 3| 1: [EmptyStmt] ;
# 6| 2: [Method] fn
# 6| 3: [TypeAccess] void
# 6| 5: [BlockStmt] { ... }
# 7| 3: [Method] fn
# 7| 3: [TypeAccess] C<C<Integer>>
# 7| 0: [TypeAccess] C<Integer>
# 7| 0: [TypeAccess] Integer
#-----| 4: (Parameters)
# 7| 0: [Parameter] i
# 7| 0: [TypeAccess] C<C<Integer>>
# 7| 0: [TypeAccess] C<Integer>
# 7| 0: [TypeAccess] Integer
# 7| 5: [BlockStmt] { ... }
# 7| 0: [ReturnStmt] return ...
# 7| 0: [VarAccess] i
# 8| 4: [Method] fn
# 8| 3: [TypeAccess] int
#-----| 4: (Parameters)
# 8| 0: [Parameter] i
# 8| 0: [TypeAccess] int
# 8| 5: [BlockStmt] { ... }
# 9| 0: [LocalVariableDeclStmt] var ...;
# 9| 0: [TypeAccess] int
# 9| 1: [LocalVariableDeclExpr] x
# 9| 0: [MethodAccess] fn(...)
# 9| -1: [ThisAccess] this
# 9| 0: [IntegerLiteral] 1
# 10| 1: [LocalVariableDeclStmt] var ...;
# 10| 0: [TypeAccess] Enu
# 10| 1: [LocalVariableDeclExpr] e
# 10| 0: [VarAccess] Enu.A
# 10| -1: [TypeAccess] Enu
# 11| 2: [ReturnStmt] return ...
# 11| 0: [IntegerLiteral] 5
# 14| 5: [Class,GenericType,ParameterizedType] C
#-----| -2: (Generic Parameters)
# 14| 0: [TypeVariable] T
# 15| 2: [Method] fn
# 15| 3: [TypeAccess] void
# 15| 5: [BlockStmt] { ... }
# 16| 0: [ExprStmt] <Expr>;
# 16| 0: [ClassInstanceExpr] new C<C<Integer>>(...)
# 16| -3: [TypeAccess] C<C<Integer>>
# 16| 0: [TypeAccess] C<Integer>
# 16| 0: [TypeAccess] Integer
# 20| 6: [Class] Enu
# 21| 3: [FieldDeclaration] Enu A;
# 21| -1: [TypeAccess] Enu
# 21| 0: [ClassInstanceExpr] new Enu(...)
# 21| -3: [TypeAccess] Enu
# 21| 4: [FieldDeclaration] Enu B;
# 21| -1: [TypeAccess] Enu
# 21| 0: [ClassInstanceExpr] new Enu(...)
# 21| -3: [TypeAccess] Enu
# 21| 5: [FieldDeclaration] Enu C;
# 21| -1: [TypeAccess] Enu
# 21| 0: [ClassInstanceExpr] new Enu(...)
# 21| -3: [TypeAccess] Enu

View File

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