mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Kotlin: Avoid using deprecated APIs
This commit is contained in:
@@ -2397,9 +2397,9 @@ open class KotlinFileExtractor(
|
||||
return result
|
||||
}
|
||||
|
||||
private fun findTopLevelFunctionOrWarn(functionFilter: String, type: String, parameterTypes: Array<String>, warnAgainstElement: IrElement): IrFunction? {
|
||||
private fun findTopLevelFunctionOrWarn(functionPkg: String, functionName: String, type: String, parameterTypes: Array<String>, warnAgainstElement: IrElement): IrFunction? {
|
||||
|
||||
val fn = getFunctionsByFqName(pluginContext, functionFilter)
|
||||
val fn = getFunctionsByFqName(pluginContext, functionPkg, functionName)
|
||||
.firstOrNull { fnSymbol ->
|
||||
fnSymbol.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type &&
|
||||
fnSymbol.owner.valueParameters.map { it.type.classFqName?.asString() }.toTypedArray() contentEquals parameterTypes
|
||||
@@ -2410,15 +2410,15 @@ open class KotlinFileExtractor(
|
||||
extractExternalClassLater(fn.parentAsClass)
|
||||
}
|
||||
} else {
|
||||
logger.errorElement("Couldn't find JVM intrinsic function $functionFilter in $type", warnAgainstElement)
|
||||
logger.errorElement("Couldn't find JVM intrinsic function $functionPkg $functionName in $type", warnAgainstElement)
|
||||
}
|
||||
|
||||
return fn
|
||||
}
|
||||
|
||||
private fun findTopLevelPropertyOrWarn(propertyFilter: String, type: String, warnAgainstElement: IrElement): IrProperty? {
|
||||
private fun findTopLevelPropertyOrWarn(propertyPkg: String, propertyName: String, type: String, warnAgainstElement: IrElement): IrProperty? {
|
||||
|
||||
val prop = getPropertiesByFqName(pluginContext, propertyFilter)
|
||||
val prop = getPropertiesByFqName(pluginContext, propertyPkg, propertyName)
|
||||
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
|
||||
?.owner
|
||||
|
||||
@@ -2427,7 +2427,7 @@ open class KotlinFileExtractor(
|
||||
extractExternalClassLater(prop.parentAsClass)
|
||||
}
|
||||
} else {
|
||||
logger.errorElement("Couldn't find JVM intrinsic property $propertyFilter in $type", warnAgainstElement)
|
||||
logger.errorElement("Couldn't find JVM intrinsic property $propertyPkg $propertyName in $type", warnAgainstElement)
|
||||
}
|
||||
|
||||
return prop
|
||||
@@ -3019,7 +3019,7 @@ open class KotlinFileExtractor(
|
||||
}
|
||||
isBuiltinCall(c, "<get-java>", "kotlin.jvm") -> {
|
||||
// Special case for KClass<*>.java, which is used in the Parcelize plugin. In normal cases, this is already rewritten to the property referenced below:
|
||||
findTopLevelPropertyOrWarn("kotlin.jvm.java", "kotlin.jvm.JvmClassMappingKt", c)?.let { javaProp ->
|
||||
findTopLevelPropertyOrWarn("kotlin.jvm", "java", "kotlin.jvm.JvmClassMappingKt", c)?.let { javaProp ->
|
||||
val getter = javaProp.getter
|
||||
if (getter == null) {
|
||||
logger.error("Couldn't find getter of `kotlin.jvm.JvmClassMappingKt::java`")
|
||||
@@ -3051,7 +3051,7 @@ open class KotlinFileExtractor(
|
||||
"kotlin.jvm.internal.ArrayIteratorsKt"
|
||||
}
|
||||
|
||||
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", typeFilter, arrayOf(parentClass.kotlinFqName.asString()), c)?.let { iteratorFn ->
|
||||
findTopLevelFunctionOrWarn("kotlin.jvm.internal", "iterator", typeFilter, arrayOf(parentClass.kotlinFqName.asString()), c)?.let { iteratorFn ->
|
||||
val dispatchReceiver = c.dispatchReceiver
|
||||
if (dispatchReceiver == null) {
|
||||
logger.errorElement("No dispatch receiver found for array iterator call", c)
|
||||
|
||||
@@ -1,33 +1,18 @@
|
||||
package com.github.codeql.utils
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun getClassByFqName(pluginContext: IrPluginContext, fqName: String): IrClassSymbol? {
|
||||
return getClassByFqName(pluginContext, FqName(fqName))
|
||||
}
|
||||
|
||||
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
|
||||
@OptIn(FirIncompatiblePluginAPI::class)
|
||||
return pluginContext.referenceClass(fqName)
|
||||
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: String, name: String): Collection<IrSimpleFunctionSymbol> {
|
||||
return getFunctionsByFqName(pluginContext, FqName(pkgName), Name.identifier(name))
|
||||
}
|
||||
|
||||
fun getFunctionsByFqName(pluginContext: IrPluginContext, fqName: String): Collection<IrSimpleFunctionSymbol> {
|
||||
return getFunctionsByFqName(pluginContext, FqName(fqName))
|
||||
}
|
||||
|
||||
private fun getFunctionsByFqName(pluginContext: IrPluginContext, fqName: FqName): Collection<IrSimpleFunctionSymbol> {
|
||||
@OptIn(FirIncompatiblePluginAPI::class)
|
||||
return pluginContext.referenceFunctions(fqName)
|
||||
}
|
||||
|
||||
fun getPropertiesByFqName(pluginContext: IrPluginContext, fqName: String): Collection<IrPropertySymbol> {
|
||||
return getPropertiesByFqName(pluginContext, FqName(fqName))
|
||||
}
|
||||
|
||||
private fun getPropertiesByFqName(pluginContext: IrPluginContext, fqName: FqName): Collection<IrPropertySymbol> {
|
||||
@OptIn(FirIncompatiblePluginAPI::class)
|
||||
return pluginContext.referenceProperties(fqName)
|
||||
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: String, name: String): Collection<IrPropertySymbol> {
|
||||
return getPropertiesByFqName(pluginContext, FqName(pkgName), Name.identifier(name))
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.jetbrains.kotlin.backend.common.extensions
|
||||
|
||||
@RequiresOptIn("This API is not available after FIR")
|
||||
annotation class FirIncompatiblePluginAPI
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.github.codeql.utils
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
|
||||
return pluginContext.referenceClass(fqName)
|
||||
}
|
||||
|
||||
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
|
||||
val fqName = pkgName.child(name)
|
||||
return pluginContext.referenceFunctions(fqName)
|
||||
}
|
||||
|
||||
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrPropertySymbol> {
|
||||
val fqName = pkgName.child(name)
|
||||
return pluginContext.referenceProperties(fqName)
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
package com.github.codeql
|
||||
|
||||
// The compiler provides the annotation class, so we don't need to do
|
||||
// anything
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.github.codeql.utils
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
|
||||
val id = ClassId.topLevel(fqName)
|
||||
return pluginContext.referenceClass(id)
|
||||
}
|
||||
|
||||
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
|
||||
val id = CallableId(pkgName, name)
|
||||
return pluginContext.referenceFunctions(id)
|
||||
}
|
||||
|
||||
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrPropertySymbol> {
|
||||
val id = CallableId(pkgName, name)
|
||||
return pluginContext.referenceProperties(id)
|
||||
}
|
||||
Reference in New Issue
Block a user