Skip to content

Commit d3941ae

Browse files
committed
Kotlin: Avoid using deprecated APIs
1 parent dc26dc8 commit d3941ae

File tree

6 files changed

+57
-37
lines changed

6 files changed

+57
-37
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,9 +2397,9 @@ open class KotlinFileExtractor(
23972397
return result
23982398
}
23992399

2400-
private fun findTopLevelFunctionOrWarn(functionFilter: String, type: String, parameterTypes: Array<String>, warnAgainstElement: IrElement): IrFunction? {
2400+
private fun findTopLevelFunctionOrWarn(functionPkg: String, functionName: String, type: String, parameterTypes: Array<String>, warnAgainstElement: IrElement): IrFunction? {
24012401

2402-
val fn = getFunctionsByFqName(pluginContext, functionFilter)
2402+
val fn = getFunctionsByFqName(pluginContext, functionPkg, functionName)
24032403
.firstOrNull { fnSymbol ->
24042404
fnSymbol.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type &&
24052405
fnSymbol.owner.valueParameters.map { it.type.classFqName?.asString() }.toTypedArray() contentEquals parameterTypes
@@ -2410,15 +2410,15 @@ open class KotlinFileExtractor(
24102410
extractExternalClassLater(fn.parentAsClass)
24112411
}
24122412
} else {
2413-
logger.errorElement("Couldn't find JVM intrinsic function $functionFilter in $type", warnAgainstElement)
2413+
logger.errorElement("Couldn't find JVM intrinsic function $functionPkg $functionName in $type", warnAgainstElement)
24142414
}
24152415

24162416
return fn
24172417
}
24182418

2419-
private fun findTopLevelPropertyOrWarn(propertyFilter: String, type: String, warnAgainstElement: IrElement): IrProperty? {
2419+
private fun findTopLevelPropertyOrWarn(propertyPkg: String, propertyName: String, type: String, warnAgainstElement: IrElement): IrProperty? {
24202420

2421-
val prop = getPropertiesByFqName(pluginContext, propertyFilter)
2421+
val prop = getPropertiesByFqName(pluginContext, propertyPkg, propertyName)
24222422
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
24232423
?.owner
24242424

@@ -2427,7 +2427,7 @@ open class KotlinFileExtractor(
24272427
extractExternalClassLater(prop.parentAsClass)
24282428
}
24292429
} else {
2430-
logger.errorElement("Couldn't find JVM intrinsic property $propertyFilter in $type", warnAgainstElement)
2430+
logger.errorElement("Couldn't find JVM intrinsic property $propertyPkg $propertyName in $type", warnAgainstElement)
24312431
}
24322432

24332433
return prop
@@ -3019,7 +3019,7 @@ open class KotlinFileExtractor(
30193019
}
30203020
isBuiltinCall(c, "<get-java>", "kotlin.jvm") -> {
30213021
// Special case for KClass<*>.java, which is used in the Parcelize plugin. In normal cases, this is already rewritten to the property referenced below:
3022-
findTopLevelPropertyOrWarn("kotlin.jvm.java", "kotlin.jvm.JvmClassMappingKt", c)?.let { javaProp ->
3022+
findTopLevelPropertyOrWarn("kotlin.jvm", "java", "kotlin.jvm.JvmClassMappingKt", c)?.let { javaProp ->
30233023
val getter = javaProp.getter
30243024
if (getter == null) {
30253025
logger.error("Couldn't find getter of `kotlin.jvm.JvmClassMappingKt::java`")
@@ -3051,7 +3051,7 @@ open class KotlinFileExtractor(
30513051
"kotlin.jvm.internal.ArrayIteratorsKt"
30523052
}
30533053

3054-
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", typeFilter, arrayOf(parentClass.kotlinFqName.asString()), c)?.let { iteratorFn ->
3054+
findTopLevelFunctionOrWarn("kotlin.jvm.internal", "iterator", typeFilter, arrayOf(parentClass.kotlinFqName.asString()), c)?.let { iteratorFn ->
30553055
val dispatchReceiver = c.dispatchReceiver
30563056
if (dispatchReceiver == null) {
30573057
logger.errorElement("No dispatch receiver found for array iterator call", c)
Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
11
package com.github.codeql.utils
22

3-
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
43
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
54
import org.jetbrains.kotlin.ir.symbols.*
65
import org.jetbrains.kotlin.name.FqName
6+
import org.jetbrains.kotlin.name.Name
77

88
fun getClassByFqName(pluginContext: IrPluginContext, fqName: String): IrClassSymbol? {
99
return getClassByFqName(pluginContext, FqName(fqName))
1010
}
1111

12-
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
13-
@OptIn(FirIncompatiblePluginAPI::class)
14-
return pluginContext.referenceClass(fqName)
12+
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: String, name: String): Collection<IrSimpleFunctionSymbol> {
13+
return getFunctionsByFqName(pluginContext, FqName(pkgName), Name.identifier(name))
1514
}
1615

17-
fun getFunctionsByFqName(pluginContext: IrPluginContext, fqName: String): Collection<IrSimpleFunctionSymbol> {
18-
return getFunctionsByFqName(pluginContext, FqName(fqName))
19-
}
20-
21-
private fun getFunctionsByFqName(pluginContext: IrPluginContext, fqName: FqName): Collection<IrSimpleFunctionSymbol> {
22-
@OptIn(FirIncompatiblePluginAPI::class)
23-
return pluginContext.referenceFunctions(fqName)
24-
}
25-
26-
fun getPropertiesByFqName(pluginContext: IrPluginContext, fqName: String): Collection<IrPropertySymbol> {
27-
return getPropertiesByFqName(pluginContext, FqName(fqName))
28-
}
29-
30-
private fun getPropertiesByFqName(pluginContext: IrPluginContext, fqName: FqName): Collection<IrPropertySymbol> {
31-
@OptIn(FirIncompatiblePluginAPI::class)
32-
return pluginContext.referenceProperties(fqName)
16+
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: String, name: String): Collection<IrPropertySymbol> {
17+
return getPropertiesByFqName(pluginContext, FqName(pkgName), Name.identifier(name))
3318
}

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_4_32/FirIncompatiblePluginAPI.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.github.codeql.utils
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
4+
import org.jetbrains.kotlin.ir.symbols.*
5+
import org.jetbrains.kotlin.name.FqName
6+
import org.jetbrains.kotlin.name.Name
7+
8+
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
9+
return pluginContext.referenceClass(fqName)
10+
}
11+
12+
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
13+
val fqName = pkgName.child(name)
14+
return pluginContext.referenceFunctions(fqName)
15+
}
16+
17+
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrPropertySymbol> {
18+
val fqName = pkgName.child(name)
19+
return pluginContext.referenceProperties(fqName)
20+
}

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/FirIncompatiblePluginAPI.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.codeql.utils
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
4+
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
5+
import org.jetbrains.kotlin.ir.symbols.*
6+
import org.jetbrains.kotlin.name.ClassId
7+
import org.jetbrains.kotlin.name.CallableId
8+
import org.jetbrains.kotlin.name.FqName
9+
import org.jetbrains.kotlin.name.Name
10+
11+
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
12+
val id = ClassId.topLevel(fqName)
13+
return pluginContext.referenceClass(id)
14+
}
15+
16+
fun getFunctionsByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrSimpleFunctionSymbol> {
17+
val id = CallableId(pkgName, name)
18+
return pluginContext.referenceFunctions(id)
19+
}
20+
21+
fun getPropertiesByFqName(pluginContext: IrPluginContext, pkgName: FqName, name: Name): Collection<IrPropertySymbol> {
22+
val id = CallableId(pkgName, name)
23+
return pluginContext.referenceProperties(id)
24+
}

0 commit comments

Comments
 (0)