mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
Extract local class declarations
This commit is contained in:
@@ -201,13 +201,13 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun extracLocalTypeDeclStmt(c: IrClass, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
private fun extractLocalTypeDeclStmt(c: IrClass, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val id = extractClassSource(c) as Label<out DbClass>
|
||||
extracLocalTypeDeclStmt(id, c, callable, parent, idx)
|
||||
extractLocalTypeDeclStmt(id, c, callable, parent, idx)
|
||||
}
|
||||
|
||||
private fun extracLocalTypeDeclStmt(id: Label<out DbClass>, locElement: IrElement, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
private fun extractLocalTypeDeclStmt(id: Label<out DbClass>, locElement: IrElement, callable: Label<out DbCallable>, parent: Label<out DbStmtparent>, idx: Int) {
|
||||
val stmtId = tw.getFreshIdLabel<DbLocaltypedeclstmt>()
|
||||
tw.writeStmts_localtypedeclstmt(stmtId, parent, idx, callable)
|
||||
tw.writeIsLocalClassOrInterface(id, stmtId)
|
||||
@@ -656,16 +656,12 @@ open class KotlinFileExtractor(
|
||||
extractVariable(s, callable, parent, idx)
|
||||
}
|
||||
is IrClass -> {
|
||||
if (s.isAnonymousObject) {
|
||||
extracLocalTypeDeclStmt(s, callable, parent, idx)
|
||||
} else {
|
||||
logger.warnElement(Severity.ErrorSevere, "Found non anonymous IrClass as IrStatement: " + s.javaClass, s)
|
||||
}
|
||||
extractLocalTypeDeclStmt(s, callable, parent, idx)
|
||||
}
|
||||
is IrFunction -> {
|
||||
if (s.isLocalFunction()) {
|
||||
val classId = extractGeneratedClass(s, listOf(pluginContext.irBuiltIns.anyType))
|
||||
extracLocalTypeDeclStmt(classId, s, callable, parent, idx)
|
||||
extractLocalTypeDeclStmt(classId, s, callable, parent, idx)
|
||||
} else {
|
||||
logger.warnElement(Severity.ErrorSevere, "Expected to find local function", s)
|
||||
}
|
||||
|
||||
@@ -658,13 +658,18 @@ class X {
|
||||
private fun getUnquotedClassLabel(c: IrClass, typeArgs: List<IrTypeArgument>?): ClassLabelResults {
|
||||
val pkg = c.packageFqName?.asString() ?: ""
|
||||
val cls = c.name.asString()
|
||||
val parent = c.parent
|
||||
val label = if (parent is IrClass) {
|
||||
// todo: fix this. Ugly string concat to handle nested class IDs.
|
||||
// todo: Can the containing class have type arguments?
|
||||
"${getUnquotedClassLabel(parent, listOf()).classLabel}\$$cls"
|
||||
} else {
|
||||
if (pkg.isEmpty()) cls else "$pkg.$cls"
|
||||
val label = when (val parent = c.parent) {
|
||||
is IrClass -> {
|
||||
// todo: fix this. Ugly string concat to handle nested class IDs.
|
||||
// todo: Can the containing class have type arguments?
|
||||
"${getUnquotedClassLabel(parent, listOf()).classLabel}\$$cls"
|
||||
}
|
||||
is IrFunction -> {
|
||||
"{${useFunction<DbMethod>(parent)}}.$cls"
|
||||
}
|
||||
else -> {
|
||||
if (pkg.isEmpty()) cls else "$pkg.$cls"
|
||||
}
|
||||
}
|
||||
|
||||
val typeArgLabels = typeArgs?.map { getTypeArgumentLabel(it) }
|
||||
|
||||
465
java/ql/test/kotlin/library-tests/classes/PrintAst.expected
Normal file
465
java/ql/test/kotlin/library-tests/classes/PrintAst.expected
Normal file
@@ -0,0 +1,465 @@
|
||||
classes.kt:
|
||||
# 0| [CompilationUnit] classes
|
||||
# 0| 1: [Class] ClassesKt
|
||||
# 32| 1: [Method] f
|
||||
#-----| 4: (Parameters)
|
||||
# 32| 0: [Parameter] s
|
||||
# 32| 5: [BlockStmt] { ... }
|
||||
# 2| 2: [Class] ClassOne
|
||||
# 2| 1: [Constructor] ClassOne
|
||||
# 2| 5: [BlockStmt] { ... }
|
||||
# 2| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 2| 1: [ExprStmt] <Expr>;
|
||||
# 2| 0: [MethodAccess] <obinit>(...)
|
||||
# 4| 3: [Class] ClassTwo
|
||||
# 4| 1: [Constructor] ClassTwo
|
||||
#-----| 4: (Parameters)
|
||||
# 4| 0: [Parameter] arg
|
||||
# 4| 5: [BlockStmt] { ... }
|
||||
# 4| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 4| 1: [ExprStmt] <Expr>;
|
||||
# 4| 0: [MethodAccess] <obinit>(...)
|
||||
# 4| 3: [Method] getArg
|
||||
# 4| 5: [BlockStmt] { ... }
|
||||
# 4| 0: [ReturnStmt] return ...
|
||||
# 4| 0: [VarAccess] this.arg
|
||||
# 4| -1: [ThisAccess] this
|
||||
# 4| 3: [FieldDeclaration] int arg;
|
||||
# 4| -1: [TypeAccess] int
|
||||
# 5| 5: [Method] getX
|
||||
# 5| 5: [BlockStmt] { ... }
|
||||
# 5| 0: [ReturnStmt] return ...
|
||||
# 5| 0: [VarAccess] this.x
|
||||
# 5| -1: [ThisAccess] this
|
||||
# 5| 5: [FieldDeclaration] int x;
|
||||
# 5| -1: [TypeAccess] int
|
||||
# 5| 0: [IntegerLiteral] 3
|
||||
# 8| 4: [Class] ClassThree
|
||||
# 8| 2: [Constructor] ClassThree
|
||||
# 8| 5: [BlockStmt] { ... }
|
||||
# 8| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 8| 1: [ExprStmt] <Expr>;
|
||||
# 8| 0: [MethodAccess] <obinit>(...)
|
||||
# 9| 3: [Method] foo
|
||||
#-----| 4: (Parameters)
|
||||
# 9| 0: [Parameter] arg
|
||||
# 12| 5: [Class] ClassFour
|
||||
# 12| 2: [Constructor] ClassFour
|
||||
# 12| 5: [BlockStmt] { ... }
|
||||
# 12| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 12| 1: [ExprStmt] <Expr>;
|
||||
# 12| 0: [MethodAccess] <obinit>(...)
|
||||
# 13| 3: [Method] foo
|
||||
#-----| 4: (Parameters)
|
||||
# 13| 0: [Parameter] arg
|
||||
# 13| 5: [BlockStmt] { ... }
|
||||
# 17| 6: [Class] ClassFive
|
||||
# 17| 1: [Constructor] ClassFive
|
||||
# 17| 5: [BlockStmt] { ... }
|
||||
# 17| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 17| 1: [ExprStmt] <Expr>;
|
||||
# 17| 0: [MethodAccess] <obinit>(...)
|
||||
# 20| 7: [Interface] IF1
|
||||
# 21| 2: [Method] funIF1
|
||||
# 21| 5: [BlockStmt] { ... }
|
||||
# 24| 8: [Interface] IF2
|
||||
# 25| 2: [Method] funIF2
|
||||
# 25| 5: [BlockStmt] { ... }
|
||||
# 28| 9: [Class] ClassSix
|
||||
# 28| 1: [Constructor] ClassSix
|
||||
# 28| 5: [BlockStmt] { ... }
|
||||
# 28| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 28| 1: [ExprStmt] <Expr>;
|
||||
# 28| 0: [MethodAccess] <obinit>(...)
|
||||
# 29| 3: [Constructor] ClassSix
|
||||
#-----| 4: (Parameters)
|
||||
# 29| 0: [Parameter] i
|
||||
# 29| 5: [BlockStmt] { ... }
|
||||
# 29| 0: [ThisConstructorInvocationStmt] this(...)
|
||||
# 34| 10: [Class] ClassSeven
|
||||
# 35| 2: [Constructor] ClassSeven
|
||||
#-----| 4: (Parameters)
|
||||
# 35| 0: [Parameter] i
|
||||
# 35| 5: [BlockStmt] { ... }
|
||||
# 35| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 35| 1: [ExprStmt] <Expr>;
|
||||
# 35| 0: [MethodAccess] <obinit>(...)
|
||||
# 36| 2: [ExprStmt] <Expr>;
|
||||
# 36| 0: [MethodAccess] f(...)
|
||||
# 36| 0: [VarAccess] i
|
||||
# 42| 3: [Method] getX
|
||||
# 42| 5: [BlockStmt] { ... }
|
||||
# 42| 0: [ReturnStmt] return ...
|
||||
# 42| 0: [VarAccess] this.x
|
||||
# 42| -1: [ThisAccess] this
|
||||
# 42| 3: [FieldDeclaration] int x;
|
||||
# 42| -1: [TypeAccess] int
|
||||
# 42| 0: [IntegerLiteral] 3
|
||||
# 49| 11: [Class] Direction
|
||||
# 0| 1: [Method] values
|
||||
# 0| 1: [Method] valueOf
|
||||
#-----| 4: (Parameters)
|
||||
# 0| 0: [Parameter] value
|
||||
# 49| 4: [Constructor] Direction
|
||||
# 49| 5: [BlockStmt] { ... }
|
||||
# 49| 0: [ExprStmt] <Expr>;
|
||||
# 49| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 49| -3: [TypeAccess] Unit
|
||||
# 49| 0: [TypeAccess] Direction
|
||||
# 49| 1: [ExprStmt] <Expr>;
|
||||
# 49| 0: [MethodAccess] <obinit>(...)
|
||||
# 49| 4: [Method] getName
|
||||
# 49| 4: [Method] getOrdinal
|
||||
# 53| 12: [Class] Color
|
||||
# 0| 1: [Method] values
|
||||
# 0| 1: [Method] valueOf
|
||||
#-----| 4: (Parameters)
|
||||
# 0| 0: [Parameter] value
|
||||
# 53| 4: [Constructor] Color
|
||||
#-----| 4: (Parameters)
|
||||
# 53| 0: [Parameter] rgb
|
||||
# 53| 5: [BlockStmt] { ... }
|
||||
# 53| 0: [ExprStmt] <Expr>;
|
||||
# 53| 0: [ClassInstanceExpr] new Enum(...)
|
||||
# 53| -3: [TypeAccess] Unit
|
||||
# 53| 0: [TypeAccess] Color
|
||||
# 53| 1: [ExprStmt] <Expr>;
|
||||
# 53| 0: [MethodAccess] <obinit>(...)
|
||||
# 53| 4: [Method] getName
|
||||
# 53| 4: [Method] getOrdinal
|
||||
# 53| 7: [Method] getRgb
|
||||
# 53| 5: [BlockStmt] { ... }
|
||||
# 53| 0: [ReturnStmt] return ...
|
||||
# 53| 0: [VarAccess] this.rgb
|
||||
# 53| -1: [ThisAccess] this
|
||||
# 53| 7: [FieldDeclaration] int rgb;
|
||||
# 53| -1: [TypeAccess] int
|
||||
# 59| 13: [Interface] Interface1
|
||||
# 60| 14: [Interface] Interface2
|
||||
# 61| 15: [GenericType,Interface,ParameterizedType] Interface3
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 61| 0: [TypeVariable] T
|
||||
# 63| 18: [Class] Class1
|
||||
# 63| 1: [Constructor] Class1
|
||||
# 63| 5: [BlockStmt] { ... }
|
||||
# 63| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 63| 1: [ExprStmt] <Expr>;
|
||||
# 63| 0: [MethodAccess] <obinit>(...)
|
||||
# 64| 3: [Method] getObject1
|
||||
#-----| 4: (Parameters)
|
||||
# 64| 0: [Parameter] b
|
||||
# 64| 5: [BlockStmt] { ... }
|
||||
# 65| 0: [ExprStmt] <Expr>;
|
||||
# 65| 0: [WhenExpr] when ...
|
||||
#-----| 0: (branch)
|
||||
# 65| 0: [VarAccess] b
|
||||
# 66| 1: [ReturnStmt] return ...
|
||||
# 66| 0: [StmtExpr] <Stmt>
|
||||
# 66| 0: [BlockStmt] { ... }
|
||||
# 66| 0: [LocalTypeDeclStmt] class ...
|
||||
# 66| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 66| 1: [Constructor]
|
||||
# 66| 5: [BlockStmt] { ... }
|
||||
# 66| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 66| 1: [ExprStmt] <Expr>;
|
||||
# 66| 0: [MethodAccess] <obinit>(...)
|
||||
# 66| 1: [ExprStmt] <Expr>;
|
||||
# 66| 0: [ClassInstanceExpr] new (...)
|
||||
# 66| -3: [TypeAccess] Object
|
||||
#-----| 1: (branch)
|
||||
# 65| 0: [BooleanLiteral] true
|
||||
# 68| 1: [ReturnStmt] return ...
|
||||
# 68| 0: [StmtExpr] <Stmt>
|
||||
# 68| 0: [BlockStmt] { ... }
|
||||
# 68| 0: [LocalTypeDeclStmt] class ...
|
||||
# 68| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 68| 1: [Constructor]
|
||||
# 68| 5: [BlockStmt] { ... }
|
||||
# 68| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 68| 1: [ExprStmt] <Expr>;
|
||||
# 68| 0: [MethodAccess] <obinit>(...)
|
||||
# 68| 1: [ExprStmt] <Expr>;
|
||||
# 68| 0: [ClassInstanceExpr] new (...)
|
||||
# 68| -3: [TypeAccess] Object
|
||||
# 71| 4: [Method] getObject2
|
||||
# 71| 5: [BlockStmt] { ... }
|
||||
# 72| 0: [ReturnStmt] return ...
|
||||
# 72| 0: [StmtExpr] <Stmt>
|
||||
# 72| 0: [BlockStmt] { ... }
|
||||
# 72| 0: [LocalTypeDeclStmt] class ...
|
||||
# 72| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 72| 1: [Constructor]
|
||||
# 72| 5: [BlockStmt] { ... }
|
||||
# 72| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 72| 1: [ExprStmt] <Expr>;
|
||||
# 72| 0: [MethodAccess] <obinit>(...)
|
||||
# 73| 3: [Method] getX
|
||||
# 73| 5: [BlockStmt] { ... }
|
||||
# 73| 0: [ReturnStmt] return ...
|
||||
# 73| 0: [VarAccess] this.x
|
||||
# 73| -1: [ThisAccess] this
|
||||
# 73| 3: [FieldDeclaration] int x;
|
||||
# 73| -1: [TypeAccess] int
|
||||
# 73| 0: [IntegerLiteral] 1
|
||||
# 74| 5: [Method] foo
|
||||
# 74| 5: [BlockStmt] { ... }
|
||||
# 75| 0: [ReturnStmt] return ...
|
||||
# 75| 0: [StmtExpr] <Stmt>
|
||||
# 75| 0: [BlockStmt] { ... }
|
||||
# 75| 0: [LocalTypeDeclStmt] class ...
|
||||
# 75| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 75| 1: [Constructor]
|
||||
# 75| 5: [BlockStmt] { ... }
|
||||
# 75| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 75| 1: [ExprStmt] <Expr>;
|
||||
# 75| 0: [MethodAccess] <obinit>(...)
|
||||
# 75| 1: [ExprStmt] <Expr>;
|
||||
# 75| 0: [ClassInstanceExpr] new (...)
|
||||
# 75| -3: [TypeAccess] Object
|
||||
# 72| 1: [ExprStmt] <Expr>;
|
||||
# 72| 0: [ClassInstanceExpr] new (...)
|
||||
# 72| -3: [TypeAccess] Object
|
||||
# 80| 5: [Method] getObject3
|
||||
# 80| 5: [BlockStmt] { ... }
|
||||
# 81| 0: [ReturnStmt] return ...
|
||||
# 81| 0: [StmtExpr] <Stmt>
|
||||
# 81| 0: [BlockStmt] { ... }
|
||||
# 81| 0: [LocalTypeDeclStmt] class ...
|
||||
# 81| 0: [AnonymousClass,LocalClass] new Interface1(...) { ... }
|
||||
# 81| 1: [Constructor]
|
||||
# 81| 5: [BlockStmt] { ... }
|
||||
# 81| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 81| 1: [ExprStmt] <Expr>;
|
||||
# 81| 0: [MethodAccess] <obinit>(...)
|
||||
# 81| 1: [ExprStmt] <Expr>;
|
||||
# 81| 0: [ClassInstanceExpr] new (...)
|
||||
# 81| -3: [TypeAccess] Interface1
|
||||
# 84| 6: [Method] getObject4
|
||||
# 84| 5: [BlockStmt] { ... }
|
||||
# 85| 0: [ReturnStmt] return ...
|
||||
# 85| 0: [StmtExpr] <Stmt>
|
||||
# 85| 0: [BlockStmt] { ... }
|
||||
# 85| 0: [LocalTypeDeclStmt] class ...
|
||||
# 85| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 85| 1: [Constructor]
|
||||
# 85| 5: [BlockStmt] { ... }
|
||||
# 85| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 85| 1: [ExprStmt] <Expr>;
|
||||
# 85| 0: [MethodAccess] <obinit>(...)
|
||||
# 85| 1: [ExprStmt] <Expr>;
|
||||
# 85| 0: [ClassInstanceExpr] new (...)
|
||||
# 85| -3: [TypeAccess] Object
|
||||
# 88| 7: [Method] getObject5
|
||||
# 88| 5: [BlockStmt] { ... }
|
||||
# 89| 0: [ReturnStmt] return ...
|
||||
# 89| 0: [StmtExpr] <Stmt>
|
||||
# 89| 0: [BlockStmt] { ... }
|
||||
# 89| 0: [LocalTypeDeclStmt] class ...
|
||||
# 89| 0: [AnonymousClass,LocalClass] new Interface3<Integer>(...) { ... }
|
||||
# 89| 1: [Constructor]
|
||||
# 89| 5: [BlockStmt] { ... }
|
||||
# 89| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 89| 1: [ExprStmt] <Expr>;
|
||||
# 89| 0: [MethodAccess] <obinit>(...)
|
||||
# 89| 1: [ExprStmt] <Expr>;
|
||||
# 89| 0: [ClassInstanceExpr] new (...)
|
||||
# 89| -3: [TypeAccess] Interface3<Integer>
|
||||
# 93| 19: [Class] pulicClass
|
||||
# 93| 2: [Constructor] pulicClass
|
||||
# 93| 5: [BlockStmt] { ... }
|
||||
# 93| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 93| 1: [ExprStmt] <Expr>;
|
||||
# 93| 0: [MethodAccess] <obinit>(...)
|
||||
# 94| 20: [Class] privateClass
|
||||
# 94| 2: [Constructor] privateClass
|
||||
# 94| 5: [BlockStmt] { ... }
|
||||
# 94| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 94| 1: [ExprStmt] <Expr>;
|
||||
# 94| 0: [MethodAccess] <obinit>(...)
|
||||
# 95| 21: [Class] internalClass
|
||||
# 95| 2: [Constructor] internalClass
|
||||
# 95| 5: [BlockStmt] { ... }
|
||||
# 95| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 95| 1: [ExprStmt] <Expr>;
|
||||
# 95| 0: [MethodAccess] <obinit>(...)
|
||||
# 96| 22: [Class] noExplicitVisibilityClass
|
||||
# 96| 1: [Constructor] noExplicitVisibilityClass
|
||||
# 96| 5: [BlockStmt] { ... }
|
||||
# 96| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 96| 1: [ExprStmt] <Expr>;
|
||||
# 96| 0: [MethodAccess] <obinit>(...)
|
||||
# 98| 23: [Class] nestedClassVisibilities
|
||||
# 98| 1: [Constructor] nestedClassVisibilities
|
||||
# 98| 5: [BlockStmt] { ... }
|
||||
# 98| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 98| 1: [ExprStmt] <Expr>;
|
||||
# 98| 0: [MethodAccess] <obinit>(...)
|
||||
# 99| 3: [Class] pulicNestedClass
|
||||
# 99| 2: [Constructor] pulicNestedClass
|
||||
# 99| 5: [BlockStmt] { ... }
|
||||
# 99| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 99| 1: [ExprStmt] <Expr>;
|
||||
# 99| 0: [MethodAccess] <obinit>(...)
|
||||
# 100| 4: [Class] protectedNestedClass
|
||||
# 100| 2: [Constructor] protectedNestedClass
|
||||
# 100| 5: [BlockStmt] { ... }
|
||||
# 100| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 100| 1: [ExprStmt] <Expr>;
|
||||
# 100| 0: [MethodAccess] <obinit>(...)
|
||||
# 101| 5: [Class] privateNestedClass
|
||||
# 101| 2: [Constructor] privateNestedClass
|
||||
# 101| 5: [BlockStmt] { ... }
|
||||
# 101| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 101| 1: [ExprStmt] <Expr>;
|
||||
# 101| 0: [MethodAccess] <obinit>(...)
|
||||
# 102| 6: [Class] internalNestedClass
|
||||
# 102| 2: [Constructor] internalNestedClass
|
||||
# 102| 5: [BlockStmt] { ... }
|
||||
# 102| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 102| 1: [ExprStmt] <Expr>;
|
||||
# 102| 0: [MethodAccess] <obinit>(...)
|
||||
# 103| 7: [Class] noExplicitVisibilityNestedClass
|
||||
# 103| 1: [Constructor] noExplicitVisibilityNestedClass
|
||||
# 103| 5: [BlockStmt] { ... }
|
||||
# 103| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 103| 1: [ExprStmt] <Expr>;
|
||||
# 103| 0: [MethodAccess] <obinit>(...)
|
||||
# 106| 24: [Class] sealedClass
|
||||
# 106| 2: [Constructor] sealedClass
|
||||
# 106| 5: [BlockStmt] { ... }
|
||||
# 106| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 106| 1: [ExprStmt] <Expr>;
|
||||
# 106| 0: [MethodAccess] <obinit>(...)
|
||||
# 107| 25: [Class] openClass
|
||||
# 107| 2: [Constructor] openClass
|
||||
# 107| 5: [BlockStmt] { ... }
|
||||
# 107| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 107| 1: [ExprStmt] <Expr>;
|
||||
# 107| 0: [MethodAccess] <obinit>(...)
|
||||
# 109| 26: [Class] C1
|
||||
# 109| 1: [Constructor] C1
|
||||
# 109| 5: [BlockStmt] { ... }
|
||||
# 109| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 109| 1: [ExprStmt] <Expr>;
|
||||
# 109| 0: [MethodAccess] <obinit>(...)
|
||||
# 110| 3: [Method] fn1
|
||||
#-----| 4: (Parameters)
|
||||
# 110| 0: [Parameter] p
|
||||
# 110| 5: [BlockStmt] { ... }
|
||||
# 111| 0: [LocalTypeDeclStmt] class ...
|
||||
# 111| 0: [Class,GenericType,LocalClass,ParameterizedType] Local1
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 111| 0: [TypeVariable] T1
|
||||
# 111| 1: [Constructor] Local1
|
||||
# 111| 5: [BlockStmt] { ... }
|
||||
# 111| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 111| 1: [ExprStmt] <Expr>;
|
||||
# 111| 0: [MethodAccess] <obinit>(...)
|
||||
# 112| 3: [Method] foo
|
||||
#-----| 4: (Parameters)
|
||||
# 112| 0: [Parameter] p
|
||||
# 112| 5: [BlockStmt] { ... }
|
||||
# 114| 1: [ExprStmt] <Expr>;
|
||||
# 114| 0: [MethodAccess] foo(...)
|
||||
# 114| -1: [ClassInstanceExpr] new Local1<Integer>(...)
|
||||
# 114| -3: [TypeAccess] Local1<Integer>
|
||||
# 114| 0: [TypeAccess] Integer
|
||||
# 114| 0: [VarAccess] p
|
||||
# 117| 4: [Method] fn2
|
||||
#-----| 4: (Parameters)
|
||||
# 117| 0: [Parameter] p
|
||||
# 117| 5: [BlockStmt] { ... }
|
||||
# 118| 0: [LocalTypeDeclStmt] class ...
|
||||
# 118| 0: [LocalClass]
|
||||
# 118| 1: [Constructor]
|
||||
# 118| 5: [BlockStmt] { ... }
|
||||
# 118| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 118| 1: [Method] localFn
|
||||
# 118| 5: [BlockStmt] { ... }
|
||||
# 119| 0: [LocalTypeDeclStmt] class ...
|
||||
# 119| 0: [Class,GenericType,LocalClass,ParameterizedType] Local2
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 119| 0: [TypeVariable] T1
|
||||
# 119| 1: [Constructor] Local2
|
||||
# 119| 5: [BlockStmt] { ... }
|
||||
# 119| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 119| 1: [ExprStmt] <Expr>;
|
||||
# 119| 0: [MethodAccess] <obinit>(...)
|
||||
# 120| 3: [Method] foo
|
||||
#-----| 4: (Parameters)
|
||||
# 120| 0: [Parameter] p
|
||||
# 120| 5: [BlockStmt] { ... }
|
||||
# 122| 1: [ExprStmt] <Expr>;
|
||||
# 122| 0: [MethodAccess] foo(...)
|
||||
# 122| -1: [ClassInstanceExpr] new Local2<Integer>(...)
|
||||
# 122| -3: [TypeAccess] Local2<Integer>
|
||||
# 122| 0: [TypeAccess] Integer
|
||||
# 122| 0: [VarAccess] p
|
||||
# 126| 5: [Method] fn3
|
||||
#-----| 4: (Parameters)
|
||||
# 126| 0: [Parameter] p
|
||||
# 126| 5: [BlockStmt] { ... }
|
||||
# 127| 0: [ReturnStmt] return ...
|
||||
# 127| 0: [StmtExpr] <Stmt>
|
||||
# 127| 0: [BlockStmt] { ... }
|
||||
# 127| 0: [LocalTypeDeclStmt] class ...
|
||||
# 127| 0: [AnonymousClass,LocalClass] new Object(...) { ... }
|
||||
# 127| 1: [Constructor]
|
||||
# 127| 5: [BlockStmt] { ... }
|
||||
# 127| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 127| 1: [ExprStmt] <Expr>;
|
||||
# 127| 0: [MethodAccess] <obinit>(...)
|
||||
# 128| 3: [Method] fn
|
||||
# 128| 5: [BlockStmt] { ... }
|
||||
# 129| 0: [LocalTypeDeclStmt] class ...
|
||||
# 129| 0: [Class,GenericType,LocalClass,ParameterizedType] Local3
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 129| 0: [TypeVariable] T1
|
||||
# 129| 1: [Constructor] Local3
|
||||
# 129| 5: [BlockStmt] { ... }
|
||||
# 129| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 129| 1: [ExprStmt] <Expr>;
|
||||
# 129| 0: [MethodAccess] <obinit>(...)
|
||||
# 130| 3: [Method] foo
|
||||
#-----| 4: (Parameters)
|
||||
# 130| 0: [Parameter] p
|
||||
# 130| 5: [BlockStmt] { ... }
|
||||
# 132| 1: [ExprStmt] <Expr>;
|
||||
# 132| 0: [MethodAccess] foo(...)
|
||||
# 132| -1: [ClassInstanceExpr] new Local3<Integer>(...)
|
||||
# 132| -3: [TypeAccess] Local3<Integer>
|
||||
# 132| 0: [TypeAccess] Integer
|
||||
# 132| 0: [VarAccess] p
|
||||
# 127| 1: [ExprStmt] <Expr>;
|
||||
# 127| 0: [ClassInstanceExpr] new (...)
|
||||
# 127| -3: [TypeAccess] Object
|
||||
superChain.kt:
|
||||
# 0| [CompilationUnit] superChain
|
||||
# 0| 1: [Class] SuperChainKt
|
||||
# 1| 2: [Class,GenericType,ParameterizedType] SuperChain1
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 1| 0: [TypeVariable] T1
|
||||
# 1| 1: [TypeVariable] T2
|
||||
# 1| 2: [Constructor] SuperChain1
|
||||
# 1| 5: [BlockStmt] { ... }
|
||||
# 1| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 1| 1: [ExprStmt] <Expr>;
|
||||
# 1| 0: [MethodAccess] <obinit>(...)
|
||||
# 2| 5: [Class,GenericType,ParameterizedType] SuperChain2
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 2| 0: [TypeVariable] T3
|
||||
# 2| 1: [TypeVariable] T4
|
||||
# 2| 2: [Constructor] SuperChain2
|
||||
# 2| 5: [BlockStmt] { ... }
|
||||
# 2| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 2| 1: [ExprStmt] <Expr>;
|
||||
# 2| 0: [MethodAccess] <obinit>(...)
|
||||
# 3| 7: [Class,GenericType,ParameterizedType] SuperChain3
|
||||
#-----| -2: (Generic Parameters)
|
||||
# 3| 0: [TypeVariable] T5
|
||||
# 3| 1: [TypeVariable] T6
|
||||
# 3| 2: [Constructor] SuperChain3
|
||||
# 3| 5: [BlockStmt] { ... }
|
||||
# 3| 0: [SuperConstructorInvocationStmt] super(...)
|
||||
# 3| 1: [ExprStmt] <Expr>;
|
||||
# 3| 0: [MethodAccess] <obinit>(...)
|
||||
1
java/ql/test/kotlin/library-tests/classes/PrintAst.qlref
Normal file
1
java/ql/test/kotlin/library-tests/classes/PrintAst.qlref
Normal file
@@ -0,0 +1 @@
|
||||
semmle/code/java/PrintAst.ql
|
||||
@@ -5,3 +5,4 @@
|
||||
| classes.kt:81:16:81:38 | new Interface1(...) { ... } | classes.kt:81:16:81:38 | new (...) | | classes.kt:81:16:81:38 | Interface1 | classes.kt:81:16:81:38 | class ... |
|
||||
| classes.kt:85:16:85:25 | new Object(...) { ... } | classes.kt:85:16:85:25 | new (...) | | classes.kt:85:16:85:25 | Object | classes.kt:85:16:85:25 | class ... |
|
||||
| classes.kt:89:16:89:44 | new Interface3<Integer>(...) { ... } | classes.kt:89:16:89:44 | new (...) | | classes.kt:89:16:89:44 | Interface3<Integer> | classes.kt:89:16:89:44 | class ... |
|
||||
| classes.kt:127:16:134:9 | new Object(...) { ... } | classes.kt:127:16:134:9 | new (...) | | classes.kt:127:16:134:9 | Object | classes.kt:127:16:134:9 | class ... |
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
| classes.kt:103:5:103:44 | noExplicitVisibilityNestedClass | nestedClassVisibilities$noExplicitVisibilityNestedClass | final, public |
|
||||
| classes.kt:106:1:106:27 | sealedClass | sealedClass | public, sealed |
|
||||
| classes.kt:107:1:107:23 | openClass | openClass | public |
|
||||
| classes.kt:109:1:136:1 | C1 | C1 | final, public |
|
||||
| classes.kt:111:9:113:9 | Local1 | C1$Local1 | final |
|
||||
| classes.kt:118:9:123:9 | | C1$ | final, public, static |
|
||||
| classes.kt:119:13:121:13 | Local2 | C1$Local2 | final |
|
||||
| classes.kt:127:16:134:9 | new Object(...) { ... } | <anonymous class> | final |
|
||||
| classes.kt:129:17:131:17 | Local3 | C1$$Local3 | final |
|
||||
| superChain.kt:0:0:0:0 | SuperChainKt | SuperChainKt | |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1 | SuperChain1 | public |
|
||||
| superChain.kt:2:1:2:60 | SuperChain2 | SuperChain2 | public |
|
||||
|
||||
@@ -106,3 +106,31 @@ class nestedClassVisibilities {
|
||||
sealed class sealedClass {}
|
||||
open class openClass {}
|
||||
|
||||
class C1 {
|
||||
fun fn1(p: Int) {
|
||||
class Local1<T1> {
|
||||
fun foo(p: Int) { }
|
||||
}
|
||||
Local1<Int>().foo(p)
|
||||
}
|
||||
|
||||
fun fn2(p: Int) {
|
||||
fun localFn() {
|
||||
class Local2<T1> {
|
||||
fun foo(p: Int) { }
|
||||
}
|
||||
Local2<Int>().foo(p)
|
||||
}
|
||||
}
|
||||
|
||||
fun fn3(p: Int): Any {
|
||||
return object {
|
||||
fun fn() {
|
||||
class Local3<T1> {
|
||||
fun foo(p: Int) { }
|
||||
}
|
||||
Local3<Int>().foo(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,12 @@ superCall
|
||||
| classes.kt:103:5:103:44 | super(...) |
|
||||
| classes.kt:106:1:106:27 | super(...) |
|
||||
| classes.kt:107:1:107:23 | super(...) |
|
||||
| classes.kt:109:1:136:1 | super(...) |
|
||||
| classes.kt:111:9:113:9 | super(...) |
|
||||
| classes.kt:118:9:123:9 | super(...) |
|
||||
| classes.kt:119:13:121:13 | super(...) |
|
||||
| classes.kt:127:16:134:9 | super(...) |
|
||||
| classes.kt:129:17:131:17 | super(...) |
|
||||
| superChain.kt:1:1:1:33 | super(...) |
|
||||
| superChain.kt:2:33:2:57 | super(...) |
|
||||
| superChain.kt:3:33:3:57 | super(...) |
|
||||
|
||||
@@ -33,6 +33,11 @@ initBlocks
|
||||
| classes.kt:103:5:103:44 | <obinit> |
|
||||
| classes.kt:106:1:106:27 | <obinit> |
|
||||
| classes.kt:107:1:107:23 | <obinit> |
|
||||
| classes.kt:109:1:136:1 | <obinit> |
|
||||
| classes.kt:111:9:113:9 | <obinit> |
|
||||
| classes.kt:119:13:121:13 | <obinit> |
|
||||
| classes.kt:127:16:134:9 | <obinit> |
|
||||
| classes.kt:129:17:131:17 | <obinit> |
|
||||
| superChain.kt:1:1:1:33 | <obinit> |
|
||||
| superChain.kt:2:1:2:60 | <obinit> |
|
||||
| superChain.kt:3:1:3:60 | <obinit> |
|
||||
@@ -66,6 +71,11 @@ initCall
|
||||
| classes.kt:103:5:103:44 | <obinit>(...) |
|
||||
| classes.kt:106:1:106:27 | <obinit>(...) |
|
||||
| classes.kt:107:1:107:23 | <obinit>(...) |
|
||||
| classes.kt:109:1:136:1 | <obinit>(...) |
|
||||
| classes.kt:111:9:113:9 | <obinit>(...) |
|
||||
| classes.kt:119:13:121:13 | <obinit>(...) |
|
||||
| classes.kt:127:16:134:9 | <obinit>(...) |
|
||||
| classes.kt:129:17:131:17 | <obinit>(...) |
|
||||
| superChain.kt:1:1:1:33 | <obinit>(...) |
|
||||
| superChain.kt:2:1:2:60 | <obinit>(...) |
|
||||
| superChain.kt:3:1:3:60 | <obinit>(...) |
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
| classes.kt:111:9:113:9 | class ... | classes.kt:111:9:113:9 | Local1 | classes.kt:110:5:115:5 | fn1 | classes.kt:109:1:136:1 | C1 |
|
||||
| classes.kt:118:9:123:9 | class ... | classes.kt:118:9:123:9 | | classes.kt:117:5:124:5 | fn2 | classes.kt:109:1:136:1 | C1 |
|
||||
| classes.kt:119:13:121:13 | class ... | classes.kt:119:13:121:13 | Local2 | classes.kt:118:9:123:9 | localFn | classes.kt:109:1:136:1 | C1 |
|
||||
| classes.kt:129:17:131:17 | class ... | classes.kt:129:17:131:17 | Local3 | classes.kt:128:13:133:13 | fn | classes.kt:127:16:134:9 | new Object(...) { ... } |
|
||||
5
java/ql/test/kotlin/library-tests/classes/localClass.ql
Normal file
5
java/ql/test/kotlin/library-tests/classes/localClass.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import java
|
||||
|
||||
from LocalTypeDeclStmt s
|
||||
where not s.getLocalType() instanceof AnonymousClass
|
||||
select s, s.getLocalType(), s.getEnclosingCallable(), s.getLocalType().getEnclosingType()
|
||||
@@ -1,3 +1,9 @@
|
||||
| classes.kt:111:9:113:9 | Local1 | 0 | classes.kt:111:22:111:23 | T1 |
|
||||
| classes.kt:111:9:113:9 | Local1<Integer> | 0 | file://<external>/Integer.class:0:0:0:0 | Integer |
|
||||
| classes.kt:119:13:121:13 | Local2 | 0 | classes.kt:119:26:119:27 | T1 |
|
||||
| classes.kt:119:13:121:13 | Local2<Integer> | 0 | file://<external>/Integer.class:0:0:0:0 | Integer |
|
||||
| classes.kt:129:17:131:17 | Local3 | 0 | classes.kt:129:30:129:31 | T1 |
|
||||
| classes.kt:129:17:131:17 | Local3<Integer> | 0 | file://<external>/Integer.class:0:0:0:0 | Integer |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1 | 0 | superChain.kt:1:24:1:25 | T1 |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1 | 1 | superChain.kt:1:28:1:29 | T2 |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1<T3,String> | 0 | superChain.kt:2:24:2:25 | T3 |
|
||||
|
||||
@@ -33,6 +33,15 @@
|
||||
| classes.kt:103:5:103:44 | noExplicitVisibilityNestedClass | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:106:1:106:27 | sealedClass | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:107:1:107:23 | openClass | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:109:1:136:1 | C1 | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:111:9:113:9 | Local1 | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:111:9:113:9 | Local1<Integer> | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:118:9:123:9 | | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:119:13:121:13 | Local2 | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:119:13:121:13 | Local2<Integer> | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:127:16:134:9 | new Object(...) { ... } | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:129:17:131:17 | Local3 | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| classes.kt:129:17:131:17 | Local3<Integer> | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1 | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1<T3,String> | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
| superChain.kt:1:1:1:33 | SuperChain1<T5,String> | file://<external>/Object.class:0:0:0:0 | Object |
|
||||
|
||||
Reference in New Issue
Block a user