Extract static method qualifier type accesses

This commit is contained in:
Chris Smowton
2021-12-16 18:48:06 +00:00
committed by Ian Lynagh
parent ef9a213ae1
commit 2730d07b4c
5 changed files with 25 additions and 0 deletions

View File

@@ -864,6 +864,8 @@ open class KotlinFileExtractor(
if (dr != null) {
extractExpressionExpr(dr, callable, id, -1, enclosingStmt)
} else if(callTarget.isStaticMethodOfClass) {
extractTypeAccess(callTarget.parentAsClass.toRawType(), callable, id, -1, c, enclosingStmt)
}
}

View File

@@ -172,4 +172,12 @@ fun IrType.toRawType(): IrType =
else -> this
}
fun IrClass.toRawType(): IrType {
val result = this.typeWith(listOf())
return if (this.typeParameters.isNotEmpty())
result.addAnnotations(listOf(RawTypeAnnotation.annotationConstructor))
else
result
}
typealias TypeSubstitution = (IrType, KotlinUsesExtractor.TypeContext, IrPluginContext) -> IrType

View File

@@ -0,0 +1,2 @@
| test.kt:4:17:4:30 | Class<> | TypeAccess | forName |
| test.kt:7:18:7:44 | StringsKt | TypeAccess | format |

View File

@@ -0,0 +1,9 @@
fun test() {
// Static method of a class with type parameters:
val c = Class.forName("xyz")
// Static method of a class without one:
val s = String.format("Hello %s", "world")
}

View File

@@ -0,0 +1,4 @@
import java
from MethodAccess ma
select ma.getQualifier(), ma.getQualifier().getAPrimaryQlClass(), ma.getCallee().toString()